[Schmitzm-commits] r347 - branches/1.0-gt2-2.6/src/schmitzm/geotools/feature

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Mon Aug 31 13:37:48 CEST 2009


Author: mojays
Date: 2009-08-31 13:37:47 +0200 (Mon, 31 Aug 2009)
New Revision: 347

Modified:
   branches/1.0-gt2-2.6/src/schmitzm/geotools/feature/FeatureTypeBuilderTableModel.java
   branches/1.0-gt2-2.6/src/schmitzm/geotools/feature/FeatureUtil.java
Log:
gt2-2.6.x conversion bugs eliminated

Modified: branches/1.0-gt2-2.6/src/schmitzm/geotools/feature/FeatureTypeBuilderTableModel.java
===================================================================
--- branches/1.0-gt2-2.6/src/schmitzm/geotools/feature/FeatureTypeBuilderTableModel.java	2009-08-31 11:37:01 UTC (rev 346)
+++ branches/1.0-gt2-2.6/src/schmitzm/geotools/feature/FeatureTypeBuilderTableModel.java	2009-08-31 11:37:47 UTC (rev 347)
@@ -388,7 +388,7 @@
           null
       );
 
-      AutoValueGenerator valueGenerator = null;
+      AutoValueGenerator<?> valueGenerator = null;
       if ( autoValue.getValue() ) {
         if ( Number.class.isAssignableFrom(type) )
           valueGenerator = new NumberValueGenerator((Number)defaultValue);

Modified: branches/1.0-gt2-2.6/src/schmitzm/geotools/feature/FeatureUtil.java
===================================================================
--- branches/1.0-gt2-2.6/src/schmitzm/geotools/feature/FeatureUtil.java	2009-08-31 11:37:01 UTC (rev 346)
+++ branches/1.0-gt2-2.6/src/schmitzm/geotools/feature/FeatureUtil.java	2009-08-31 11:37:47 UTC (rev 347)
@@ -108,12 +108,12 @@
    *  hinterlegt. */
   public static ResourceProvider RESOURCE = new ResourceProvider( LangUtil.extendPackagePath(FeatureUtil.class,"resource.locales.FeatureResourceBundle"), Locale.ENGLISH );
 
-	/**
-	 * Convenience method to access the {@link ResourceProvider}.
-	*/
-	public static String R(String key, Object... values) {
-		return RESOURCE.getString(key, values);
-	}
+  /**
+   * Convenience method to access the {@link ResourceProvider}.
+   */
+  public static String R(String key, Object... values) {
+    return RESOURCE.getString(key, values);
+  }
 
   private static final Logger LOGGER = LangUtil.createLogger(FeatureUtil.class);
 
@@ -135,7 +135,10 @@
   /** Instance of {@link FilterFactory2}. */
   public static final FilterFactory2 FILTER_FACTORY2 = CommonFactoryFinder.getFilterFactory2(GeoTools.getDefaultHints());
 
-  
+  /** Caches the already created {@link SimpleFeatureBuilder SimpleFeatureBuilders}
+   *  for reusing in {@link #createFeature(SimpleFeatureType, String, Object[])}. */
+  private static Map<SimpleFeatureType, SimpleFeatureBuilder> featureBuilderCache = new HashMap<SimpleFeatureType, SimpleFeatureBuilder>();
+
   /** Join-Types. */
   public static enum JoinType {
     /** The feature of the left collection is taken into the result, even
@@ -739,7 +742,7 @@
         else
           getDefaultAttributeValues(fType2,fValues,0,projAttr);
         // Erweitertes SimpleFeature erzeugen und FeatureCollection fuellen
-        resultFc.add( resultType.create( fValues ) );
+        resultFc.add( createFeature(resultType,fValues ) );
       } else {
         for (SimpleFeature f2 = null; joinedFeatures.hasNext(); ) {
           f2 = joinedFeatures.next();
@@ -749,7 +752,7 @@
           else
             getAttributeValues(f2,fValues,0,projAttr);
           // Erweitertes SimpleFeature erzeugen und FeatureCollection fuellen
-          SimpleFeature feature = resultType.create( fValues );
+          SimpleFeature feature = createFeature(resultType,fValues);
           resultFc.add( feature );
         }
       }
@@ -1070,7 +1073,10 @@
     for ( ;rs.next(); ) {
       for (int i=0; i<rsFeatureType.getAttributeCount(); i++)
         rsFeatureValues[i] = rs.getObject( rsFeatureType.getDescriptor(i).getName().getLocalPart() );
-      rsFeatureCollection.add( rsFeatureType.create(rsFeatureValues) );
+      rsFeatureCollection.add( createFeature(
+          rsFeatureType,
+          rsFeatureValues
+      ));
     }
 
     return rsFeatureCollection;
@@ -1199,6 +1205,21 @@
   }
 
   /**
+   * Returns a {@link SimpleFeatureBuilder} for a given schema from cache.
+   * If schema is not already used, a new builder is created and cached.
+   * @param schema the feature schema
+   * @param forceNewBuilder forces to create and cache a new builder instance
+   */
+  private static SimpleFeatureBuilder getFeatureBuilderFromCache(SimpleFeatureType schema, boolean forceNewBuilder) {
+    SimpleFeatureBuilder builder = featureBuilderCache.get(schema);
+    if ( builder == null || forceNewBuilder ) {
+      builder = new SimpleFeatureBuilder(schema);
+      featureBuilderCache.put(schema, builder);
+    }
+    return builder;
+  }
+
+  /**
    * Registriert einen {@link AutoValueGenerator} fuer einen {@link AttributeDescriptor}, so
    * dass {@link #getNextAutoValue(AttributeDescriptor)} fuer diesen {@link AttributeDescriptor}
    * verwendet werden kann.
@@ -1235,23 +1256,53 @@
    *            kein {@link AutoValueGenerator} registriert ist
    */
   public static Object getNextAutoValue(AttributeDescriptor aType) {
-    AutoValueGenerator avg = getAutoValueGenerator(aType);
+    AutoValueGenerator<?> avg = getAutoValueGenerator(aType);
     if ( avg == null )
       throw new UnsupportedOperationException("No AutoValueGenerator registered for attribute type: "+aType.getLocalName());
     return avg.getNextValue();
   }
+    
+  /**
+   * Creates a new feature for a given schema.
+   * @param schema     schema for the feature
+   * @param forceNewBuilder forces the creation of a new {@link SimpleFeatureBuilder}
+   * @param fID        feature id for the new feature
+   * @param attrValues values of the attributes
+   */
+  public static SimpleFeature createFeature(SimpleFeatureType schema, boolean forceNewBuilder, String fID, Object... attrValues) {
+    SimpleFeatureBuilder builder = getFeatureBuilderFromCache(schema, forceNewBuilder);
+    return builder.buildFeature(fID, attrValues);
+  }
   
+  /**
+   * Creates a new feature for a given schema.
+   * @param schema     schema for the feature
+   * @param fID        feature id for the new feature
+   * @param attrValues values of the attributes
+   */
+  public static SimpleFeature createFeature(SimpleFeatureType schema, String fID, Object... attrValues) {
+    return createFeature(schema, false, fID, attrValues);
+  }
 
+  /**
+   * Creates a new feature for a given schema with a random generated id.
+   * @param schema     schema for the feature
+   * @param attrValues values of the attributes
+   */
+  public static SimpleFeature createFeature(SimpleFeatureType schema, Object... attrValues) {
+    return createFeature(
+        schema,
+        "FID_" + new Random().nextInt(),
+        attrValues
+    );
+  }
+  
 	/**
 	 * Creates a sample SimpleFeature instance of the given {@link SimpleFeatureType}
-	 * 
 	 * @param schema
 	 *            the schema for which to create a sample SimpleFeature instance
-	 *            
 	 * @author SK
-	 * 
 	 * @throws org.opengis.feature.IllegalAttributeException
-	 * 
 	 */
 	public static SimpleFeature createSampleFeature(SimpleFeatureType schema) {
 		SimpleFeature sampleFeature;



More information about the Schmitzm-commits mailing list