[Schmitzm-commits] r770 - in trunk/src: schmitzm/geotools/feature skrueger skrueger/geotools

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Sun Mar 21 12:36:12 CET 2010


Author: alfonx
Date: 2010-03-21 12:36:11 +0100 (Sun, 21 Mar 2010)
New Revision: 770

Modified:
   trunk/src/schmitzm/geotools/feature/FeatureUtil.java
   trunk/src/skrueger/AbstractAttributeMetadata.java
   trunk/src/skrueger/AttributeMetadata.java
   trunk/src/skrueger/AttributeMetadataImpl.java
   trunk/src/skrueger/geotools/AttributeMetadataImplMap.java
   trunk/src/skrueger/geotools/AttributeMetadataMap.java
   trunk/src/skrueger/geotools/StyledFS.java
   trunk/src/skrueger/geotools/StyledFeatureCollection.java
   trunk/src/skrueger/geotools/StyledLayerUtil.java
Log:
Had to switch the AttributeMetadata key from org.opengis.feature.type.Name to geotools.NameImpl. That sounds not-so-nice, because it is generally better to program against an interface instead of an implementation, BUT NameImpl implements Serializable which is a big help when i want to map that AttributeMetaDataMap in another project.

Modified: trunk/src/schmitzm/geotools/feature/FeatureUtil.java
===================================================================
--- trunk/src/schmitzm/geotools/feature/FeatureUtil.java	2010-03-21 11:02:34 UTC (rev 769)
+++ trunk/src/schmitzm/geotools/feature/FeatureUtil.java	2010-03-21 11:36:11 UTC (rev 770)
@@ -2251,7 +2251,7 @@
 	 * 
 	 * @return If no match is found, <code>null</code> is returned.
 	 */
-	public static org.opengis.feature.type.Name findBestMatchingAttribute(
+	public static NameImpl findBestMatchingAttribute(
 			SimpleFeatureType schema, String localName) {
 
 		if (localName == null) {
@@ -2268,14 +2268,14 @@
 		// Checking for exact match
 		for (AttributeDescriptor d : attributeDescriptors) {
 			if (d.getName().getLocalPart().equals(localName))
-				return d.getName();
+				return new NameImpl( d.getName().getNamespaceURI(), d.getName().getLocalPart() );
 		}
 		// Checking for irgnoreCase match
 		for (AttributeDescriptor d : attributeDescriptors) {
 			if (d.getName().getLocalPart().equalsIgnoreCase(localName)) {
 				LOGGER.error("Corrected attributeName '" + localName + "' to "
 						+ d.getName().getLocalPart());
-				return d.getName();
+				return new NameImpl( d.getName().getNamespaceURI(), d.getName().getLocalPart() );
 			}
 		}
 
@@ -2285,7 +2285,7 @@
 					localName.replace(" ", "_"))) {
 				LOGGER.error("Corrected attributeName '" + localName + "' to "
 						+ d.getName().getLocalPart());
-				return d.getName();
+				return new NameImpl( d.getName().getNamespaceURI(), d.getName().getLocalPart() );
 			}
 		}
 		return null;

Modified: trunk/src/skrueger/AbstractAttributeMetadata.java
===================================================================
--- trunk/src/skrueger/AbstractAttributeMetadata.java	2010-03-21 11:02:34 UTC (rev 769)
+++ trunk/src/skrueger/AbstractAttributeMetadata.java	2010-03-21 11:36:11 UTC (rev 770)
@@ -11,7 +11,7 @@
 public abstract class AbstractAttributeMetadata implements AttributeMetadata {
 
 	/** The Name of the attribute. This is the 'primary key' **/
-	protected Name name;
+	protected NameImpl name;
 
 	/** {@link Translation}s of the attribute's title **/
 	protected Translation title = new Translation();
@@ -94,7 +94,7 @@
 	 * <code>org.bla.plo:blub</code>
 	 */
 	@Override
-	public Name getName() {
+	public NameImpl getName() {
 		return name;
 	}
 
@@ -116,7 +116,7 @@
 	 * <code>org.bla.plo:blub</code>
 	 */
 	@Override
-	public void setName(final Name name) {
+	public void setName(final NameImpl name) {
 		this.name = name;
 	}
 

Modified: trunk/src/skrueger/AttributeMetadata.java
===================================================================
--- trunk/src/skrueger/AttributeMetadata.java	2010-03-21 11:02:34 UTC (rev 769)
+++ trunk/src/skrueger/AttributeMetadata.java	2010-03-21 11:36:11 UTC (rev 770)
@@ -2,6 +2,7 @@
 
 import java.util.HashSet;
 
+import org.geotools.feature.NameImpl;
 import org.opengis.feature.type.Name;
 
 import skrueger.geotools.Copyable;
@@ -46,12 +47,12 @@
 	 * {@link #getLocalName()} value. The first may be <code>null</code> or
 	 * represent the layer name.
 	 */
-	public Name getName();
+	public NameImpl getName();
 
 	/**
 	 * set the fully qualified {@link Name} of this attribute.
 	 */
-	public void setName(Name name);
+	public void setName(NameImpl name);
 
 	/**
 	 * A list og objects that represent NODATA-values for this attribute. The

Modified: trunk/src/skrueger/AttributeMetadataImpl.java
===================================================================
--- trunk/src/skrueger/AttributeMetadataImpl.java	2010-03-21 11:02:34 UTC (rev 769)
+++ trunk/src/skrueger/AttributeMetadataImpl.java	2010-03-21 11:36:11 UTC (rev 770)
@@ -35,7 +35,6 @@
 import org.apache.log4j.Logger;
 import org.geotools.feature.NameImpl;
 import org.opengis.feature.type.AttributeDescriptor;
-import org.opengis.feature.type.Name;
 
 import skrueger.geotools.Copyable;
 import skrueger.geotools.StyledLayerInterface;
@@ -72,13 +71,13 @@
 
 	public AttributeMetadataImpl(final AttributeDescriptor attDesc,
 			final int weight, final List<String> langs) {
-		this(attDesc.getName(), langs);
+		this( new NameImpl(attDesc.getName().getNamespaceURI(), attDesc.getName().getLocalPart()), langs);
 		setWeight(weight);
 	}
 
 	public AttributeMetadataImpl(final AttributeDescriptor attDesc,
 			final List<String> langs) {
-		this(attDesc.getName(), langs);
+		this(new NameImpl(attDesc.getName().getNamespaceURI(), attDesc.getName().getLocalPart()), langs);
 	}
 
 	/**
@@ -97,7 +96,7 @@
 	 * @param unit
 	 *            {@link String} of the unit that the information is in
 	 */
-	public AttributeMetadataImpl(final Name name, final Boolean visible,
+	public AttributeMetadataImpl(final NameImpl name, final Boolean visible,
 			final Translation title, final Translation desc, final String unit) {
 
 		this.setName(name);
@@ -119,7 +118,7 @@
 	 * @param unit
 	 *            {@link String} of the unit that the information is in
 	 */
-	public AttributeMetadataImpl(final Name name, final Boolean visible,
+	public AttributeMetadataImpl(final NameImpl name, final Boolean visible,
 			final String unit) {
 		this.setName(name);
 		this.visible = visible;
@@ -129,7 +128,7 @@
 	/**
 	 * Creates a new visible {@link AttributeMetadataImpl}
 	 */
-	public AttributeMetadataImpl(final Name name, final List<String> langs) {
+	public AttributeMetadataImpl(final NameImpl name, final List<String> langs) {
 		this(name, true, new Translation(langs, name.getLocalPart()),
 				new Translation(), "");
 	}
@@ -137,7 +136,7 @@
 	/**
 	 * Creates a new visible {@link AttributeMetadataImpl}
 	 */
-	public AttributeMetadataImpl(final Name name, final String defaultTitle,
+	public AttributeMetadataImpl(final NameImpl name, final String defaultTitle,
 			final List<String> langs) {
 		this(name, true, new Translation(langs, defaultTitle),
 				new Translation(), "");

Modified: trunk/src/skrueger/geotools/AttributeMetadataImplMap.java
===================================================================
--- trunk/src/skrueger/geotools/AttributeMetadataImplMap.java	2010-03-21 11:02:34 UTC (rev 769)
+++ trunk/src/skrueger/geotools/AttributeMetadataImplMap.java	2010-03-21 11:36:11 UTC (rev 770)
@@ -2,12 +2,16 @@
 
 import java.util.List;
 
+import org.geotools.feature.NameImpl;
 import org.opengis.feature.type.Name;
 
 import skrueger.AttributeMetadataImpl;
 
 public class AttributeMetadataImplMap extends AttributeMetadataMap<AttributeMetadataImpl> {
 
+	private static final long serialVersionUID = 6781939984242527498L;
+
+
 	public AttributeMetadataImplMap(List<String> langs) {
 		super(langs);
 	}
@@ -32,7 +36,7 @@
 	 * fly.
 	 */
 	@Override
-	public AttributeMetadataImpl get(final Name name) {
+	public AttributeMetadataImpl get(final NameImpl name) {
 		final AttributeMetadataImpl AttributeMetadataImpl = super.get(name);
 		if (AttributeMetadataImpl == null && name != null
 				&& !name.getLocalPart().trim().isEmpty()) {

Modified: trunk/src/skrueger/geotools/AttributeMetadataMap.java
===================================================================
--- trunk/src/skrueger/geotools/AttributeMetadataMap.java	2010-03-21 11:02:34 UTC (rev 769)
+++ trunk/src/skrueger/geotools/AttributeMetadataMap.java	2010-03-21 11:36:11 UTC (rev 770)
@@ -23,7 +23,7 @@
  * <code>null</code>, but rather create a default {@link AMD_IMPL} on-the-fly.
  */
 public abstract class AttributeMetadataMap<AMD_IMPL extends AttributeMetadata>
-		extends TreeMap<Name, AMD_IMPL> implements
+		extends TreeMap<NameImpl, AMD_IMPL> implements
 		Copyable<AttributeMetadataMap>, QualityQuantizable {
 
 	private static final long serialVersionUID = 4936966916517396063L;
@@ -75,7 +75,7 @@
 
 		amdMap.clear();
 
-		for (final Name key : keySet()) {
+		for (final NameImpl key : keySet()) {
 			final AMD_IMPL AMD_IMPL = get(key);
 			amdMap.put(key, AMD_IMPL.copy());
 		}
@@ -83,11 +83,11 @@
 	}
 
 	/**
-	 * Returns the {@link AMD_IMPL} for a given {@link Name}. May return
+	 * Returns the {@link AMD_IMPL} for a given {@link NameImpl}. May return
 	 * <code>null</code> or create a default {@link AttributeMetadata} depending
 	 * on whether this method is overwritten. fly.
 	 */
-	public AMD_IMPL get(final Name name) {
+	public AMD_IMPL get(final NameImpl name) {
 		return super.get(name);
 	}
 

Modified: trunk/src/skrueger/geotools/StyledFS.java
===================================================================
--- trunk/src/skrueger/geotools/StyledFS.java	2010-03-21 11:02:34 UTC (rev 769)
+++ trunk/src/skrueger/geotools/StyledFS.java	2010-03-21 11:36:11 UTC (rev 770)
@@ -41,6 +41,7 @@
 import org.apache.log4j.Logger;
 import org.geotools.data.FeatureSource;
 import org.geotools.feature.FeatureCollection;
+import org.geotools.feature.NameImpl;
 import org.geotools.styling.Style;
 import org.opengis.feature.simple.SimpleFeature;
 import org.opengis.feature.simple.SimpleFeatureType;
@@ -259,8 +260,9 @@
 			for (int i = 1; i < fs.getSchema().getAttributeCount(); i++) {
 				AttributeDescriptor attDesc = fs.getSchema().getDescriptor(i);
 
-				AttributeMetadataImpl attMetaData = new AttributeMetadataImpl(attDesc
-						.getName(), map.getLanguages());
+				AttributeMetadataImpl attMetaData = new AttributeMetadataImpl( new NameImpl(attDesc
+						.getName().getNamespaceURI(), attDesc
+						.getName().getLocalPart()), map.getLanguages());
 				map.put(attDesc.getName(), attMetaData);
 			}
 		}

Modified: trunk/src/skrueger/geotools/StyledFeatureCollection.java
===================================================================
--- trunk/src/skrueger/geotools/StyledFeatureCollection.java	2010-03-21 11:02:34 UTC (rev 769)
+++ trunk/src/skrueger/geotools/StyledFeatureCollection.java	2010-03-21 11:36:11 UTC (rev 770)
@@ -38,6 +38,7 @@
 import org.geotools.data.collection.CollectionDataStore;
 import org.geotools.data.store.EmptyFeatureCollection;
 import org.geotools.feature.FeatureCollection;
+import org.geotools.feature.NameImpl;
 import org.geotools.feature.collection.SubFeatureCollection;
 import org.geotools.styling.Style;
 import org.opengis.feature.simple.SimpleFeature;
@@ -319,7 +320,7 @@
 		for (int i = 0; i < ftype.getAttributeCount(); i++) {
 			AttributeDescriptor aDesc = ftype.getAttributeDescriptors().get(i);
 			if (aDesc != ftype.getGeometryDescriptor())
-				metaDataMap.put(aDesc.getName(), new AttributeMetadataImpl(aDesc.getName(), 
+				metaDataMap.put(aDesc.getName(), new AttributeMetadataImpl( new NameImpl( aDesc.getName().getNamespaceURI(), aDesc.getName().getLocalPart()), 
 						true, // visible
 						new Translation(aDesc.getLocalName()), // Column name
 						new Translation(aDesc.getLocalName()), // description

Modified: trunk/src/skrueger/geotools/StyledLayerUtil.java
===================================================================
--- trunk/src/skrueger/geotools/StyledLayerUtil.java	2010-03-21 11:02:34 UTC (rev 769)
+++ trunk/src/skrueger/geotools/StyledLayerUtil.java	2010-03-21 11:36:11 UTC (rev 770)
@@ -289,7 +289,7 @@
 				.getAttributeValue("namespace"));
 		final String localname = String.valueOf(element
 				.getAttributeValue("localname"));
-		final Name aName = new NameImpl(namespace, localname);
+		final NameImpl aName = new NameImpl(namespace, localname);
 		final Boolean visible = Boolean.valueOf(element
 				.getAttributeValue("visible"));
 		final String unit = element.getAttributeValue("unit");
@@ -1265,7 +1265,7 @@
 			AttributeDescriptor foundDescr = schema
 					.getDescriptor(atm.getName());
 			if (foundDescr == null) {
-				Name bestMatch = FeatureUtil.findBestMatchingAttribute(schema,
+				NameImpl bestMatch = FeatureUtil.findBestMatchingAttribute(schema,
 						atm.getLocalName());
 				if (bestMatch == null)
 					willRemove.add(atm.getName());
@@ -1289,7 +1289,7 @@
 			if (ad instanceof GeometryDescriptor)
 				continue;
 			if (!attributeMetaDataMap.containsKey(ad.getName())) {
-				attributeMetaDataMap.put(ad.getName(),
+				attributeMetaDataMap.put( new NameImpl(ad.getName().getNamespaceURI(), ad.getName().getLocalPart()),
 						new AttributeMetadataImpl(ad, schema
 								.getAttributeDescriptors().indexOf(ad),
 								attributeMetaDataMap.getLanguages()));



More information about the Schmitzm-commits mailing list