final T previous = map.putSpecialized(authority, value); if (previous != null && !previous.equals(value)) { Context.warningOccured(context, IdentifierMap.class, "putSpecialized", Errors.class, Errors.Keys.InconsistentAttribute_2, authority.getName(), value); map.putSpecialized(authority, previous);
/** * 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); } } }
/** * Invoked by JAXB for specifying the unique identifier. * * @see org.apache.sis.metadata.iso.ISOMetadata#setUUID(String) */ private void setUUID(final String id) { getIdentifierMap().put(IdentifierSpace.UUID, id); } }
/** * 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)); }
/** * 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)); }
String id = Context.getObjectID(context, object); if (id == null) { id = object.getIdentifierMap().getSpecialized(IdentifierSpace.ID); if (id != null) { final StringBuilder buffer = new StringBuilder();
/** * 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()); }
/** * 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)); }
String id = Context.getObjectID(context, object); if (id == null) { id = object.getIdentifierMap().getSpecialized(IdentifierSpace.ID); if (id != null) { final StringBuilder buffer = new StringBuilder();
final T previous = map.putSpecialized(authority, value); if (previous != null && !previous.equals(value)) { Context.warningOccured(context, IdentifierMap.class, "putSpecialized", Errors.class, Errors.Keys.InconsistentAttribute_2, authority.getName(), value); map.putSpecialized(authority, previous);
/** * 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); } } }
/** * Invoked by JAXB for specifying the unique identifier. * * @see org.apache.sis.metadata.iso.ISOMetadata#setUUID(String) */ @SuppressWarnings("unused") private void setUUID(final String id) { getIdentifierMap().put(IdentifierSpace.UUID, id); } }
XLink link = map.getSpecialized(IdentifierSpace.XLINK); UUID uuid = map.getSpecialized(IdentifierSpace.UUID); if (uuid != null || link != null) {
/** * Sets the International Standard Serial Number. * In this SIS implementation, invoking this method is equivalent to: * * {@preformat java * getIdentifierMap().putSpecialized(Citations.ISSN, newValue); * } * * @param newValue the new ISSN. * * @see #setIdentifiers(Collection) * @see Citations#ISSN */ public void setISSN(final String newValue) { checkWritePermission(); if (newValue != null || !isNullOrEmpty(identifiers)) { getIdentifierMap().putSpecialized(Citations.ISSN, newValue); } }
/** * 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); }
/** * Sets an unique identifier. * This method is invoked automatically by JAXB and should never be invoked explicitely. */ private void setUUID(final String id) { /* * IdentifierMapAdapter will take care of converting the String to UUID if possible, or * will store the value as a plain String if it can not be converted. In the later case, * a warning will be emitted (logged or processed by listeners). */ getIdentifierMap().put(IdentifierSpace.UUID, id); } }
XLink link = map.getSpecialized(IdentifierSpace.XLINK); UUID uuid = map.getSpecialized(IdentifierSpace.UUID); if (uuid != null || link != null) {
/** * Invoked by {@code setID(String)} method implementations for assigning an identifier to an object * at unmarshalling time. * * @param object the object for which to assign an identifier. * @param id the {@code gco:id} or {@code gml:id} value. * * @since 0.7 */ public static void setObjectID(final IdentifiedObject object, String id) { id = CharSequences.trimWhitespaces(id); if (id != null && !id.isEmpty()) { object.getIdentifierMap().putSpecialized(IdentifierSpace.ID, id); final Context context = Context.current(); if (!Context.setObjectForID(context, object, id)) { Context.warningOccured(context, object.getClass(), "setID", Errors.class, Errors.Keys.DuplicatedIdentifier_1, id); } } } }
/** * 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); }
/** * Sets an unique identifier. * This method is invoked automatically by JAXB and should never be invoked explicitly. */ private void setUUID(final String id) { /* * IdentifierMapAdapter will take care of converting the String to UUID if possible, or * will store the value as a plain String if it can not be converted. In the later case, * a warning will be emitted (logged or processed by listeners). */ getIdentifierMap().put(IdentifierSpace.UUID, id); } }