UuidFeatureIdRetriever.java

  1. package de.turnertech.ows.gml;

  2. import java.util.UUID;

  3. /**
  4.  * Defines the logic for unique ID generation. This implementation will generate a UUID
  5.  * if no ID was already present, and will set it on the supplied object!
  6.  *
  7.  * If you only want to check if the ID is present, use the .getId() function of the
  8.  * object.
  9.  *
  10.  * This class will be of value in TransactionHandlers. There we will be handling new
  11.  * instances of {@link IFeature} which may not have been sent with an ID parameter.
  12.  */
  13. public class UuidFeatureIdRetriever implements FeatureIdRetriever {
  14.    
  15.     @Override
  16.     public String retrieveFeatureId(IFeature feature) {
  17.         String id = feature.getId();

  18.         if(id == null) {
  19.             FeatureProperty idProperty = feature.getFeatureType().getIdProperty();
  20.             if(idProperty != null) {
  21.                 id = UUID.randomUUID().toString();
  22.                 feature.setPropertyValue(idProperty.getName(), id);
  23.             }
  24.         }

  25.         return id;
  26.     }

  27. }