[Schmitzm-commits] r1228 - trunk/src/skrueger/geotools

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Wed Nov 3 21:44:17 CET 2010


Author: alfonx
Date: 2010-11-03 21:44:16 +0100 (Wed, 03 Nov 2010)
New Revision: 1228

Modified:
   trunk/src/skrueger/geotools/StyledFS.java
   trunk/src/skrueger/geotools/StyledFeaturesInterface.java
   trunk/src/skrueger/geotools/StyledLayerInterface.java
   trunk/src/skrueger/geotools/StyledLayerUtil.java
Log:
c

Modified: trunk/src/skrueger/geotools/StyledFS.java
===================================================================
--- trunk/src/skrueger/geotools/StyledFS.java	2010-11-03 20:14:09 UTC (rev 1227)
+++ trunk/src/skrueger/geotools/StyledFS.java	2010-11-03 20:44:16 UTC (rev 1228)
@@ -53,6 +53,7 @@
 import schmitzm.geotools.io.GeoImportUtil;
 import schmitzm.geotools.styling.StylingUtil;
 import skrueger.AttributeMetadataImpl;
+import skrueger.AttributeMetadataInterface;
 import skrueger.i8n.Translation;
 
 import com.vividsolutions.jts.geom.Envelope;
@@ -88,7 +89,7 @@
 	private File sldFile;
 
 	/** A map of simple attribute names to their meta-data **/
-	private AttributeMetadataMap<AttributeMetadataImpl> map;
+	private AttributeMetadataMap<AttributeMetadataImpl> attMap;
 
 	private Filter filter = Filter.INCLUDE;
 
@@ -271,41 +272,13 @@
 	/**
 	 * 
 	 */
+	@Override
 	public AttributeMetadataMap<AttributeMetadataImpl> getAttributeMetaDataMap() {
-		if (map == null) {
-
-			map = new AttributeMetadataImplMap();
-
-			// // Leaving out the first one, it will be the_geom
-			// for (int i = 1; i < fs.getSchema().getAttributeCount(); i++) {
-			// AttributeDescriptor attDesc = fs.getSchema().getDescriptor(i);
-			//
-			// AttributeMetadataImpl attMetaData = new AttributeMetadataImpl(
-			// new NameImpl(attDesc
-			// .getName().getNamespaceURI(), attDesc
-			// .getName().getLocalPart()), map.getLanguages());
-			// map.put(attDesc.getName(), attMetaData);
-			// }
-
-			// Leaving out the first one, it will be the_geom
-			for (int i = 1; i < fs.getSchema().getAttributeCount(); i++) {
-				AttributeDescriptor attDesc = fs.getSchema().getDescriptor(i);
-
-				// TODO AttributeMetadataAS would be nicer, which would not work
-				// with Translations ;-)
-				AttributeMetadataImpl attMetaData = new AttributeMetadataImpl(
-						new NameImpl(attDesc.getName().getNamespaceURI(),
-								attDesc.getName().getLocalPart()),
-						map.getLanguages());
-				if (String.class.isAssignableFrom(attDesc.getType()
-						.getBinding())) {
-					// For Strings we add the "" as NODATA values
-					attMetaData.addNodataValue("");
-				}
-				map.put(attDesc.getName(), attMetaData);
-			}
+		if (attMap == null) {
+			attMap = StyledLayerUtil
+					.createDefaultAttributeMetadataMap(getSchema());
 		}
-		return map;
+		return attMap;
 	}
 
 	/**

Modified: trunk/src/skrueger/geotools/StyledFeaturesInterface.java
===================================================================
--- trunk/src/skrueger/geotools/StyledFeaturesInterface.java	2010-11-03 20:14:09 UTC (rev 1227)
+++ trunk/src/skrueger/geotools/StyledFeaturesInterface.java	2010-11-03 20:44:16 UTC (rev 1228)
@@ -36,6 +36,7 @@
 import org.opengis.filter.Filter;
 
 import skrueger.AttributeMetadataImpl;
+import skrueger.AttributeMetadataInterface;
 
 /**
  * This Interface combines all styled layers that are running on

Modified: trunk/src/skrueger/geotools/StyledLayerInterface.java
===================================================================
--- trunk/src/skrueger/geotools/StyledLayerInterface.java	2010-11-03 20:14:09 UTC (rev 1227)
+++ trunk/src/skrueger/geotools/StyledLayerInterface.java	2010-11-03 20:44:16 UTC (rev 1228)
@@ -39,6 +39,7 @@
 import org.opengis.referencing.crs.CoordinateReferenceSystem;
 
 import skrueger.AttributeMetadataImpl;
+import skrueger.AttributeMetadataInterface;
 import skrueger.RasterLegendData;
 import skrueger.i8n.Translation;
 
@@ -86,9 +87,9 @@
  * <ul>
  * <li>layer list only depends on {@link StyledLayerInterface}</li>
  * <li>methods returning {@link Translation} must not return {@code null}</li>
- * <li>methods returning {@link AttributeMetadataImpl}-Map must not return {@code
+ * <li>methods returning {@link AttributeMetadataInterface}-Map must not return {@code
  * null}</li>
- * <li>static helper method to get a new {@link AttributeMetadataImpl}-map withe the
+ * <li>static helper method to get a new {@link AttributeMetadataImpl}-map with the
  * visible attributes only</li>
  * <li>static helper method to create a "default" {@link AttributeMetadataImpl}-map
  * for a {@link FeatureCollection} with all attributes visible and without real

Modified: trunk/src/skrueger/geotools/StyledLayerUtil.java
===================================================================
--- trunk/src/skrueger/geotools/StyledLayerUtil.java	2010-11-03 20:14:09 UTC (rev 1227)
+++ trunk/src/skrueger/geotools/StyledLayerUtil.java	2010-11-03 20:44:16 UTC (rev 1228)
@@ -99,6 +99,8 @@
 import skrueger.RasterLegendData;
 import skrueger.i8n.Translation;
 
+import com.vividsolutions.jts.geom.Geometry;
+
 /**
  * This class provides static helper methods for dealing with
  * {@link StyledLayerInterface} stuff.
@@ -1363,4 +1365,37 @@
 		}
 		return nicelyFormatted;
 	}
+
+	/**
+	 * Creates a new {@link AttributeMetadataMap} with instances of
+	 * {@link AttributeMetadataInterface} for every non-geometry attribute.
+	 * Default NODATA values (like "" for String) are set.
+	 */
+	public static AttributeMetadataMap<AttributeMetadataImpl> createDefaultAttributeMetadataMap(
+			SimpleFeatureType schema) {
+		AttributeMetadataImplMap attMap = new AttributeMetadataImplMap();
+
+		for (int i = 0; i < schema.getAttributeCount(); i++) {
+			AttributeDescriptor attDesc = schema.getDescriptor(i);
+
+			if (Geometry.class.isAssignableFrom(attDesc.getType().getBinding())) {
+				// Ignore the Geometry column
+				continue;
+			}
+
+			// TODO AttributeMetadataAS would be nicer, which would not work
+			// with Translations ;-)
+			AttributeMetadataImpl attMetaData = new AttributeMetadataImpl(
+					new NameImpl(attDesc.getName().getNamespaceURI(), attDesc
+							.getName().getLocalPart()), attMap.getLanguages());
+
+			if (String.class.isAssignableFrom(attDesc.getType().getBinding())) {
+				// For Strings we add the "" as NODATA values
+				attMetaData.addNodataValue("");
+			}
+
+			attMap.put(attDesc.getName(), attMetaData);
+		}
+		return attMap;
+	}
 }



More information about the Schmitzm-commits mailing list