/** * Invoked by JAXB at both marshalling and unmarshalling time. * This attribute has been added by ISO 19115:2014 standard. * If (and only if) marshalling an older standard version, we omit this attribute. */ @XmlElement(name = "phone") private Collection<Telephone> getPhoneList() { return FilterByVersion.CURRENT_METADATA.accept() ? getPhones() : null; }
public Telephone getPhone() { Telephone phone = null; final Collection<Telephone> phones = getPhones(); if (phones != null) { // May be null on marshalling. CodeList<?> ignored = null;
Telephone phone = null; if (FilterByVersion.LEGACY_METADATA.accept()) { final Collection<Telephone> phones = getPhones(); if (phones != null) { // May be null on marshalling. CodeList<?> ignored = null;
new DefaultTelephone("00.04", UnsupportedCodeList.VOICE), new DefaultTelephone("00.03", UnsupportedCodeList.FACSIMILE) }, contact.getPhones().toArray());
/** * 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 the ISO 19115:2014 {@link DefaultContact#setPhones(Collection)} method, * then query with both the new and the deprecated methods. */ @Test @SuppressWarnings("deprecation") public void testSetPhones() { init(); final DefaultTelephone tel1 = new DefaultTelephone("00.01", UnsupportedCodeList.valueOf("SMS")); final DefaultTelephone tel2 = new DefaultTelephone("00.02", UnsupportedCodeList.VOICE); final DefaultTelephone tel3 = new DefaultTelephone("00.03", UnsupportedCodeList.FACSIMILE); final DefaultTelephone tel4 = new DefaultTelephone("00.04", UnsupportedCodeList.VOICE); final DefaultTelephone[] tels = new DefaultTelephone[] {tel1, tel2, tel3, tel4}; final DefaultContact contact = new DefaultContact(); contact.setPhones(Arrays.asList(tel1, tel2, tel3, tel4)); assertArrayEquals("getPhones", tels, contact.getPhones().toArray()); /* * Test the deprecated 'getPhone()' method. Invoking that method shall emit * a warning, since the ISO 19115:2003 methods can not represent SMS numbers. */ assertSame("getPhone", tel2, contact.getPhone()); // Shall ignore the TelephoneType.SMS. assertEquals("warningOccured", "IgnoredPropertyAssociatedTo_1", resourceKey); assertArrayEquals("warningOccured", new String[] {"SMS"}, parameters); verifyLegacyLists(tels); }