/** * Validates the given contact information. * * @param object the object to validate, or {@code null}. * * @since 3.1 */ public void validate(final Contact object) { if (object == null) { return; } for (final Telephone e : toArray(Telephone.class, object.getPhones())) { validate(e); } for (final Address e : toArray(Address.class, object.getAddresses())) { validate(e); } for (final OnlineResource e : toArray(OnlineResource.class, object.getOnlineResources())) { validate(e); } for (final InternationalString e : toArray(InternationalString.class, object.getHoursOfService())) { container.validate(e); } validateOptional(object.getContactInstructions()); }
/** * Constructs a new instance initialized with the values from the specified metadata object. * This is a <cite>shallow</cite> copy constructor, since the other metadata contained in the * given object are not recursively copied. * * @param object the metadata to copy values from, or {@code null} if none. * * @see #castOrCopy(Contact) */ public DefaultContact(final Contact object) { super(object); if (object != null) { hoursOfService = object.getHoursOfService(); contactInstructions = object.getContactInstructions(); if (object instanceof DefaultContact) { final DefaultContact c = (DefaultContact) object; phones = copyCollection(c.getPhones(), Telephone.class); addresses = copyCollection(c.getAddresses(), Address.class); onlineResources = copyCollection(c.getOnlineResources(), OnlineResource.class); contactType = c.getContactType(); } else { phones = singleton(object.getPhone(), Telephone.class); addresses = singleton(object.getAddress(), Address.class); onlineResources = singleton(object.getOnlineResource(), OnlineResource.class); } } }
/** * Constructs a new instance initialized with the values from the specified metadata object. * This is a <cite>shallow</cite> copy constructor, since the other metadata contained in the * given object are not recursively copied. * * @param object the metadata to copy values from, or {@code null} if none. * * @see #castOrCopy(Contact) */ public DefaultContact(final Contact object) { super(object); if (object != null) { hoursOfService = object.getHoursOfService(); contactInstructions = object.getContactInstructions(); if (object instanceof DefaultContact) { final DefaultContact c = (DefaultContact) object; phones = copyCollection(c.getPhones(), Telephone.class); addresses = copyCollection(c.getAddresses(), Address.class); onlineResources = copyCollection(c.getOnlineResources(), OnlineResource.class); contactType = c.getContactType(); } else { phones = singleton(object.getPhone(), Telephone.class); addresses = singleton(object.getAddress(), Address.class); onlineResources = singleton(object.getOnlineResource(), OnlineResource.class); } } }
/** * Tests XML unmarshalling for a metadata version. * The version is not specified since it should be detected automatically. * * @param file file containing the metadata to unmarshal. */ private void testUnmarshalling(final String file) throws JAXBException { final DefaultCitation c = unmarshalFile(DefaultCitation.class, file); assertTitleEquals("title", "Fight against poverty", c); final CitationDate date = getSingleton(c.getDates()); assertEquals("date", date.getDate(), TestUtilities.date("2015-10-17 00:00:00")); assertEquals("dateType", DateType.valueOf("adopted"), date.getDateType()); assertEquals("presentationForm", PresentationForm.valueOf("physicalObject"), getSingleton(c.getPresentationForms())); final Iterator<ResponsibleParty> it = c.getCitedResponsibleParties().iterator(); final Contact contact = assertResponsibilityEquals(Role.ORIGINATOR, "Maid Marian", it.next()); assertEquals("Contact instruction", "Send carrier pigeon.", String.valueOf(contact.getContactInstructions())); final OnlineResource resource = contact.getOnlineResource(); assertEquals("Resource name", "IP over Avian Carriers", String.valueOf(resource.getName())); assertEquals("Resource description", "High delay, low throughput, and low altitude service.", String.valueOf(resource.getDescription())); assertEquals("Resource linkage", "https://tools.ietf.org/html/rfc1149", String.valueOf(resource.getLinkage())); assertEquals("Resource function", OnLineFunction.OFFLINE_ACCESS, resource.getFunction()); // Thanks to xlink:href, the Contact shall be the same instance as above. assertSame("contact", contact, assertResponsibilityEquals(Role.valueOf("funder"), "Robin Hood", it.next())); assertFalse(it.hasNext()); }