/** * Creates a new GML object wrapping the given GeoAPI implementation. * The ID will be determined from the given object. * * <p>This constructor is typically invoked at marshalling time. The {@link #id} * value set by this constructor will be used by JAXB for producing the XML.</p> * * @param wrapped an instance of a GeoAPI interface to be wrapped. */ protected GMLAdapter(final Object wrapped) { if (wrapped instanceof IdentifiedObject) { final IdentifierMap map = ((IdentifiedObject) wrapped).getIdentifierMap(); if (map != null) { // Should not be null, but let be safe. id = map.get(IdentifierSpace.ID); } } }
/** * Tests read operations on an {@link IdentifierMap} using specific API. */ @Test public void testGetSpecialized() { final List<Identifier> identifiers = new ArrayList<>(); final IdentifierMap map = new ModifiableIdentifierMap(identifiers); assertNull(map.put(ID, "myID")); assertNull(map.put(UUID, "a1eb6e53-93db-4942-84a6-d9e7fb9db2c7")); assertNull(map.put(HREF, "http://mylink")); assertMapEquals("{gml:id=“myID”," + " gco:uuid=“a1eb6e53-93db-4942-84a6-d9e7fb9db2c7”," + " xlink:href=“http://mylink”}", map); assertEquals("myID", map.get (ID)); assertEquals("a1eb6e53-93db-4942-84a6-d9e7fb9db2c7", map.get (UUID)); assertEquals("http://mylink", map.get (HREF)); assertEquals("myID", map.getSpecialized(ID)); assertEquals(URI.create("http://mylink"), map.getSpecialized(HREF)); assertEquals(fromString("a1eb6e53-93db-4942-84a6-d9e7fb9db2c7"), map.getSpecialized(UUID)); }
/** * Invoked by JAXB for fetching the unique identifier unique "worldwide". * * @see org.apache.sis.metadata.iso.ISOMetadata#getUUID() */ @XmlAttribute // Defined in "gco" as unqualified attribute. @XmlJavaTypeAdapter(CollapsedStringAdapter.class) private String getUUID() { return isNullOrEmpty(identifiers) ? null : getIdentifierMap().get(IdentifierSpace.UUID); }
/** * Tests write operations on an {@link IdentifierMap} using specific API. */ @Test public void testPutSpecialized() { final List<Identifier> identifiers = new ArrayList<>(); final IdentifierMap map = new ModifiableIdentifierMap(identifiers); final String myID = "myID"; final java.util.UUID myUUID = fromString("a1eb6e53-93db-4942-84a6-d9e7fb9db2c7"); final URI myURI = URI.create("http://mylink"); assertNull(map.putSpecialized(ID, myID)); assertNull(map.putSpecialized(UUID, myUUID)); assertNull(map.putSpecialized(HREF, myURI)); assertMapEquals("{gml:id=“myID”," + " gco:uuid=“a1eb6e53-93db-4942-84a6-d9e7fb9db2c7”," + " xlink:href=“http://mylink”}", map); assertSame(myID, map.getSpecialized(ID)); assertSame(myUUID, map.getSpecialized(UUID)); assertSame(myURI, map.getSpecialized(HREF)); assertEquals("myID", map.get(ID)); assertEquals("a1eb6e53-93db-4942-84a6-d9e7fb9db2c7", map.get(UUID)); assertEquals("http://mylink", map.get(HREF)); }
/** * Creates a new GML object wrapping the given GeoAPI implementation. * The ID will be determined from the given object. * * <p>This constructor is typically invoked at marshalling time. The {@link #id} * value set by this constructor will be used by JAXB for producing the XML.</p> * * @param wrapped an instance of a GeoAPI interface to be wrapped. */ protected GMLAdapter(final Object wrapped) { if (wrapped instanceof IdentifiedObject) { final IdentifierMap map = ((IdentifiedObject) wrapped).getIdentifierMap(); if (map != null) { // Should not be null, but let be safe. id = map.get(IdentifierSpace.ID); } } }
/** * Tests explicitly the special handling of {@code href} values. */ @Test public void testHRefSubstitution() { final List<Identifier> identifiers = new ArrayList<>(); final IdentifierMap map = new ModifiableIdentifierMap(identifiers); assertNull(map.put(HREF, "myHREF")); assertEquals("Shall contain the entry we added.", "myHREF", map.get(HREF)); // Check the XLink object final XLink link = map.getSpecialized(XLINK); assertEquals("Added href shall be stored as XLink attribute.", "myHREF", String.valueOf(link.getHRef())); assertEquals("Identifier list shall contain the XLink.", link.toString(), getSingleton(identifiers).getCode()); // Modidfy the XLink object directly link.setHRef(URI.create("myNewHREF")); assertEquals("Change in XLink shall be reflected in href.", "myNewHREF", map.get(HREF)); }
/** * Invoked by JAXB for fetching the unique identifier unique "worldwide". * * @see org.apache.sis.metadata.iso.ISOMetadata#getUUID() */ @XmlAttribute // Defined in "gco" as unqualified attribute. @XmlJavaTypeAdapter(CollapsedStringAdapter.class) private String getUUID() { return isNullOrEmpty(identifiers) ? null : getIdentifierMap().get(IdentifierSpace.UUID); }
/** * Returns an unique identifier, or {@code null} if none. * This method is invoked automatically by JAXB and should never be invoked explicitely. */ @XmlAttribute // Defined in "gco" as unqualified attribute. @XmlJavaTypeAdapter(CollapsedStringAdapter.class) private String getUUID() { /* * IdentifierMapAdapter will take care of converting UUID to String, * or to return a previously stored String if it was an unparsable UUID. */ return isNullOrEmpty(identifiers) ? null : getIdentifierMap().get(IdentifierSpace.UUID); }
/** * Returns an unique identifier, or {@code null} if none. * This method is invoked automatically by JAXB and should never be invoked explicitly. */ @XmlAttribute // Defined in "gco" as unqualified attribute. @XmlJavaTypeAdapter(CollapsedStringAdapter.class) private String getUUID() { /* * IdentifierMapAdapter will take care of converting UUID to String, * or to return a previously stored String if it was an unparsable UUID. */ return isNullOrEmpty(identifiers) ? null : getIdentifierMap().get(IdentifierSpace.UUID); }
/** * Returns the ISBN or ISSN identifier for the given authority, or {@code null} if none. */ private String getIdentifier(final Citation authority) { return isNullOrEmpty(identifiers) ? null : getIdentifierMap().get(authority); }
/** * Returns the International Standard Serial Number. * In this SIS implementation, invoking this method is equivalent to: * * {@preformat java * return getIdentifierMap().getSpecialized(Citations.ISSN); * } * * @return the ISSN, or {@code null} if none. * * @see #getIdentifiers() * @see Citations#ISSN */ @Override @XmlElement(name = "ISSN") public String getISSN() { return isNullOrEmpty(identifiers) ? null : getIdentifierMap().get(Citations.ISSN); }
/** * Returns the International Standard Book Number. * In this SIS implementation, invoking this method is equivalent to: * * {@preformat java * return getIdentifierMap().getSpecialized(Citations.ISBN); * } * * @return the ISBN, or {@code null} if none. * * @see #getIdentifiers() * @see Citations#ISBN */ @Override @XmlElement(name = "ISBN") public String getISBN() { return isNullOrEmpty(identifiers) ? null : getIdentifierMap().get(Citations.ISBN); }
/** * Tests the handling of duplicated authorities. */ @Test public void testDuplicatedAuthorities() { final List<Identifier> identifiers = new ArrayList<>(); assertTrue(identifiers.add(new IdentifierMapEntry(ID, "myID1"))); assertTrue(identifiers.add(new IdentifierMapEntry(UUID, "myUUID"))); assertTrue(identifiers.add(new IdentifierMapEntry(ID, "myID2"))); final IdentifierMap map = new ModifiableIdentifierMap(identifiers); assertEquals("Duplicated authorities shall be filtered.", 2, map.size()); assertEquals("Duplicated authorities shall still exist.", 3, identifiers.size()); assertEquals("myID1", map.get(ID)); assertEquals("myUUID", map.get(UUID)); final Iterator<Citation> it = map.keySet().iterator(); assertTrue(it.hasNext()); assertSame(ID, it.next()); it.remove(); assertTrue(it.hasNext()); assertSame(UUID, it.next()); assertFalse("Duplicated authority shall have been removed.", it.hasNext()); assertEquals(1, identifiers.size()); assertEquals(1, map.size()); }