Author: aaime
Date: 2007-09-30 17:46:16 -0700 (Sun, 30 Sep 2007)
New Revision: 27294
Added:
geotools/trunk/gt/modules/library/legacy/
geotools/trunk/gt/modules/library/legacy/pom.xml
geotools/trunk/gt/modules/library/legacy/src/
geotools/trunk/gt/modules/library/legacy/src/main/
geotools/trunk/gt/modules/library/legacy/src/main/java/
geotools/trunk/gt/modules/library/legacy/src/main/java/org/
geotools/trunk/gt/modules/library/legacy/src/main/java/org/geotools/
geotools/trunk/gt/modules/library/legacy/src/main/java/org/geotools/feature/
geotools/trunk/gt/modules/library/legacy/src/main/java/org/geotools/feature/AttributeType.java
geotools/trunk/gt/modules/library/legacy/src/main/java/org/geotools/feature/AttributeTypeFactory.java
geotools/trunk/gt/modules/library/legacy/src/main/java/org/geotools/feature/DefaultAttributeType.java
geotools/trunk/gt/modules/library/legacy/src/main/java/org/geotools/feature/DefaultAttributeTypeFactory.java
geotools/trunk/gt/modules/library/legacy/src/main/java/org/geotools/feature/DefaultFeature.java
geotools/trunk/gt/modules/library/legacy/src/main/java/org/geotools/feature/DefaultFeatureBuilder.java
geotools/trunk/gt/modules/library/legacy/src/main/java/org/geotools/feature/DefaultFeatureFactory.java
geotools/trunk/gt/modules/library/legacy/src/main/java/org/geotools/feature/DefaultFeatureType.java
geotools/trunk/gt/modules/library/legacy/src/main/java/org/geotools/feature/DefaultFeatureTypeFactory.java
geotools/trunk/gt/modules/library/legacy/src/main/java/org/geotools/feature/DefaultFeatureTypeFactory2.java
geotools/trunk/gt/modules/library/legacy/src/main/java/org/geotools/feature/Feature.java
geotools/trunk/gt/modules/library/legacy/src/main/java/org/geotools/feature/FeatureAttributeType.java
geotools/trunk/gt/modules/library/legacy/src/main/java/org/geotools/feature/FeatureCollectionType.java
geotools/trunk/gt/modules/library/legacy/src/main/java/org/geotools/feature/FeatureType.java
geotools/trunk/gt/modules/library/legacy/src/main/java/org/geotools/feature/FeatureTypeBuilder.java
geotools/trunk/gt/modules/library/legacy/src/main/java/org/geotools/feature/FeatureTypeFactory.java
geotools/trunk/gt/modules/library/legacy/src/main/java/org/geotools/feature/GeometryAttributeType.java
geotools/trunk/gt/modules/library/legacy/src/main/java/org/geotools/feature/MultiAttributeType.java
geotools/trunk/gt/modules/library/legacy/src/main/java/org/geotools/feature/PrimativeAttributeType.java
geotools/trunk/gt/modules/library/legacy/src/main/java/org/geotools/feature/SimpleFeature.java
geotools/trunk/gt/modules/library/legacy/src/main/java/org/geotools/feature/SimpleFeatureType.java
geotools/trunk/gt/modules/library/legacy/src/main/java/org/geotools/feature/type/
geotools/trunk/gt/modules/library/legacy/src/main/java/org/geotools/feature/type/ChoiceAttributeType.java
geotools/trunk/gt/modules/library/legacy/src/main/java/org/geotools/feature/type/DefaultAttributeTypeBuilder.java
geotools/trunk/gt/modules/library/legacy/src/main/java/org/geotools/feature/type/DefaultFeatureTypeBuilder.java
geotools/trunk/gt/modules/library/legacy/src/main/java/org/geotools/feature/type/FeatureAttributeType.java
geotools/trunk/gt/modules/library/legacy/src/main/java/org/geotools/feature/type/GeometricAttributeType.java
geotools/trunk/gt/modules/library/legacy/src/main/java/org/geotools/feature/type/ListAttributeType.java
geotools/trunk/gt/modules/library/legacy/src/main/java/org/geotools/feature/type/NestedAttributeType.java
geotools/trunk/gt/modules/library/legacy/src/main/java/org/geotools/feature/type/NumericAttributeType.java
geotools/trunk/gt/modules/library/legacy/src/main/java/org/geotools/feature/type/SetAttributeType.java
geotools/trunk/gt/modules/library/legacy/src/main/java/org/geotools/feature/type/TemporalAttributeType.java
geotools/trunk/gt/modules/library/legacy/src/main/java/org/geotools/feature/type/TextualAttributeType.java
geotools/trunk/gt/modules/library/legacy/src/test/
geotools/trunk/gt/modules/library/legacy/src/test/java/
geotools/trunk/gt/modules/library/legacy/src/test/java/org/
geotools/trunk/gt/modules/library/legacy/src/test/java/org/geotools/
geotools/trunk/gt/modules/library/legacy/src/test/java/org/geotools/feature/
geotools/trunk/gt/modules/library/legacy/src/test/java/org/geotools/feature/AttributeTypeTest.java
geotools/trunk/gt/modules/library/legacy/src/test/java/org/geotools/feature/FeatureTypeFactoryTest.java
geotools/trunk/gt/modules/library/legacy/src/test/java/org/geotools/feature/FlatFeatureFactorySpiTest.java
geotools/trunk/gt/modules/library/legacy/src/test/java/org/geotools/feature/type/
geotools/trunk/gt/modules/library/legacy/src/test/java/org/geotools/feature/type/DefaultFeatureTypeBuilderTest.java
Removed:
geotools/trunk/gt/modules/library/api/src/main/java/org/geotools/feature/AttributeType.java
geotools/trunk/gt/modules/library/api/src/main/java/org/geotools/feature/Feature.java
geotools/trunk/gt/modules/library/api/src/main/java/org/geotools/feature/FeatureAttributeType.java
geotools/trunk/gt/modules/library/api/src/main/java/org/geotools/feature/FeatureCollectionType.java
geotools/trunk/gt/modules/library/api/src/main/java/org/geotools/feature/FeatureType.java
geotools/trunk/gt/modules/library/api/src/main/java/org/geotools/feature/GeometryAttributeType.java
geotools/trunk/gt/modules/library/api/src/main/java/org/geotools/feature/PrimativeAttributeType.java
geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/AttributeTypeFactory.java
geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/DefaultAttributeType.java
geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/DefaultAttributeTypeFactory.java
geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/DefaultFeature.java
geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/DefaultFeatureBuilder.java
geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/DefaultFeatureFactory.java
geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/DefaultFeatureType.java
geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/DefaultFeatureTypeFactory.java
geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/DefaultFeatureTypeFactory2.java
geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/FeatureTypeBuilder.java
geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/FeatureTypeFactory.java
geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/MultiAttributeType.java
geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/SimpleFeature.java
geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/SimpleFeatureType.java
geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/type/ChoiceAttributeType.java
geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/type/DefaultAttributeTypeBuilder.java
geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/type/DefaultFeatureTypeBuilder.java
geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/type/FeatureAttributeType.java
geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/type/GeometricAttributeType.java
geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/type/ListAttributeType.java
geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/type/NestedAttributeType.java
geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/type/NumericAttributeType.java
geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/type/SetAttributeType.java
geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/type/TemporalAttributeType.java
geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/type/TextualAttributeType.java
geotools/trunk/gt/modules/library/main/src/test/java/org/geotools/data/DummyFeatureType.java
geotools/trunk/gt/modules/library/main/src/test/java/org/geotools/feature/AttributeTypeTest.java
geotools/trunk/gt/modules/library/main/src/test/java/org/geotools/feature/ChoiceAttrTypeTest.java
geotools/trunk/gt/modules/library/main/src/test/java/org/geotools/feature/FeatureTypeFactoryTest.java
geotools/trunk/gt/modules/library/main/src/test/java/org/geotools/feature/FeatureWrappedComplexTest.java
geotools/trunk/gt/modules/library/main/src/test/java/org/geotools/feature/FlatFeatureFactorySpiTest.java
Modified:
geotools/trunk/gt/modules/library/main/pom.xml
geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/AttributeImpl.java
geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/AttributeTypeBuilder.java
geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/simple/SimpleFeatureBuilder.java
geotools/trunk/gt/modules/library/main/src/test/java/org/geotools/feature/FeatureCollectionTest.java
geotools/trunk/gt/modules/library/main/src/test/java/org/geotools/feature/FeatureFlatTest.java
geotools/trunk/gt/modules/library/pom.xml
geotools/trunk/gt/modules/library/xml/src/main/java/org/geotools/xml/gml/ChoiceAttributeTypeImpl.java
geotools/trunk/gt/modules/library/xml/src/main/java/org/geotools/xml/gml/ChoiceGeometryTypeImpl.java
Log:
Legacy module to hold the old feature model
Deleted: geotools/trunk/gt/modules/library/api/src/main/java/org/geotools/feature/AttributeType.java
===================================================================
--- geotools/trunk/gt/modules/library/api/src/main/java/org/geotools/feature/AttributeType.java 2007-10-01 00:43:34 UTC (rev 27293)
+++ geotools/trunk/gt/modules/library/api/src/main/java/org/geotools/feature/AttributeType.java 2007-10-01 00:46:16 UTC (rev 27294)
@@ -1,211 +0,0 @@
-/*
- * GeoTools - OpenSource mapping toolkit
- * http://geotools.org
- * (C) 2002-2006, GeoTools Project Managment Committee (PMC)
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation;
- * version 2.1 of the License.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- */
-package org.geotools.feature;
-
-import org.opengis.feature.type.AttributeDescriptor;
-import org.opengis.feature.type.PropertyDescriptor;
-import org.opengis.filter.Filter;
-
-
-/**
- * <p>
- * Stores metadata about a single attribute object.
- *
- * <ol>
- * <li>
- * Name: A string that is used to reference the attribute.
- * </li>
- * <li>
- * Nillable: if nulls are allowed as this attribute.
- * </li>
- * <li>
- * Type: The expected Java class of this attribute.
- * </li>
- * </ol>
- * </p>
- *
- * <p>
- * AttributeTypes must also provide the <code>validate(Object obj)</code>
- * method, which determines whether a given object matches the constraints
- * imposed by the AttributeType. In a default attribute this will simply be
- * that it is of the correct class and non-null (or null if isNillable is
- * true). More complex AttributeTypes can impose any restrictions that they
- * like. Nested FeatureTypes are an example of this, as they need to check
- * that the Feature object matches all its constraints, not that it is just
- * of class Feature.
- * </p>
- *
- * <p>
- * Additionally, implementors may use the parse method to convert an object to
- * its preferred storage type. If an implementor does not choose to provide
- * any functionality for this method they should simple return the object
- * passed in. If parsing is attempted and not successful, then an exception
- * should be thrown. This method is primarily used by FeatureType to try to
- * convert objects to the correct storage type, such as a string of a double
- * when the AttributeType requires a Double.
- * </p>
- *
- * @author Rob Hranac, VFNY
- * @author Chris Holmes, TOPP
- * @source $URL$
- * @version $Id$
- *
- * @deprecated use {@link AttributeDescriptor}.
- */
-public interface AttributeType extends AttributeDescriptor {
- /** Represents any number of elements. Same '' in a reg-ex */
- public static int UNBOUNDED = Integer.MAX_VALUE;
-
- /* feature-exp2 redesign notes:
- * 1) removed isNested() from the api as are going to incorporating
- * more complex attribute sequences ... including sets and choices.
- * isNested() was used very little, and was never fully thought through
- * So killing it should not have too much of an effect.
- *
- * 2) Added minOccurs and maxOccurs since we are going to get into
- * multiplicity, where this matters. The isNilleable is not enough
- *
- * 3) deprecated isGeometry() as it is a convenience method that can
- * be accomplished in different ways, and it means nothing for a
- * featureType
- *
- * 4) We are planning on killing getFieldLength, as it is extremely
- * impercise, has no general meaning. We are going to replace it
- * with the concept of xml facets, hopefully we will have time to.
- *
- */
-
- /**
- * Gets the name of this attribute.
- *
- * @return Name.
- * @deprecated use {@link #getLocalName()}
- */
-
- //String getLocalName();
-
- /**
- * Returns the unqualified name of this attribute.
- * <p>
- * This method is a replacement for {@link #getName()} in order to resolve
- * a naming conflict with the geoapi feature model.
- * </p>
- * @see PropertyDescriptor#getName()
- * @since 2.4
- */
- String getLocalName();
-
- /**
- * Gets the type of this attribute.
- *
- * @return Type.
- * @deprecated use {@link #getBinding()}
- */
-
- //Class getBinding();
-
- /**
- * Gets the class/type/binding for this attribute.
- * <p>
- * This method is a replacement for {@link #getType()} in order to resolve
- * a naming conflict with the geoapi feature model.
- * </p>
- *
- * @see AttributeDescriptor#getType()
- * @since 2.4
- */
- Class getBinding();
-
- /**
- * This represents a Facet in XML schema ... for example can be used to
- * represent the max length of 20 for a string.
- *
- * @return Filter, or Filter.INCLUDE if no restriction is needed.
- */
- Filter getRestriction();
-
- /**
- * Returns whether nulls are allowed for this attribute.
- *
- * @return true if nulls are permitted, false otherwise.
- */
- boolean isNillable();
-
- /**
- * Returns the Min number of occurences ...
- *
- */
- int getMinOccurs();
-
- /**
- * Returns the Max number of occurences ...
- *
- */
- int getMaxOccurs();
-
- /**
- * Allows this AttributeType to convert an argument to its prefered storage
- * type. If no parsing is possible, returns the original value. If a parse
- * is attempted, yet fails (i.e. a poor decimal format) throw the
- * Exception. This is mostly for use internally in Features, but
- * implementors should simply follow the rules to be safe.
- *
- * @param value the object to attempt parsing of.
- *
- * @return <code>value</code> converted to the preferred storage of this
- * <code>AttributeType</code>. If no parsing was possible then
- * the same object is returned.
- *
- * @throws IllegalArgumentException if parsing is attempted and is
- * unsuccessful.
- */
- Object parse(Object value) throws IllegalArgumentException;
-
- /**
- * Whether the tested object passes the validity constraints of this
- * AttributeType. At a minimum it should be of the correct class
- * specified by {@link #getBinding()}, non-null if isNillable is
- * <tt>false</tt>, and a geometry if isGeometry is <tt>true</tt>. If The
- * object does not validate then an IllegalArgumentException reporting the
- * error in validation should be thrown.
- *
- * @param obj The object to be tested for validity.
- *
- * @throws IllegalArgumentException if the object does not validate.
- */
- void validate(Object obj) throws IllegalArgumentException;
-
- /**
- * Create a duplicate value of the passed Object. For immutable Objects, it
- * is not neccessary to create a new Object.
- *
- * @param src The Object to duplicate.
- *
- * @return Duplicate of provided object
- *
- * @throws IllegalAttributeException If the src Object is not the correct
- * type.
- */
- Object duplicate(Object src) throws IllegalAttributeException;
-
- /**
- * Create a default value for this AttributeType. If the type is nillable,
- * the Object may or may not be null.
- *
- * @return Default value, note may be null if isNillable is true
- */
- Object createDefaultValue();
-}
Deleted: geotools/trunk/gt/modules/library/api/src/main/java/org/geotools/feature/Feature.java
===================================================================
--- geotools/trunk/gt/modules/library/api/src/main/java/org/geotools/feature/Feature.java 2007-10-01 00:43:34 UTC (rev 27293)
+++ geotools/trunk/gt/modules/library/api/src/main/java/org/geotools/feature/Feature.java 2007-10-01 00:46:16 UTC (rev 27294)
@@ -1,328 +0,0 @@
-/*
- * GeoTools - OpenSource mapping toolkit
- * http://geotools.org
- * (C) 2002-2006, GeoTools Project Managment Committee (PMC)
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation;
- * version 2.1 of the License.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- */
-package org.geotools.feature;
-
-import com.vividsolutions.jts.geom.Envelope;
-import com.vividsolutions.jts.geom.Geometry;
-import org.opengis.feature.simple.SimpleFeature;
-import org.geotools.geometry.jts.ReferencedEnvelope;
-
-
-/**
- * <p>
- * Represents a feature of arbitrary complexity.
- * <p>
- * This interface answers the question: How do we store feature attributes?
- * (The answer to the more useful question, How do we access feature attribute,
- * is contained in the Expression class.
- * <p>
- * <p>
- * Warning: We are revising the Feature Model to be more complete in the
- * next round of GeoTools. If you do any data access in your classes please try
- * and make use of Expression to access your information, if you do this you will
- * not be affected by the change (beyond a few search and replace operations).
- * </p>
- * The most generic approach would be to pass all feature attributes as objects
- * and use Java variable and method references to access them. However, this is
- * also the most useless approach because it establishes no unified methods for getting
- * attribute information (since it is totally Object dependent), without
- * elaborate reflection/introspection, which is inconvenient to use. Unlike
- * its {@link FeatureType} counterpart, this interface does not attempt to
- * serve as a typing framework. Rather, multiple implementations of this
- * interface should generally be for performance reasons.
- * </p>
- *
- * <p>
- * This interface serves two important purposes. Most obviously, it gives
- * users of features a unified, consistent framework for accessing and
- * manipulating feature data. Perhaps more importantly, the
- * <code>FeatureType</code> and <code>Feature</code> interfaces also work
- * together to give implementers a framework for constraining and enforcing
- * constraints (respectively) on allowed feature types. As such, this
- * interface is as general as possible in terms of the types of objects to
- * which it provides access. Keep in mind that creating new features is
- * relatively difficult and should only be done to optimize performance for
- * highly constrained schema types. For the vast majority of schemas, the
- * generic feature implementation will work fine.
- * </p>
- *
- * <p>
- * <b>Notes for Feature Clients:</b><br>
- * Clients should always use feature accessor methods (getAttribute and
- * setAttribute) to modify the state of internal attribute objects. It is
- * possible that some feature implementations will allow object state changes
- * by clients outside of the class, but this is strongly discouraged. In
- * general, feature implementations will make defensive copies of objects
- * passed to clients and it is therefore not guaranteed that client state
- * changes that take place outside of the feature will be reflected in the
- * internal state of the feature object! <i>For this reason, clients should
- * always use the set methods to change feature attribute object states!</i>
- * </p>
- *
- * <p>
- * <b>Notes for Feature Implementers:</b><br>
- * It is the responsibility of the implementing class to ensure that the
- * <code>Feature</code> attributes stay synchronized with its FeatureType
- * definition. <i>Features should never get out of synch with their declared
- * schemas and should never alter their schemas!</i> There are four
- * conventions of which implementers of this interface must be aware in order
- * to successfully manage a <code>Feature</code>:
- * </p>
- *
- * <ol>
- * <li>
- * <b>FeatureType Reference</b><br>
- * Features must always hold a single (immutable: see
- * <code>FeatureType</code>) schema reference and this reference should not be
- * altered after a feature has been created. To ensure this, is is strongly
- * recommended that features take a valid reference to an existing immutable
- * schema in its constructor and declare that reference final.
- * </li>
- * <li>
- * <b>Default Geometry</b><br>
- * Each feature must have a default geometry, but this primary geometry may be
- * null. This means that a feature may contain no geometries, but it must
- * always have a method for accessing a geometry object (even if it is null).
- * It also means that a feature with multiple geometries must pick one as its
- * default geometry. Note that the designation of the default geometry is
- * stored as part of the <code>FeatureType</code> and is therefore immmutable.
- * </li>
- * <li>
- * <b>Attributes</b><br> All features contain zero or more attributes, which
- * can have one or more occurrences inside the feature. Attributes may be any
- * valid Java object. If attributes are instances of <code>Feature</code>,
- * they are handled specially by the <code>Feature</code> methods, in that
- * their attributes may be accessed directly by their containing feature. All
- * other object variables and methods must be accessed through the objects
- * themselves. It is up to implementers of <code>Feature</code> to make sure
- * that each attribute value conforms to its internal schema. A feature
- * should never reach a state where its attributes (or sub-attributes) do not
- * conform to their <code>FeatureType</code> definitions. There are three
- * ways to implement this. The first is to simply make features immutable;
- * however, given the ubiquity and required flexibility of features, this is
- * likely not possible. The second (and second easiest), is to make all
- * feature attributes immutable. For most cases, this is probably the best way
- * to handle this issue. The third way, is to never give out a reference that
- * would allow a client to change an attribute object's class (most obviously,
- * an array reference). Generally speaking, features should attempt to
- * minimize external object references by attempting to clone incoming
- * attributes before adding them and outgoing attributes before sending them.
- * For features with non-cloneable attributes, of course, this is not
- * possible, so this is left to the discretion of the implementor.
- * </li>
- * <li>
- * <b>Constructors</b><br> Constructors should take arguments with enough
- * information to create a valid representation of the feature. They should
- * also always include a valid schema that can be used to check the proposed
- * attributes. This is necessary to ensure that the feature is always in a
- * valid state, relative to its schema.
- * </li>
- * <li>
- * <b>hashCode() and equals(Object other)</b><br>
- * Determining equality and equivalence for Feature instances is of utmost
- * importance. This must be done in a constistent manner, as many other areas
- * of geotools will rely on these relations. See java.lang.Object for details.
- * </li>
- * </ol>
- *
- *
- * @author James Macgill, CCG
- * @author Rob Hranac, TOPP
- * @author Ian Schneider, USDA-ARS
- * @author dzwiers
- * @source $URL$
- * @version $Id$
- *
- * @see org.geotools.feature.FeatureType
- * @see org.geotools.feature.DefaultFeature
- *
- * @deprecated use {@link SimpleFeature}.
- */
-public interface Feature extends SimpleFeature {
- /**
- * Gets a reference to the schema for this feature.
- *
- * @return A reference to this feature's schema.
- */
- FeatureType getFeatureType();
-
- /**
- * Gets the unique feature ID for this feature.
- *
- * @return Unique identifier for this feature.
- */
- String getID();
-
- /**
- * Copy all the attributes of this Feature into the given array. If the
- * argument array is null, a new one will be created. Gets all attributes
- * from this feature, returned as a complex object array. This array
- * comes with no metadata, so to interpret this collection the caller
- * class should ask for the schema as well. This array may have multiple
- * entries for each AttributeType depending on the AttributeType's
- * multiplicity.
- *
- * @param attributes An array to copy attributes into. May be null.
- *
- * @return The array passed in, or a new one if null.
- */
- Object[] getAttributes(Object[] attributes);
-
- /**
- * Gets an attribute for this feature at the location specified by xPath.
- * Due to the complex nature of xpath, a List of all valid values will be
- * returned when an attribute is requested. These values can range from
- * complete Feature Collections to single primative attribute values. When
- * a particular instance of the Attribute is requested, then the Object
- * will be returned. Simply put, in the general case we are assuming the
- * existance of multiplicity, so specify which instance you want or you
- * get them all. Example of getting a list: ./road returns the
- * List of road attribute instances Example of getting an Object:
- * ./road[0] returns the first road
- *
- * @param xPath XPath representation of attribute location.
- *
- * @return A List of copies of the requested attribute, null if the
- * requested xpath is not found, or NULL_ATTRIBUTE.
- */
- Object getAttribute(String xPath);
-
- /**
- * Gets an attribute by the given zero-based index. This index is based on
- * the values within the Feature as opposed to the AttributeType
- * declaration. To get the values for the 5th attributeType, use the
- * schema to determine the xPath and class the getAttribute(xPath)
- * method.
- *
- * @param index The requested index. Must be 0 <= idx <
- * getNumberOfAttributes().
- *
- * @return A copy of the requested attribute, or NULL_ATTRIBUTE.
- *
- * @see Feature#getAttribute(String)
- */
- Object getAttribute(int index);
-
- /**
- * Sets an attribute by the given zero-based index. This index is based on
- * the values within the Feature as opposed to the AttributeType
- * declaration. To get the values for the 5th attributeType, use the
- * schema to determine the xPath and class the setAttribute(xPath,val)
- * method.
- *
- * @param position The requested index. Must be 0 <= idx <
- * getNumberOfAttributes()
- * @param val An object representing the attribute being set
- *
- * @throws IllegalAttributeException if the passed in val does not validate
- * against the AttributeType at that position.
- * @throws ArrayIndexOutOfBoundsException if an invalid position is given
- *
- * @see Feature#setAttribute(String, Object)
- */
- void setAttribute(int position, Object val);
-
- /**
- * Get the number of attributes this feature has. This is NOT simply a
- * convenience method for calling
- * getFeatureType().getNumberOfAttributes(). This is the same as calling
- * getAttributes(null).length. This represents the number of actual
- * attribute values in the feature, and may differ from the number of
- * AttributeTypes defined in the FeatureType based on the multiplicity of
- * the AttributeTypes.
- *
- * @return The total number of attributes this Feature contains.
- */
- int getNumberOfAttributes();
-
- /**
- * Sets a single attribute for this feature, passed as a complex object. If
- * the attribute does not exist or the object does not conform to the
- * internal schema, an exception is thrown. Checking this is, of course,
- * left to the feature to do internally. Well behaved features should
- * always fully check the passed attributes against thire schema before
- * adding them. NOTE: The xPath may contain instance information about
- * multiplicity, for example: ./road[3] which is the third road
- * attribute in this feature.
- *
- * @param xPath XPath representation of attribute location.
- * @param attribute Feature attribute to set.
- *
- * @throws IllegalAttributeException If the attribute is illegal for the
- * path specified.
- */
- void setAttribute(String xPath, Object attribute) throws IllegalAttributeException;
-
- /**
- * Gets the default geometry for this feature.
- *
- * <p>
- * This method will return <code>null</code> if no DefaultGeometry has been
- * defined by the schema.
- * </p>
- *
- * @return Default geometry for this feature, or <code>null</code>
- */
- Geometry getDefaultGeometry();
-
- /**
- * Sets the default geometry for this feature.
- *
- * @param geometry The geometry to set.
- *
- * @throws IllegalAttributeException If the AttributeType is not a
- * geometry, or is invalid for some other reason.
- */
- void setDefaultGeometry(Geometry geometry) throws IllegalAttributeException;
-
- /**
- * Get the total bounds of this feature which is calculated by doing a
- * union of the bounds of each geometry this feature is associated with.
- *
- * <p>
- * This method will return an empty Envelope if the feature contains no
- * geometry information.
- * </p>
- *
- * @return An Envelope containing the total bounds of this Feature.
- */
- ReferencedEnvelope getBounds();
-
- /**
- * Not straight forward, this is a "null" object to represent the value
- * null for a given attribute which is nullable.
- */
- static final class NULL implements Comparable {
- /**
- * Implementation of Comparable.
- *
- * @param o The other thing to compare to.
- *
- * @return 0 if null or this, 1 for all others.
- */
- public int compareTo(Object o) {
- if (o == null) {
- return 0;
- }
-
- if (o == this) {
- return 0;
- }
-
- return 1;
- }
- }
-}
Deleted: geotools/trunk/gt/modules/library/api/src/main/java/org/geotools/feature/FeatureAttributeType.java
===================================================================
--- geotools/trunk/gt/modules/library/api/src/main/java/org/geotools/feature/FeatureAttributeType.java 2007-10-01 00:43:34 UTC (rev 27293)
+++ geotools/trunk/gt/modules/library/api/src/main/java/org/geotools/feature/FeatureAttributeType.java 2007-10-01 00:46:16 UTC (rev 27294)
@@ -1,112 +0,0 @@
-/*
- * GeoTools - OpenSource mapping toolkit
- * http://geotools.org
- * (C) 2002-2006, GeoTools Project Managment Committee (PMC)
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation;
- * version 2.1 of the License.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- */
-package org.geotools.feature;
-
-import org.opengis.filter.Filter;
-
-
-/**
- * A FeatureType aware Feature AttributeType.
- *
- * <p>
- * While we could use a plain AttributeType to capture a Feature instance we
- * would miss out one one important aspect: the schema.
- * </p>
- *
- * <p>
- * By definition the schema of a Feature is not defined by java interface
- * alone, this interface allows access the the assocaited FeatureType.
- * </p>
- *
- * <p>
- * Suggestion: we can look at having this class extend ListFeatureType and
- * exactly specifying how delegation to the getSchema() should occur. (the
- * alternative is to make FeatureType extend ListAttributeType). Something
- * should be done as they have 90% the same API.
- * </p>
- *
- * @author Jody Garnett, Refractions Research, Inc.
- *
- * @since 2.1.M5
- * @source $URL$
- */
-public interface FeatureAttributeType extends AttributeType, PrimativeAttributeType {
- /**
- * Method should delegate responsibility to a FeatureFactory.
- *
- * @see org.geotools.feature.AttributeType#createDefaultValue()
- */
- Object createDefaultValue();
-
- /**
- * Method should return getSchema().duplicate( feature )
- *
- * <p>
- * Exampe implementation:
- * <pre><code>
- * <b>return</b> getSchema().duplicate( (Feature) getValue() );
- * </code></pre>
- * It is understood that FeatureType.duplicate
- * </p>
- *
- * @see org.geotools.feature.AttributeType#duplicate(java.lang.Object)
- */
- Object duplicate(Object src) throws IllegalAttributeException;
-
- /**
- * Method must return type Feature.class.
- *
- * <p>
- * Exampe implementation:
- * <pre><code>
- * <b>return</b> Feature.class;
- * </code></pre>
- * </p>
- *
- * @see org.geotools.feature.AttributeType#getBinding()
- */
- Class getBinding();
-
- /**
- * Retrieve the schema for this FeatureType
- *
- * @return CS_CoordinateSystem for this GeometryAttributeType
- */
- public FeatureType getSchema();
-
- /**
- * Must return <code>false</code>.
- *
- * @return DOCUMENT ME!
- *
- * @see org.geotools.feature.AttributeType#isGeometry()
- * @deprecated repalce with: <code>type instanceof
- * GeometryAttributeType</code>
- */
- boolean isGeometry();
-
- /**
- * Filter must indicate value is required to be a member of getSchema().
- *
- * <p>
- * TODO: We need a Filter code snipit describing how to enforce the
- * indicated relationship.
- * </p>
- *
- * @see org.geotools.feature.AttributeType#getRestriction()
- */
- Filter getRestriction();
-}
Deleted: geotools/trunk/gt/modules/library/api/src/main/java/org/geotools/feature/FeatureCollectionType.java
===================================================================
--- geotools/trunk/gt/modules/library/api/src/main/java/org/geotools/feature/FeatureCollectionType.java 2007-10-01 00:43:34 UTC (rev 27293)
+++ geotools/trunk/gt/modules/library/api/src/main/java/org/geotools/feature/FeatureCollectionType.java 2007-10-01 00:46:16 UTC (rev 27294)
@@ -1,34 +0,0 @@
-/*
- * GeoTools - OpenSource mapping toolkit
- * http://geotools.org
- * (C) 2002-2006, GeoTools Project Managment Committee (PMC)
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation;
- * version 2.1 of the License.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- */
-package org.geotools.feature;
-
-
-/**
- * A SimpleFeatureCollectionType indicating that the contents are stored using the
- * deprecated GeoTools FeatureType. This FeatureCollectionType indicates that *no*
- * attribtues are stored at the FeatureCollection level.
- * <p>
- * The only useful information is available via:
- * <ul>
- * <li>FeatureCollectioType.getMemberType()
- * @author Jody Garnett (Refractions Research)
- */
-public interface FeatureCollectionType extends FeatureType {
- /**
- * Explicitly documents the FeatureCollection as containing this FeatureType.
- */
- public SimpleFeatureType getMemberType();
-}
Deleted: geotools/trunk/gt/modules/library/api/src/main/java/org/geotools/feature/FeatureType.java
===================================================================
--- geotools/trunk/gt/modules/library/api/src/main/java/org/geotools/feature/FeatureType.java 2007-10-01 00:43:34 UTC (rev 27293)
+++ geotools/trunk/gt/modules/library/api/src/main/java/org/geotools/feature/FeatureType.java 2007-10-01 00:46:16 UTC (rev 27294)
@@ -1,541 +0,0 @@
-/*
- * GeoTools - OpenSource mapping toolkit
- * http://geotools.org
- * (C) 2002-2006, GeoTools Project Managment Committee (PMC)
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation;
- * version 2.1 of the License.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- */
-package org.geotools.feature;
-
-import java.net.URI;
-import org.opengis.feature.simple.SimpleFeatureType;
-
-
-/**
- * A metadata template for a Feature of arbitrary complexity.
- * <p>
- * Notes:
- * <ul>
- * <li>that this documentation should be read in conjunction with the {@link Feature}API.
- * <li>the attributes described by this FeatureType <b>and its ancestors </b> define the complete
- * schema for a Feature
- * </p>
- * <p>
- * This interface answers the question: How do we represent features within GeoTools? Of course, the
- * most general answer would be: features can be any Java object. However, this is also the least
- * useful solution because it means that users of features have essentially no way to find out about
- * the meaning of features other than using Java introspection/reflection. This is too cumbersome
- * and is insufficient for the goal of creating a simple framework for manipulating and accessing
- * generic geographic data. The opposite approach might be to define a very constrained set of
- * possible attributes (that, for example, mirrored Java primitives and OGC simple geometries) and
- * only allow features of this type.
- * </p>
- * <p>
- * This interface takes a different approach: it defines a minimal ontology for representing a
- * feature and serves as a consistent framework for defining more constrained (and, therefore, often
- * more meaningful) feature types. A <code>FeatureType</code> represents features as an object
- * that contains zero or more attribute objects, one of which will generally be a geometry, but no
- * geometry and multiple geometries are allowed, according to implementation. Note that instances of
- * implementations of this class are henceforth referred to as schemas.
- * </p>
- * <p>
- * With oneexceptions, the type of an attribute is considered to be its cannonical definition by the
- * FeatureType. For example, an attribute type might be a <code>javax.sound.midi.Sequence</code>
- * object, which contains a <code>float</code> public field called PPQ. The fact that this
- * attribute exists is not known by the <code>FeatureType</code> itself. If a caller asks this
- * <code>FeatureType</code> for all of its attributes, the <code>
- * FeatureType</code> will tell
- * the caller that it has an attribute of type <code>javax.sound.midi.Sequence</code>, but not
- * that this attribute has a sub-attribute (field) called PPQ. It is the responsibility of the
- * callers to understand the objects it is asking for and manipulate them appropriately.
- * </p>
- * <p>
- * The exceptions is for:
- * <ul>
- * <li>if the type stored in the <code>FeatureType</code> is a
- * <code>org.geotools.datasource.Feature</code> type. <br>
- * In this case, all information about sub-attributes are stored and passed to calling classes upon
- * request. The style of reference (XPath) is defined in and mediated by <code>FeatureType</code>
- * implementations.
- * </ul>
- * Question: how does one determine the schema for the attribute defined as a FeatureType? I suspect
- * that FeatureType may be a valid AttributeType? (One needs this schema information before xpath
- * can be used to query the Feature value.
- * </p>
- * <p>
- * It is the responsibility of the implementing class to ensure that the <code>FeatureType</code>
- * is always in a valid state. This means that each attribute tuple must be fully initialized and
- * valid. The minimum valid <code>FeatureType</code> is one with nulls for namespace, type, and
- * attributes; this is clearly a trivial case, since it is so constrained that it would not allow
- * for any feature construction. There are a few conventions of which implementers of this interface
- * must be aware in order to successfully manage a <code>FeatureType</code>:
- * </p>
- * <ol>
- * <li><b>Immutability </b> <br>
- * <i>FeatureTypes must be implemented as immutable objects! </i> All setting methods have been
- * removed from this interface, that functionality is now available in the mutable {@link
- * FeatureTypeFactory}</li>
- * <li><b>Default Geometries </b> <br>
- * Note that the FeatureType contains a special methods for handling geometries. The primary
- * geometry retrieval methods are in <code>Feature</code> because they may change over the life of
- * the feature, while the schema may not. In cases where there are more than one geometries it is up
- * to the implementor to determine which is the default geometry. <code>getDefaultGeometry</code>
- * may return <code>null</code> if there are no geometries in the FeatureType, but if there is one
- * or more geometry then the method must return one of them, <code>null</code> is never an
- * acceptable return value.</li>
- * <li><b>XPath </b> <br>
- * XPath is the standard used to access all attributes (flat, nested, and multiple), via a single,
- * unified string. Using XPath to access attributes has the convenient side-benefit of making them
- * appear to be non-nested and non-multiple to callers with no awareness of XPath. This greatly
- * simplifies accessing and manipulating data. However, it does put extra burden on the implementers
- * of <code>FeatureType</code> to understand and correctly implement XPath pointers. Note that the
- * <code>Feature</code> object does not understand XPath at all and relies on implementors of this
- * interface to interpret XPath references. Fortunately, XPath is quite simple and has a clearly
- * written <a href="http://www.w3.org/TR/xpath">specification </a>.</li>
- * <li><b>Feature Creation </b> <br>
- * FeatureType also must provide methods for the creation of Features, as specified in
- * FeatureFactory. The creating FeatureType should check to see if the passed in objects validate
- * against its AttributeTypes, and if it does should return a new Feature.</li>
- * </ol>
- * <h2>Redesign Notes (feature-exp2)</h2>
- * The main design goal of this is to have FeatureType extend AttributeType. This allows us to
- * nesting of features much more nicely. We already are going in this direction, with the
- * FeatureAttributeType buried in DefaultAttribute. This is just making it explicit, so it works
- * with the complex objects GML can return a lot more sensible. So much of the work in this class is
- * figuring out what concepts are the same. Some stuff may need to be rethought a bit, as there are
- * a few subtle assumptions that we are working with flat files. We will revisit this when we
- * implement choice and multiplicity.
- * <ul>
- * <li>got rid of deprecated getNamespace() method that returned a string, replaced it with a URI
- * return. This has been deprecated for a bit, and was done out of a desire to keep backwards
- * compatibility with 2.0, but that mission failed, so we're just moving on. This change will break
- * a few things, but is a good one, people just need to update their client code a bit.
- * <li>Deprecated getTypeName() to be getName(). They are the same thing, would be nice to get rid
- * of getTypeName, but it's used super extensively. Though perhaps we could consider keeping it as a
- * convenience, a bit more explicit, but it seems like overkill.
- * <li>Updated comments of the AttributeType operations that are inhierited to say what they mean
- * in the context of a FeatureType.
- * </ul>
- * <h2>Redesign Notes (factory-hints)</h2>
- * The factory-hints design is finally coming through on the promiss of the great geotools factory
- * design. This design is actualy placing the factory system under application (rather than
- * 'default') control, as such it is really showing every last place where we did not follow our
- * architecture.
- * <ul>
- * Use Cases:
- * <li>Custom Feature: <br>
- * Application spedcifies the use of a custom feature implementation. This is used so an application
- * interface is supported by each and every feature created.
- * <li>optiomized coordinate storage <br>
- * LiteRenderer2 wants Shape2d specific CoordinateSequenceFactory used for all Geometry creation.
- * The point is to allow only the xy information to be retrieved, and in a format suitable for rapid
- * reprojection and coversion to a Java2D Shape. Any OpenGL (or Java3D) based renderer would also
- * run into this need.
- * </ul>
- * The second use case is interesting in that LiteRenderer2 will be using the Datastore at the same
- * time as other threads that want the normal coordinate sequence. So this is a per Query hint.
- * </ul>
- * <p>
- * Consequence: Since FeatureType is immutable, and CoordianteSequence is specified by the
- * GeometryFactory of the DefaultGeometryAttribute this implys that we have a per Query SchemaType.
- * </p>
- * <p>
- * It strikes me that this is a bad separation of concerns the "schema" should be exactly the same,
- * it is just the GeometryFactory that controls construction that is in the wrong spot. It should be
- * a hint, not attached to GeomtryAttributeType.
- * </p>
- *
- * @author Rob Hranac, VFNY
- * @author Chris Holmes, TOPP
- * @author David Zwiers, Refractions
- * @author Jody Garnett, Refractions
- * @source $URL$
- * @version $Id$
- * @see org.geotools.feature.Feature
- * @see org.geotools.feature.FeatureTypeFactory
- * @see org.geotools.feature.type.NestedAttributeType
- * @see org.geotools.feature.DefaultFeatureType
- *
- * @deprecated use {@link SimpleFeatureType}.
- */
-public interface FeatureType extends SimpleFeatureType {
- //
- // XML Mapping Information
- //
- // Used for mapping Feature information to Geographical Markup Language,
- //
- /**
- * Gets the global schema namespace.
- * <p>
- * This is often used to record the schema prefix (not the URI) required when writing out this
- * Feature using GML. The supporting application will need to be able to start the GMLWriter off
- * with the correct URI information so everything makes sense.
- * </p>
- * <p>
- * The Registry interface provided by the data module provides an example of how to store
- * associate FeatureType and namespace information. Please note that you may not have duplicate
- * typeNames in the same Namespace.
- * </p>
- *
- * @return Namespace of schema
- */
- URI getNamespace();
-
- /**
- * Gets the type name for this schema.
- * <p>
- * In GML this must be the element name of the Feature.
- * </p>
- *
- * @return The name of this feature type.
- */
- String getTypeName();
-
- /**
- * Test to determine whether this FeatureType is descended from the given FeatureType. Think of
- * this relationship likes the "extends" relationship in java.
- *
- * @param nsURI The namespace URI to use.
- * @param typeName The typeName.
- * @return true if descendant, false otherwise.
- */
- boolean isDescendedFrom(URI nsURI, String typeName);
-
- /**
- * A convenience method for calling <br>
- * <code><pre>
- * FeatureType f1;
- * FeatureType f2;
- * f1.isDescendedFrom(f2.getNamespace(), f2.getName());
- * </pre></code>
- * <p>
- * Question: this method duplicates the information provided by getAncestors().
- * </p>
- *
- * @param type The type to compare to.
- * @return true if descendant, false otherwise.
- */
- boolean isDescendedFrom(FeatureType type);
-
- /**
- * Is this FeatureType an abstract type?
- * <p>
- * When true is returned instances of this Feature cannot be created, instead a child
- * FeatureType must use this FeatureType as its ancestor.
- * </p>
- *
- * @return true if abstract, false otherwise.
- */
- boolean isAbstract();
-
- /**
- * Obtain an array of this FeatureType's direct ancestors.
- * Implementors should return a non-null array (may be of length 0).
- * <p>
- * <ul>
- * <li>length 0 - a root FeatureType
- * <li>length 1 - singe inhieratance
- * <li>length 1+ - multiple inheiratance, order is not significant
- * </ul>
- * </p>
- * GetAncestors() indicates *just* the direct parents of this FeatureType.
- * It capures the inheirtance relationship from the OGC overview document.
- * </p>
- * <p>
- * Example Code:<pre><code>
- * public FeatureType getAncestors()}
- * return new FeatureType[]{ getSuper(), };
- * }
- * </code></pre>
- * </p>
- *
- * @return An array of ancestors.
- */
- FeatureType[] getAncestors();
-
- /**
- * Return the direct supertype of this FeatureType.
- * <p>
- * This is a conviance method for FeatureType where only single
- * inheirtance is supported (as is the case with GML).
- * </p>
- * <p>
- * This method will return null for a root FeatureType.
- * </p>
- * @return Get the super type, or null for root.
- */
-
- //FeatureType getSuper();
-
- /**
- * Gets the default geometry AttributeType.
- * <p>
- * If the FeatureType has more one geometry it is up to the implementor to determine which
- * geometry is the default. If working with multiple geometries it is best to get the
- * attributeTypes and iterate through them, checking for instances of GeometryAttribtueType.
- * </p>
- * <p>
- * This should just be used a convenience method when it is known that the features do not have
- * multiple geometries.
- * </p>
- *
- * @return The attribute type of the default geometry, which will contain the position.
- * @deprecated use {@link #getPrimaryGeometry()}.
- */
-
- //GeometryAttributeType getPrimaryGeometry();
-
- /**
- * Gets the primary or default geometry AttributeType.
- * <p>
- * If the FeatureType has more one geometry it is up to the implementor to determine which
- * geometry is the default. If working with multiple geometries it is best to get the
- * attributeTypes and iterate through them, checking for instances of GeometryAttribtueType.
- * </p>
- * <p>
- * This should just be used a convenience method when it is known that the features do not have
- * multiple geometries.
- * </p>
- * <p>
- * This method is a replacement for {@link #getDefaultGeometry()} in order
- * to resolve a naming conflict with the geoapi feature model.
- * </p>
- *
- * @return The attribute type of the default geometry, which will contain the position.
- * @since 2.4
- */
- GeometryAttributeType getDefaultGeometry();
-
- /**
- * The number of attribues defined by this schema.
- * <p>
- * This method to allows access to the complete schema as defined by this
- * FeatureType and its ancestors.
- * </p>
- * <p>
- * <ul>
- * Notes:
- * <li>
- * <li>for FeatureType with no super type this count value is the the
- * same as getAttributeTypes().length.
- * </p>
- *
- * @return number of distinct attributeTypes available, taking ancestors and taking overrides
- * into account.
- */
- int getAttributeCount();
-
- /**
- * Gets the attributeType at this xPath, if the specified attributeType does
- * not exist then <code>null</code> is returned.
- * <p>
- * Question: it is unclear how this interacts with the complete schema defined by this
- * FeatureType and its ancestors (in which a given xpath may refer to several AttributeTypes as
- * restrictions are applied.
- * </p>
- * <p>
- * Perhaps this method should be restricted to a FlatFeatureType? Or should have the option of
- * returning an array of matching AttributeType in order of inheiritence?
- * </p>
- *
- * @param xPath XPath pointer to attribute type.
- * @return AttributeType, or null if unavaialble
- */
- AttributeType getAttributeType(String xPath);
-
- /**
- * Find the position of a given AttributeType.
- * <p>
- * Match is based on attribute type name, the resulting index
- * may be used with getAttributeType( index ).
- * </p>
- * @param type The type to search for.
- * @return -1 if not found, a zero-based index if found.
- */
- int find(AttributeType type);
-
- /**
- * Find the position of an AttributeType which matches the given String.
- * <p>
- * This index may be used with getAttributeType( index ), the search space is the entire schema
- * defined by this FeatureType and its ancestors.
- * </p>
- *
- * @param attName the name to look for
- * @return -1 if not found, zero-based index otherwise
- */
- int find(String attName);
-
- /**
- * Gets the schema attributeType at the specified index.
- * <p>
- * The index is specified with respect to the entire Schema (as defined by this FeatureType and
- * it's ancestors).
- * <p>
- * <ul>
- * The index value should not be used with either:
- * <li>FeatureType.getAttributeTypes()[index] - as it defines only attributes contributed by
- * this FeatureType
- * <li>Feature.getAttribute( index ) - as attributes order may or may not be in sequence
- * </ul>
- * </p>
- *
- * @param position a integer index into the complete schema represented by
- * this FeatureType and its ancestors
- *
- * @return the attribute type at the specified position
- */
- AttributeType getAttributeType(int position);
-
- /**
- * AttributeTypes for this FeatureType, all attributes defined by this FeatureType
- * and its super types define schema for feature instances.
- * <p>
- * The provided array of AttributeTypes should be considered as adding to (or overriding) the
- * the AttribtueTypes defined by this FeatureTypes ancestors.
- * </p>
- * <p>
- * Note Well: Client code should not consider the index provided by the find( attName ) method
- * as a valid index into the returned array.
- * </p>
- *
- * @return Array of AttributeType describing this schema, array may be length 0, but should
- * not be null
- */
- AttributeType[] getAttributeTypes();
-
- //
- // Depreicated AttributeType handling code
- //
- // This is origional Geotools 2.0 api that is depricated and will
- // be removed as part of Geotools 2.2.
- //
- /**
- * This is only used twice in the whole geotools code base, and one of those is for a test, so
- * we're removing it from the interface. If getAttributeType does not have the AttributeType it
- * will just return null. Gets the number of occurrences of this attribute.
- * <p>
- * Question: the comment says we are removing this, but it is not depricated? And how the heck
- * can the number of occurances out of a boolean.
- * </p>
- *
- * @deprecated It seems this method is ill concieved, use getAttributeType( xpath ) != null as a
- * replacement
- * @param xPath XPath pointer to attribute type.
- * @return Number of occurrences.
- */
- boolean hasAttributeType(String xPath);
-
- //
- // This is code that was available in Geotools 2.0 as part of the
- // FeatureFactory API, In geotools 2.1 we are providing a clear
- // separation between schema information and construction.
- //
- /**
- * Create a duplicate of the provided feature, must delegate to an appropriate FeatureFactory
- * create method.
- * <p>
- * The implementation is assumed to make use of AttributeType duplicate as required for a deep
- * copy.
- * </p>
- *
- * //@deprecated This method will be removed in 2.2, please use FeatureFactory obtained from FactoryFinder
- * @param feature
- * @return a deep copy of feature
- * @throws IllegalAttributeException
- */
- Feature duplicate(Feature feature) throws IllegalAttributeException;
-
- /**
- * Creates a new feature, with a generated unique featureID.
- * <p>
- * Generating a FeatureID is less than ideal, as a FeatureID should be something
- * special about the "real world object" being modeled as a feature.
- * <p>
- * As an example: the "Effiel Tower" is a great feature id (there is only one) and we can
- * use that Feature ID in serveral systems:
- * <ul>
- * <li>In a tour guide FeatureTypes one which records (NAME, LOCATION, COST); and
- * <li>In a historical reference (NAME, LOCATION, HIEGHT, DATE, HISTORY)
- * </ul>
- * <p>
- * Explicitly a FeatureID should be persistant over time, and between systems.
- * <p>
- * The FeatureIDs "generated" by this method are generally created by a datasource.
- * This method is more for testing that doesn't need featureID.
- * </p>
- * <p>
- * Warning: This class does not follow the geotools guidelines of sepearting out
- * Interface from Factory, in geotools 2.3 there will be a formal FeatureFactory
- * allowing you to provide application specific FeatureImplementations as an orthogonal
- * concern to definition of type.
- * </p>
- *
- * @param attributes the array of attribute values
- * @return The created feature
- * @throws IllegalAttributeException if the FeatureType does not validate the attributes.
- */
- Feature create(Object[] attributes) throws IllegalAttributeException;
-
- /**
- * Scheduled for removal in Geotools 2.2, please use FeatureFactory.
- * <p>
- * Creates a new feature, with the indicated featureID.
- * </p>
- *
- * @param attributes the array of attribute values.
- * @param featureID the feature ID.
- * @return the created feature.
- * @throws IllegalAttributeException if the FeatureType does not validate the attributes.
- */
- Feature create(Object[] attributes, String featureID)
- throws IllegalAttributeException;
-
- /**
- * FeatureType check based on namespace, typeName, attributes and ancestors.
- * <p>
- * Conceptually FeatureType equality is supped to indicate an exact match based AttributeType
- * and Ancestors. The geotools models includes additional information of namespace
- * and typename.
- * </p>
- * <p>
- * As far as the geotools data model is concerned any FeatureType implementation should be able
- * to be subsituted for another. (An actually application may provided an implementation that
- * provdes tracking of metadata such as creation history, or support for additional interfaces).
- * </p>
- * <p>
- * Required implementation:<pre><code>
- * </code></pre>
- * A sample implementation is provided in FeatureTypes.equals( FeatureType, FeatureType ).
- * </p>
- * <p>
- * Questions:
- * <br>Q: You may wonder why namespace and typeName are not enought?
- * <br>A: Geotools often returns a "limitied" schema in response to a query where only a subset
- * of the attributes are requested.
- * <br>Q: Doesn't that still indicate the same schema?
- * <br>A: Yes it kind of should, a GML application (such as GeoServer) has to actually follow the
- * application schema and include attributes required by the schema (but not request by the query).
- * This library is more lax in its treatment, and expects you to uses isDecendedFrom as required.
- * </p>
- */
- public boolean equals(Object arg0);
-
- /**
- * Hascode based on namespace, typeName, attributes and ancestors.
- * <p>
- * Hascode is always a matched set with an equals implementation, please see the javadocs
- * for equals for a detailed discussion.
- * </p>
- * @see java.lang.Object#hashCode()
- */
- public int hashCode();
-}
Deleted: geotools/trunk/gt/modules/library/api/src/main/java/org/geotools/feature/GeometryAttributeType.java
===================================================================
--- geotools/trunk/gt/modules/library/api/src/main/java/org/geotools/feature/GeometryAttributeType.java 2007-10-01 00:43:34 UTC (rev 27293)
+++ geotools/trunk/gt/modules/library/api/src/main/java/org/geotools/feature/GeometryAttributeType.java 2007-10-01 00:46:16 UTC (rev 27294)
@@ -1,106 +0,0 @@
-/*
- * GeoTools - OpenSource mapping toolkit
- * http://geotools.org
- * (C) 2002-2006, GeoTools Project Managment Committee (PMC)
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation;
- * version 2.1 of the License.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- */
-package org.geotools.feature;
-
-import com.vividsolutions.jts.geom.GeometryFactory;
-
-//import org.geotools.cs.CoordinateSystem;
-import org.opengis.feature.type.GeometryDescriptor;
-import org.opengis.filter.Filter;
-import org.opengis.referencing.crs.CoordinateReferenceSystem;
-
-
-/**
- * A CoordinateSystem aware Geometry AttributeType.
- * <p>
- * This class is the bridge between our FeatureType/AttributeType
- * classes and the CoordianteSystem.
- * </p>
- * <p>
- * This also allows access to the GeometryFactory used by this
- * GeometryAttributeType parse( Object ) method.
- * </p>
- * <p>
- * With JTS14 you can use GeometryFactory to to provide your own
- * CoordianteSequence representation. CoordinateSystem is given the
- * responsiblity of providing this class for the GeometryAttributeType as
- * only it knows the CoordianteSequence class and PercisionModel mosted
- * suitable. It also may know an SRID number suitable for the
- * GeometryFactory to use when constructing new Geometry objects.
- * </p>
- * It is recomended that the CoordinateSystem GeometryFactory also
- * supply the CoordinateSystem as the value for Geometry.getUserData().
- * </p>
- *
- * @author Jody Garnett, Refractions Research, Inc.
- * @source $URL$
- */
-public interface GeometryAttributeType extends AttributeType, PrimativeAttributeType,
- GeometryDescriptor {
- /**
- * Type must be an sub type of Geometry.class.
- * <p>
- * If this was java I would say Class<X extends Geometry>.
- * Warning this will need revisiting for Geotools 2.2 when
- * GeoAPI Geometry enters use.
- * </p>
- * @see org.geotools.feature.AttributeType#getBinding()
- */
- Class getBinding();
-
- /**
- * Restriction is assumed to be in agreement with Geometry class indicated.
- *
- * @see org.geotools.feature.AttributeType#getRestriction()
- */
- Filter getRestriction();
-
- /**
- * Retrieve the CS_CoordinateSystem used by this GeometryAttributeType.
- * <p>
- * OUT OF DATE: The class CoordinateSystem holds a GeometryFactory
- * that is used for creating new content. By extension this includes the SRID,
- * PercisionModel and CoordinateSequenceFactory information.
- * </p>
- *
- * @return The coordinate reference system for this GeometryAttributeType
- */
- public CoordinateReferenceSystem getCoordinateSystem();
-
- /**
- * The Geometryfactory used for creating new content.
- * <p>
- * Replace with the following code:<pre><code>
- * Map hints = new HashMap();
- * hints.put( CoordinateReferneceSystem.class, type.getCoordinateSystem() );
- * GeometryFactory gf = FactoryFinder.getGeometryFactory( Map hints );
- *
- * // You can now use gf create methods
- * </code></pre>
- *
- * @return GeometryFactory used for new Content
- * @deprecated Please use GeometrFactory associated with your FeatureFactory
- * using the hinting system.
- */
- public GeometryFactory getGeometryFactory();
-
- /**
- * Must return <code>true</code>
- * @deprecated replace with type instnaceof GeometryAttribtueType
- * @see org.geotools.feature.AttributeType#isGeometry()
- */
- boolean isGeometry();
-}
Deleted: geotools/trunk/gt/modules/library/api/src/main/java/org/geotools/feature/PrimativeAttributeType.java
===================================================================
--- geotools/trunk/gt/modules/library/api/src/main/java/org/geotools/feature/PrimativeAttributeType.java 2007-10-01 00:43:34 UTC (rev 27293)
+++ geotools/trunk/gt/modules/library/api/src/main/java/org/geotools/feature/PrimativeAttributeType.java 2007-10-01 00:46:16 UTC (rev 27294)
@@ -1,51 +0,0 @@
-/*
- * GeoTools - OpenSource mapping toolkit
- * http://geotools.org
- * (C) 2003-2006, GeoTools Project Managment Committee (PMC)
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation;
- * version 2.1 of the License.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- */
-package org.geotools.feature;
-
-import org.opengis.filter.Filter;
-
-
-/**
- * Adds the ability to have restrictions on a particular data primitive
- * in a declarative manner.
- *
- * Standard expectations include internal validation using the specified
- * restrictions, and that the restrictions are immutable.
- *
- * @author dzwiers
- * @source $URL$
- *
- * @deprecated Will be removed in geotools 2.6
- */
-public interface PrimativeAttributeType extends AttributeType {
- /**
- * This provides access to the immutable restriction for this attribute
- * type. This restriction should be applied when real data hits instances
- * of this class. This mapps to the idea of a Facet in xml schema, or
- * restrictions in a database.
- *
- * Examples may include Length <= 20 (VARCHAR 20)
- *
- * The Default value is Filter.EXCLUDE
- *
- * @return the restriction for applied to this attribute type, or
- * Filter.EXCLUDE. Mat not be null.
- *
- * @see Filter
- * @see Filter#ALL
- */
- Filter getRestriction();
-}
Added: geotools/trunk/gt/modules/library/legacy/pom.xml
===================================================================
--- geotools/trunk/gt/modules/library/legacy/pom.xml 2007-10-01 00:43:34 UTC (rev 27293)
+++ geotools/trunk/gt/modules/library/legacy/pom.xml 2007-10-01 00:46:16 UTC (rev 27294)
@@ -0,0 +1,103 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- =======================================================================
+ Maven Project Configuration File
+
+ The Geotools Project
+ http://www.geotools.org/
+
+ Version: $Id: pom.xml 27277 2007-09-30 22:16:11Z jgarnett $
+ ======================================================================= -->
+ <project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
+ http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.geotools</groupId>
+ <artifactId>gt2-library</artifactId>
+ <version>2.5-SNAPSHOT</version>
+ </parent>
+
+
+ <!-- =========================================================== -->
+ <!-- Module Description -->
+ <!-- =========================================================== -->
+ <groupId>org.geotools</groupId>
+ <artifactId>gt2-legacy</artifactId>
+ <packaging>jar</packaging>
+ <name>Legacy API and implementation</name>
+ <url>http://maven.geotools.fr/reports/modules/library/api/</url>
+
+ <scm>
+ <connection>
+ scm:svn:http://svn.geotools.org/geotools/trunk/gt/modules/library/legacy/
+ </connection>
+ <url>http://svn.geotools.org/geotools/trunk/gt/modules/library/legacy/</url>
+ </scm>
+
+ <description>
+ The legacy module contains the old geotools feature module interfaces
+ and implementations
+ </description>
+
+ <licenses>
+ <license>
+ <name>Lesser General Public License (LGPL)</name>
+ <url>http://www.gnu.org/copyleft/lesser.txt</url>
+ <distribution>repo</distribution>
+ </license>
+ </licenses>
+
+
+ <!-- =========================================================== -->
+ <!-- Developers and Contributors -->
+ <!-- =========================================================== -->
+ <developers>
+ <developer>
+ <name>Jody Garnett</name>
+ <id>jive</id>
+ <email>jgarnett@...>
+ <organization>Refractions Research, Inc.</organization>
+ <roles>
+ <role>Java Developer</role>
+ <role>Documentation</role>
+ <role>Module Maintainer</role>
+ </roles>
+ </developer>
+ </developers>
+
+
+ <!-- =========================================================== -->
+ <!-- Dependency Management -->
+ <!-- =========================================================== -->
+ <dependencies>
+ <dependency>
+ <groupId>com.vividsolutions</groupId>
+ <artifactId>jts</artifactId>
+ <!-- The version number is specified in the parent POM. -->
+ </dependency>
+ <dependency>
+ <groupId>org.geotools</groupId>
+ <artifactId>gt2-main</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.geotools</groupId>
+ <artifactId>gt2-main</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.geotools</groupId>
+ <artifactId>gt2-main</artifactId>
+ <version>${project.version}</version>
+ <classifier>tests</classifier>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.geotools</groupId>
+ <artifactId>gt2-referencing</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ </dependencies>
+</project>
Copied: geotools/trunk/gt/modules/library/legacy/src/main/java/org/geotools/feature/AttributeType.java (from rev 27279, geotools/trunk/gt/modules/library/api/src/main/java/org/geotools/feature/AttributeType.java)
Copied: geotools/trunk/gt/modules/library/legacy/src/main/java/org/geotools/feature/AttributeTypeFactory.java (from rev 27279, geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/AttributeTypeFactory.java)
===================================================================
--- geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/AttributeTypeFactory.java 2007-09-30 22:30:23 UTC (rev 27279)
+++ geotools/trunk/gt/modules/library/legacy/src/main/java/org/geotools/feature/AttributeTypeFactory.java 2007-10-01 00:46:16 UTC (rev 27294)
@@ -0,0 +1,283 @@
+/*
+ * GeoTools - OpenSource mapping toolkit
+ * http://geotools.org
+ * (C) 2002-2006, GeoTools Project Managment Committee (PMC)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ */
+package org.geotools.feature;
+
+import java.util.Collections;
+import java.util.Map;
+
+import org.geotools.factory.Factory;
+import org.opengis.filter.Filter;
+
+
+/**
+ * Abstract class for AttributeType factories. Extending classes need only
+ * implement createAttributeType
+ *
+ * @author Ian Schneider, USDA-ARS
+ * @source $URL$
+ * @version $Id$
+ */
+public abstract class AttributeTypeFactory implements Factory {
+
+ /**
+ * Returns the default attribute factory for the system - constucting a new
+ * one if this is first time the method has been called.
+ *
+ * @return the default instance of AttributeTypeFactory.
+ */
+ public static AttributeTypeFactory defaultInstance() {
+ // depend on CommonFactoryFinder to keep singleton cached
+ //
+ return new DefaultAttributeTypeFactory();
+ }
+
+ /**
+ * Returns a new instance of the current AttributeTypeFactory.
+ * <p>
+ * If no implementations are found then DefaultAttributeTypeFactory is returned.
+ * </p>
+ * @return A new instance of an AttributeTypeFactory.
+ * @deprecated Please use CommonFactoryFinder
+ */
+ public static AttributeTypeFactory newInstance() {
+ return new DefaultAttributeTypeFactory(); // only need new instance if factory stateful?
+ }
+
+ /**
+ * Creates a new AttributeType with the given name, class and nillable
+ * values.
+ *
+ * @param name The name of the AttributeType to be created.
+ * @param clazz The class that objects will validate against.
+ * @param isNillable If nulls are allowed (will force min=0)
+ *
+ * @return A new AttributeType of name, clazz and isNillable.
+ */
+ public static AttributeType newAttributeType(String name, Class clazz,
+ boolean isNillable,int fieldLength,Object defaultValue) {
+ return defaultInstance().createAttributeType(name, clazz, isNillable,fieldLength, defaultValue);
+ }
+ /**
+ * Creates a new AttributeType with the addition of metadata like CRS.
+ * <p>
+ * Currently MetaData is used to supply the CoordinateSequence
+ * when making a GeometryAttributeType.
+ * </p>
+ * @param name name of the attribute type to be created
+ * @param clazz Class that objects will validate against
+ * @param isNillable If nulls are allowed (will force min=0)
+ * @param fieldLength A common restriction (this will produce a Filter)
+ * @param defaultValue Initial valid value for new Feature
+ * @param metaData Additional information (example a CoordinateReferenceSystem for a Geometry)
+ *
+ * @return Created AttributeType
+ */
+ public static AttributeType newAttributeType(String name, Class clazz,
+ boolean isNillable,int fieldLength,Object defaultValue, Object metaData) {
+ return defaultInstance().createAttributeType(name, clazz, isNillable,fieldLength, defaultValue, metaData);
+ }
+ /**
+ * Creates a new AttributeType with the addition of metadata like CRS.
+ *
+ * @param name name of the attribute type to be created
+ * @param clazz Class that objects will validate against
+ * @param isNillable If nulls are allowed (will force min=0)
+ * @param restriction Filter restricting valid content
+ * @param defaultValue Initial valid value for new Feature
+ * @param metaData Additional information (example a CoordinateReferenceSystem for a Geometry)
+ *
+ * @return Created AttributeType
+ */
+ public static AttributeType newAttributeType(String name, Class clazz,
+ boolean isNillable, Filter restriction,Object defaultValue, Object metaData) {
+ return defaultInstance().createAttributeType(name, clazz, isNillable, restriction, defaultValue, metaData);
+ }
+
+ /**
+ * Creates a new AttributeType.
+ *
+ * @param name name of the attribute type to be created
+ * @param clazz Class that objects will validate against
+ * @param isNillable If nulls are allowed (will force min=0)
+ * @param restriction
+ * @param defaultValue
+ * @param metaData metaData Additional information (example a CoordinateReferenceSystem for a Geometry)
+ * @param min minimum number of occurances for an array class
+ * @param max maximum number of occurances for an array class
+ * @return Created AttributeType
+ */
+ public static AttributeType newAttributeType(String name, Class clazz,
+ boolean isNillable, Filter restriction,Object defaultValue, Object metaData, int min, int max ) {
+ return defaultInstance().createAttributeType(name, clazz, isNillable, restriction, defaultValue, metaData, min, max);
+ }
+ /**
+ * Creates a new AttributeType with the given name, class and nillable
+ * values.
+ *
+ * @param name The name of the AttributeType to be created.
+ * @param clazz The class that objects will validate against.
+ * @param isNillable If nulls are allowed (will force min=0)
+ *
+ * @return A new AttributeType of name, clazz and isNillable.
+ */
+ public static AttributeType newAttributeType(String name, Class clazz,
+ boolean isNillable,int fieldLength) {
+ return defaultInstance().createAttributeType(name, clazz, isNillable,fieldLength);
+ }
+
+ /**
+ * Creates a new AttributeType with the given name, class and nillable
+ * values.
+ *
+ * @param name The name of the AttributeType to be created.
+ * @param clazz The class that objects will validate against.
+ * @param isNillable If nulls are allowed (will force min=0)
+ *
+ * @return A new AttributeType of name, clazz and isNillable.
+ */
+ public static AttributeType newAttributeType(String name, Class clazz,
+ boolean isNillable) {
+ return defaultInstance().createAttributeType(name, clazz, isNillable,Integer.MAX_VALUE);
+ }
+
+ /**
+ * Convenience method to just specify name and class. Nulls are allowed as
+ * attributes by default (isNillable = <code>true</code>).
+ *
+ * @param name The name of the AttributeType to be created.
+ * @param clazz The class that objects will validate against.
+ *
+ * @return A new AttributeType of name and clazz.
+ */
+ public static AttributeType newAttributeType(String name, Class clazz) {
+ return newAttributeType(name, clazz, true);
+ }
+
+ /**
+ * Constucts a new AttributeType that accepts Features (specified by a
+ * FeatureType)
+ *
+ * @param name The name of the AttributeType to be created.
+ * @param type the FeatureType that features will validate agist
+ * @param isNillable If nulls are allowed (will force min=0)
+ *
+ * @return A new AttributeType of name, type, and isNillable.
+ */
+ public static AttributeType newAttributeType(String name, FeatureType type,
+ boolean isNillable) {
+ return defaultInstance().createAttributeType(name, type, isNillable);
+ }
+
+ /**
+ * Constucts a new AttributeType that accepts Feature (specified by a
+ * FeatureType). Nulls are allowed as attributes by default (isNillable =
+ * <code>true</code>).
+ *
+ * @param name The name of the AttributeType to be created.
+ * @param type the FeatureType that features will validate agist
+ *
+ * @return A new AttributeType of name and type.
+ */
+ public static AttributeType newAttributeType(String name, FeatureType type) {
+ return newAttributeType(name, type, true);
+ }
+
+ /**
+ * Create an AttributeType with the given name, Class, nillability,
+ * fieldLength, and provided defaultValue.
+ *
+ * @param name The name of the AttributeType to be created.
+ * @param clazz The class that objects will validate against.
+ * @param isNillable if nulls are allowed in the new type.
+ *
+ * @return the new AttributeType
+ * @throws IllegalArgumentException If the field is not nillable, yet
+ */
+ protected abstract AttributeType createAttributeType(String name,
+ Class clazz, boolean isNillable, int fieldLength, Object defaultValue);
+
+ /**
+ * Create an AttributeType with the given name, Class, nillability,
+ * fieldLength, and provided defaultValue.
+ *
+ * @param name The name of the AttributeType to be created.
+ * @param clazz The class that objects will validate against.
+ * @param isNillable if nulls are allowed in the new type.
+ * @param restriction Used to limit the valid values
+ * @return the new AttributeType
+ * @throws IllegalArgumentException If the field is not nillable, yet
+ */
+ protected abstract AttributeType createAttributeType(String name,
+ Class clazz, boolean isNillable, Filter restriction, Object defaultValue, Object metadata);
+
+ /**
+ * Create an AttributeType with the given name, Class, nillability,
+ * fieldLength, and provided defaultValue.
+ *
+ * @param name The name of the AttributeType to be created.
+ * @param clazz The class that objects will validate against.
+ * @param isNillable if nulls are allowed in the new type.
+ * @param restriction Used to limit the valid values
+ * @param min the minimum number of occurences of the attribute
+ * @param max the maximum number of occurences of the attribute
+ * @return the new AttributeType
+ * @throws IllegalArgumentException If the field is not nillable, yet
+ */
+ protected abstract AttributeType createAttributeType(
+ String name, Class type, boolean isNillable, Filter restriction, Object defaultValue,
+ Object metaData, int min, int max
+ );
+
+ /**
+ * Create an AttributeType with the given name, Class, nillability, and
+ * fieldLength, defering the defaultValue to the type of Attribute.
+ */
+ protected abstract AttributeType createAttributeType(String name,
+ Class clazz, boolean isNillable, int fieldLength);
+
+ /**
+ * Create a Feature AttributeType which holds the a Feature instance which
+ * is of the given FeatureType or null if any arbitrary Feature can be held.
+ *
+ * @param name The name of the AttributeType to be created.
+ * @param type The FeatureType that Features will validate against.
+ * @param isNillable if nulls are allowed in the new type.
+ *
+ * @return the new AttributeType
+ */
+ protected abstract AttributeType createAttributeType(String name,
+ FeatureType type, boolean isNillable);
+
+ /**
+ * Create a Feature AttributeType which holds the a Feature instance which
+ * is of the given FeatureType or null if any arbitrary Feature can be held.
+ *
+ * @param name The name of the AttributeType to be created.
+ * @param type The FeatureType that Features will validate against.
+ * @param isNillable if nulls are allowed in the new type.
+ * @param defaultValue default value, may be null if isNilable is true
+ * @param metaData metadata for attribute type (such as CoordianteReferenceSystem)
+ * @return the new AttributeType
+ */
+ protected abstract AttributeType createAttributeType( String name, Class type, boolean isNillable, int fieldLength, Object defaultValue, Object metaData );
+
+ /**
+ * Returns the implementation hints. The default implementation returns en empty map.
+ */
+ public Map getImplementationHints() {
+ return Collections.EMPTY_MAP;
+ }
+}
Copied: geotools/trunk/gt/modules/library/legacy/src/main/java/org/geotools/feature/DefaultAttributeType.java (from rev 27279, geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/DefaultAttributeType.java)
Copied: geotools/trunk/gt/modules/library/legacy/src/main/java/org/geotools/feature/DefaultAttributeTypeFactory.java (from rev 27279, geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/DefaultAttributeTypeFactory.java)
Copied: geotools/trunk/gt/modules/library/legacy/src/main/java/org/geotools/feature/DefaultFeature.java (from rev 27279, geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/DefaultFeature.java)
Copied: geotools/trunk/gt/modules/library/legacy/src/main/java/org/geotools/feature/DefaultFeatureBuilder.java (from rev 27279, geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/DefaultFeatureBuilder.java)
===================================================================
--- geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/DefaultFeatureBuilder.java 2007-09-30 22:30:23 UTC (rev 27279)
+++ geotools/trunk/gt/modules/library/legacy/src/main/java/org/geotools/feature/DefaultFeatureBuilder.java 2007-10-01 00:46:16 UTC (rev 27294)
@@ -0,0 +1,15 @@
+package org.geotools.feature;
+
+import org.geotools.feature.simple.SimpleFeatureBuilder;
+
+public class DefaultFeatureBuilder extends SimpleFeatureBuilder {
+
+ public DefaultFeatureBuilder(Feature feature) {
+ super(feature.getType());
+ init(feature);
+ }
+
+ public DefaultFeatureBuilder(FeatureType featureType) {
+ super(featureType);
+ }
+}
Copied: geotools/trunk/gt/modules/library/legacy/src/main/java/org/geotools/feature/DefaultFeatureFactory.java (from rev 27279, geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/DefaultFeatureFactory.java)
Copied: geotools/trunk/gt/modules/library/legacy/src/main/java/org/geotools/feature/DefaultFeatureType.java (from rev 27279, geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/DefaultFeatureType.java)
===================================================================
--- geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/DefaultFeatureType.java 2007-09-30 22:30:23 UTC (rev 27279)
+++ geotools/trunk/gt/modules/library/legacy/src/main/java/org/geotools/feature/DefaultFeatureType.java 2007-10-01 00:46:16 UTC (rev 27294)
@@ -0,0 +1,576 @@
+/*
+ * GeoTools - OpenSource mapping toolkit
+ * http://geotools.org
+ * (C) 2002-2006, GeoTools Project Managment Committee (PMC)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ */
+package org.geotools.feature;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+
+import org.geotools.feature.simple.SimpleFeatureTypeImpl;
+import org.geotools.resources.Utilities;
+import org.opengis.feature.type.AttributeDescriptor;
+import org.opengis.feature.type.GeometryDescriptor;
+import org.opengis.util.InternationalString;
+
+/**
+ * A basic implementation of FeatureType.
+ *
+ * @author Ian Schneider
+ * @source $URL$
+ * @version $Id$
+ */
+public class DefaultFeatureType extends SimpleFeatureTypeImpl implements FeatureType {
+
+ /** The name of this FeatureType. */
+ //private final String typeName;
+
+ /** The namespace to uniquely identify this FeatureType. */
+ //private final URI namespace;
+
+ /** The array of types that this FeatureType can have as attributes. */
+ //private final AttributeType[] types;
+
+ /** The FeatureTypes this is descended from. */
+ //private final FeatureType[] ancestors;
+
+ /** The default geometry AttributeType. */
+ //private final GeometryAttributeType defaultGeom;
+
+ private final int hashCode;
+
+ /** The position of the default Geometry
+ * Leave as package protected for use by DefaultFeature
+ */
+ //final int defaultGeomIdx;
+
+ /** An feature type with no attributes */
+ public static final FeatureType EMPTY = new DefaultFeatureType();
+
+ /** attname:string -> position:int */
+ //private final java.util.Map attLookup;
+
+ private final static URI toURI( String namespace ) throws SchemaException {
+ try {
+ return new URI( namespace );
+ } catch (URISyntaxException badNamespace ) {
+ throw new SchemaException( badNamespace );
+ }
+ }
+ public DefaultFeatureType(String typeName, String namespace,
+ Collection types, Collection superTypes, GeometryAttributeType defaultGeom)
+ throws SchemaException, NullPointerException {
+ this( typeName, toURI(namespace ), types, superTypes, defaultGeom );
+ }
+ public DefaultFeatureType(String typeName, URI namespace,
+ Collection types, Collection superTypes, GeometryAttributeType defaultGeom)
+ throws NullPointerException {
+ this( namespace != null ? new Name( namespace.toString(), typeName ) : new Name( FeatureTypes.DEFAULT_NAMESPACE.toString(), typeName ),
+ types, superTypes, defaultGeom );
+ }
+ private static final <T> List<T> toList( Collection<T> collection ){
+ if( collection == null ){
+ return new ArrayList<T>();
+ }
+ else {
+ return new ArrayList<T>(collection);
+ }
+ }
+ private static final FeatureType toFeatureType( Collection types ){
+ if( types == null || types.isEmpty() ){
+ return null;
+ }
+ if ( types.size() > 1 ) {
+ throw new IllegalArgumentException("May only specify a single parent");
+ }
+
+ return (FeatureType) types.iterator().next();
+
+ }
+ /**
+ * Constructs a new DefaultFeatureType.
+ *
+ * <p>
+ * Attributes from the superTypes will be copied to the list of attributes
+ * for this feature type.
+ *
+ * @param typeName The name to give this FeatureType.
+ * @param namespace The namespace of the new FeatureType.
+ * @param types The attributeTypes to use for validation.
+ * @param superTypes The ancestors of this FeatureType.
+ * @param defaultGeom The attributeType to set as the defaultGeometry.
+ *
+ * @throws SchemaException For problems making the FeatureType.
+ * @throws NullPointerException If typeName is null.
+ */
+ public DefaultFeatureType( org.opengis.feature.type.Name name,
+ Collection types, Collection superTypes, GeometryAttributeType defaultGeom)
+ throws NullPointerException {
+ super( name, (List)types, defaultGeom, false, null, toFeatureType(superTypes), null );
+
+ if (name == null) {
+ throw new NullPointerException("Name required");
+ }
+
+// this.typeName = typeName;
+// this.namespace = namespace == null ? FeatureTypes.DEFAULT_NAMESPACE : namespace;
+// this.ancestors = toFeatureTypes( superTypes );
+//
+// Collection attributes = new java.util.ArrayList( types );
+// for (int i = 0, ii = ancestors.length; i < ii; i++) {
+// FeatureType ancestor = ancestors[i];
+// for (int j = 0, jj = ancestor.getAttributeCount(); j < jj; j++) {
+// attributes.add(ancestor.getAttributeType(j));
+// }
+// }
+// if(attributes.size()!=0)
+// this.types = (AttributeType[]) attributes.toArray(new AttributeType[attributes.size()]);
+// else
+// this.types = new AttributeType[0];
+//
+// this.defaultGeom = defaultGeom;
+
+ //attLookup = new java.util.HashMap(this.types.length);
+ //attLookup = new java.util.HashMap(types.size());
+ //for (int i = 0, ii = this.types.length; i < ii; i++) {
+// int i = 0;
+// for( Iterator t = types.iterator(); t.hasNext(); ) {
+// AttributeType type = (AttributeType) t.next();
+// //attLookup.put(this.types[i].getLocalName(),new Integer(i));
+// attLookup.put(type.getLocalName(),new Integer(i++));
+// }
+
+ //this.defaultGeomIdx = find(defaultGeom);
+
+ hashCode = computeHash();
+ }
+
+
+ public DefaultFeatureType(
+ org.opengis.feature.type.Name name, List schema, GeometryDescriptor defaultGeometry,
+ boolean isAbstract, List restrictions,org.opengis.feature.type.AttributeType superType,
+ InternationalString description) {
+
+ super(name, schema, defaultGeometry,isAbstract, restrictions,superType, description);
+
+ hashCode = computeHash();
+ }
+ /**
+ * Builds an empty feature type, useful for testing
+ * @throws SchemaException
+ */
+ private DefaultFeatureType() {
+ this("emptyFeatreType", FeatureTypes.DEFAULT_NAMESPACE, Collections.EMPTY_LIST, Collections.EMPTY_LIST, null );
+// this.typeName = "emptyFeatureType";
+// namespace = FeatureTypes.DEFAULT_NAMESPACE;
+// this.types = new AttributeType[0];
+// this.ancestors = new FeatureType[0];
+// this.defaultGeomIdx = -1;
+// this.defaultGeom = null;
+// hashCode = computeHash();
+// attLookup = java.util.Collections.EMPTY_MAP;
+ }
+
+ /*
+ * additional initialization shared among constructors.
+ */
+ private void init() {
+
+ }
+
+ /**
+ * Creates a new feature, with a generated unique featureID. This is less
+ * than ideal, as a FeatureID should be persistant over time, generally
+ * created by a datasource. This method is more for testing that doesn't
+ * need featureID.
+ *
+ * @param attributes the array of attribute values
+ *
+ * @return The created feature with this as its feature type.
+ *
+ * @throws IllegalAttributeException if this FeatureType does not validate
+ * the attributes.
+ */
+ public Feature create(Object[] attributes) throws IllegalAttributeException {
+ return create(attributes, null);
+ }
+
+ /**
+ * Creates a new feature, with the proper featureID, using this
+ * FeatureType.
+ *
+ * @param attributes the array of attribute values.
+ * @param featureID the feature ID.
+ *
+ * @return the created feature.
+ *
+ * @throws IllegalAttributeException if this FeatureType does not validate
+ * the attributes.
+ */
+ public Feature create(Object[] attributes, String featureID)
+ throws IllegalAttributeException {
+ if ( attributes == null && getAttributeCount() != 0 ) {
+ throw new IllegalAttributeException("attributes null");
+ }
+
+ try {
+ DefaultFeatureBuilder builder = new DefaultFeatureBuilder( this );
+ builder.add( attributes );
+
+ return (Feature) builder.buildFeature(featureID);
+ }
+ catch( Exception e ) {
+ throw (IllegalAttributeException) new IllegalAttributeException("illegal attribute").initCause(e);
+ }
+
+ //return new DefaultFeature(this, attributes, featureID);
+ }
+
+ public Feature duplicate(Feature original) throws IllegalAttributeException{
+ if( original == null ) return null;
+ FeatureType featureType = original.getFeatureType();
+ if (!featureType.equals(this)) {
+ throw new IllegalAttributeException("Feature type " + featureType
+ + " does not match " + this);
+ }
+
+ try {
+ DefaultFeatureBuilder builder = new DefaultFeatureBuilder(original);
+ return (Feature) builder.buildFeature(original.getID());
+ }
+ catch( Exception e ) {
+ throw (IllegalAttributeException) new IllegalAttributeException("illegal attribute").initCause(e);
+ }
+
+// String id = original.getID();
+// int numAtts = featureType.getAttributeCount();
+// Object attributes[] = new Object[numAtts];
+// for (int i = 0; i < numAtts; i++) {
+// AttributeType curAttType = getAttributeType(i);
+// attributes[i] = curAttType.duplicate(original.getAttribute(i));
+// }
+// return featureType.create(attributes, id );
+ }
+
+ /**
+ * Gets the primary geometry AttributeType. If the FeatureType has more
+ * one geometry it is up to the implementor to determine which geometry is
+ * the default. If working with multiple geometries it is best to get the
+ * attributeTypes and iterate through them, checking isGeometry on each.
+ * This should just be used a convenience method when it is known that the
+ * features are flat.
+ *
+ * @return The attribute type of the default geometry, which will contain
+ * the position.
+ */
+ public GeometryAttributeType getDefaultGeometry() {
+// return defaultGeom;
+ return (GeometryAttributeType) super.getDefaultGeometry();
+ }
+
+ /**
+ * Gets the attributeType at this xPath, if the specified attributeType
+ * does not exist then null is returned.
+ *
+ * @param xPath XPath pointer to attribute type.
+ *
+ * @return True if attribute exists.
+ */
+ public AttributeType getAttributeType(String xPath) {
+ return (AttributeType) getAttribute(xPath);
+// AttributeType attType = null;
+// int idx = find(xPath);
+// if (idx >= 0)
+// attType = types[idx];
+// return attType;
+ }
+
+ /**
+ * Find the position of a given AttributeType.
+ *
+ * @param type The type to search for.
+ *
+ * @return -1 if not found, a zero-based index if found.
+ */
+ public int find(AttributeType type) {
+
+ if (type == null) return -1;
+ int idx = find(type.getLocalName());
+ if (idx < 0 || !getAttributes().get(idx).equals(type))
+ idx = -1;
+ return idx;
+ }
+
+ /**
+ * Find the position of an AttributeType which matches the given String.
+ * @param attName the name to look for
+ * @return -1 if not found, zero-based index otherwise
+ */
+ public int find(String attName) {
+ return indexOf(attName);
+// Integer idx = (Integer) attLookup.get(attName);
+// return idx == null ? -1 : idx.intValue();
+ }
+
+ /**
+ * Gets the attributeType at the specified index.
+ *
+ * @param position the position of the attribute to check.
+ *
+ * @return The attribute type at the specified position.
+ */
+ public AttributeType getAttributeType(int position) {
+// return types[position];
+ return (AttributeType) getAttributes().get(position);
+ }
+
+ public AttributeType[] getAttributeTypes() {
+// return (AttributeType[]) types.clone();
+ return (AttributeType[]) getAttributes().toArray( new AttributeType[ getAttributes().size()]);
+ }
+
+ /**
+ * Gets the global schema namespace.
+ *
+ * @return Namespace of schema.
+ */
+ public URI getNamespace() {
+// return namespace;
+ try {
+ return getName().getNamespaceURI() != null ? new URI( getName().getNamespaceURI() ) : null;
+ }
+ catch (URISyntaxException e) {
+ //dont have to worry, would have thrown an exception in constructor
+ return null;
+ }
+ }
+
+ /**
+ * Gets the type name for this schema.
+ *
+ * @return Namespace of schema.
+ */
+ public String getTypeName() {
+// return typeName;
+ return getName().getLocalPart();
+ }
+
+ /**
+ * This is only used twice in the whole geotools code base, and one of
+ * those is for a test, so we're removing it from the interface. If
+ * getAttributeType does not have the AttributeType it will just return
+ * null. Gets the number of occurrences of this attribute.
+ *
+ * @param xPath XPath pointer to attribute type.
+ *
+ * @return Number of occurrences.
+ */
+ public boolean hasAttributeType(String xPath) {
+ return getAttributeType(xPath) != null;
+ }
+
+ /**
+ * Returns the number of attributes at the first 'level' of the schema.
+ *
+ * @return the total number of first level attributes.
+ */
+ public int getAttributeCount() {
+// return types.length;
+ return getAttributes().size();
+ }
+
+// public boolean equals(FeatureType other) {
+// if(other == this)
+// return true;
+//
+// if (other == null) {
+// return false;
+// }
+//
+// if ((typeName == null) && (other.getTypeName() != null)) {
+// return false;
+// } else if (!typeName.equals(other.getTypeName())) {
+// return false;
+// }
+//
+// if ((namespace == null) && (other.getNamespace() != null)) {
+// return false;
+// } else if (!namespace.equals(other.getNamespace())) {
+// return false;
+// }
+//
+// if (types.length != other.getAttributeCount()) {
+// return false;
+// }
+//
+// for (int i = 0, ii = types.length; i < ii; i++) {
+// if (!types[i].equals(other.getAttributeType(i))) {
+// return false;
+// }
+// }
+//
+// return true;
+// }
+
+ private int computeHash() {
+// int hash = typeName.hashCode() ^ namespace.hashCode();
+// for (int i = 0, ii = types.length; i < ii; i++) {
+// hash ^= types[i].hashCode();
+// }
+// return hash;
+ return super.hashCode();
+ }
+
+ public int hashCode() {
+ return hashCode;
+ }
+
+// public String toString() {
+// String info = "name=" + typeName;
+// info += (" , namespace=" + namespace);
+// info += (" , abstract=" + isAbstract());
+//
+// String types1 = "types=(";
+//
+// for (int i = 0, ii = this.types.length; i < ii; i++) {
+// types1 += this.types[i].toString();
+//
+// if (i < ii) {
+// types1 += ",";
+// }
+// }
+//
+// types1 += ")";
+// info += (" , " + types1);
+//
+// return "DefaultFeatureType [" + info + "]";
+// }
+
+ public boolean equals(Object other) {
+ if (other instanceof FeatureType)
+ return super.equals((FeatureType) other);
+
+ return false;
+ }
+
+ /**
+ * Obtain an array of this FeatureTypes ancestors. Implementors should
+ * return a non-null array (may be of length 0).
+ *
+ * @return An array of ancestors.
+ */
+ public FeatureType[] getAncestors() {
+// return ancestors;
+ return null;
+ }
+
+ /**
+ * Is this FeatureType an abstract type?
+ *
+ * @return true if abstract, false otherwise.
+ */
+ public boolean isAbstract() {
+ return false;
+ }
+
+ /**
+ * A convenience method for calling<br>
+ * <code> FeatureType f1; FeatureType f2;
+ * f1.isDescendedFrom(f2.getNamespace(),f2.getName()); </code>
+ *
+ * @param type The type to compare to.
+ *
+ * @return true if descendant, false otherwise.
+ */
+ public boolean isDescendedFrom(FeatureType type) {
+ return isDescendedFrom(type.getNamespace(), type.getTypeName());
+ }
+
+ /**
+ * Test to determine whether this FeatureType is descended from the given
+ * FeatureType. Think of this relationship likes the "extends"
+ * relationship in java.
+ *
+ * @param nsURI The namespace URI to use.
+ * @param typeName1 The typeName.
+ *
+ * @return true if descendant, false otherwise.
+ *
+ * @task HACK: if nsURI is null only typeName is tested.
+ */
+ public boolean isDescendedFrom(URI nsURI, String typeName1) {
+ FeatureType superType = (FeatureType) getSuper();
+ while( superType != null ) {
+ if ( nsURI == null ) {
+ //dont match on namespace
+ if ( Utilities.equals(superType.getTypeName(), typeName1) ) {
+ return true;
+ }
+ }
+ else {
+ if ( Utilities.equals(superType.getNamespace(),nsURI) &&
+ Utilities.equals(superType.getTypeName(), typeName1)) {
+ return true;
+ }
+ }
+
+
+ superType = (FeatureType) superType.getSuper();
+ }
+
+ //one more effort, if no
+ return false;
+ }
+
+ static final class Abstract extends DefaultFeatureType {
+ public Abstract(String typeName, URI namespace, Collection types,
+ Collection superTypes, GeometryAttributeType defaultGeom)
+ throws SchemaException {
+ super(typeName, namespace, types, superTypes, defaultGeom);
+
+ Iterator st = superTypes.iterator();
+
+ while (st.hasNext()) {
+ FeatureType ft = (FeatureType) st.next();
+
+ //JD: removing this check, as its not the case in xml
+ //if (!ft.isAbstract()) {
+ // throw new SchemaException(
+ // "Abstract type cannot descend from no abstract type : "
+ // + ft);
+ //}
+ }
+ }
+
+ public final boolean isAbstract() {
+ return true;
+ }
+
+ public Feature create(Object[] atts) throws IllegalAttributeException {
+ throw new UnsupportedOperationException("Abstract Type");
+ }
+
+ public Feature create(Object[] atts, String id)
+ throws IllegalAttributeException {
+ throw new UnsupportedOperationException("Abstract Type");
+ }
+
+ }
+
+}
Copied: geotools/trunk/gt/modules/library/legacy/src/main/java/org/geotools/feature/DefaultFeatureTypeFactory.java (from rev 27279, geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/DefaultFeatureTypeFactory.java)
Copied: geotools/trunk/gt/modules/library/legacy/src/main/java/org/geotools/feature/DefaultFeatureTypeFactory2.java (from rev 27279, geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/DefaultFeatureTypeFactory2.java)
Copied: geotools/trunk/gt/modules/library/legacy/src/main/java/org/geotools/feature/Feature.java (from rev 27279, geotools/trunk/gt/modules/library/api/src/main/java/org/geotools/feature/Feature.java)
Copied: geotools/trunk/gt/modules/library/legacy/src/main/java/org/geotools/feature/FeatureAttributeType.java (from rev 27279, geotools/trunk/gt/modules/library/api/src/main/java/org/geotools/feature/FeatureAttributeType.java)
Copied: geotools/trunk/gt/modules/library/legacy/src/main/java/org/geotools/feature/FeatureCollectionType.java (from rev 27279, geotools/trunk/gt/modules/library/api/src/main/java/org/geotools/feature/FeatureCollectionType.java)
Copied: geotools/trunk/gt/modules/library/legacy/src/main/java/org/geotools/feature/FeatureType.java (from rev 27279, geotools/trunk/gt/modules/library/api/src/main/java/org/geotools/feature/FeatureType.java)
Copied: geotools/trunk/gt/modules/library/legacy/src/main/java/org/geotools/feature/FeatureTypeBuilder.java (from rev 27279, geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/FeatureTypeBuilder.java)
===================================================================
--- geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/FeatureTypeBuilder.java 2007-09-30 22:30:23 UTC (rev 27279)
+++ geotools/trunk/gt/modules/library/legacy/src/main/java/org/geotools/feature/FeatureTypeBuilder.java 2007-10-01 00:46:16 UTC (rev 27294)
@@ -0,0 +1,716 @@
+/*
+ * GeoTools - OpenSource mapping toolkit
+ * http://geotools.org
+ * (C) 2002-2006, GeoTools Project Managment Committee (PMC)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ */
+package org.geotools.feature;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import javax.swing.text.html.HTMLDocument.Iterator;
+
+import org.geotools.factory.CommonFactoryFinder;
+import org.geotools.factory.Factory;
+import org.geotools.factory.FactoryConfigurationError;
+import org.geotools.factory.GeoTools;
+import org.geotools.factory.Hints;
+import org.geotools.feature.type.FeatureTypeFactoryImpl;
+import org.opengis.feature.simple.SimpleFeatureType;
+
+/**
+ * A schema builder, because FeatureTypes are meant to be immutable, this
+ * object is mutable.
+ *
+ * <p>
+ * The basic idea for usage is that you configure the builder to whatever state
+ * is desired, setting properties and adding AttributeTypes. When the desired
+ * state is acheived, the expected FeatureType can be retrieved by calling<br>
+ * <code>getFeatureType()</code>
+ * </p>
+ * <p>
+ * Repeated calls to getFeatureType will return the <i>same</i> FeatureType
+ * given that no calls which modify the state of the factory are made.
+ * </p>
+ *
+ * <p>
+ * Here's an example of how to use this:
+ * <code><pre>
+ * FeatureTypeBuilder build = FeatureTypeFactory.newInstance();
+ * build.addType(...);
+ * build.setName(...);
+ * build.setNamespace(...);
+ * FeatureType type = build.getFeatureType();
+ * </pre></code>
+ * There are also a set of convenience methods for creation of FeatureTypes.
+ * These are the various newFeatureType methods.
+ * </p>
+ *
+ * </p>
+ *
+ * @author Ian Schneider
+ * @source $URL$
+ * @version $Id$
+ */
+public abstract class FeatureTypeBuilder extends FeatureTypes implements Factory {
+
+ /** abstract base type for all feature types */
+ public final static FeatureType ABSTRACT_FEATURE_TYPE;
+ static {
+ FeatureType featureType = null;
+ try {
+ featureType = new DefaultFeatureType("Feature",new URI("http://www.opengis.net/gml"), null, null, null);
+ }
+ catch(Exception e ) {
+ //shold not happen
+ }
+ ABSTRACT_FEATURE_TYPE = featureType;
+ }
+
+ /** If the base types have been initialized */
+ private static boolean initialized;
+
+ /** The name to give the FeatureType to be created. */
+ private String name;
+
+ /** The namespace to give the FeatureType to be created. */
+ private URI namespace;
+
+ /** If something in the factory has changed. */
+ private boolean dirty = true;
+
+ /** The type created. */
+ private FeatureType type = null;
+
+ /** The current defaultGeometry of the FeatureType returned. */
+ private GeometryAttributeType defaultGeometry = null;
+
+ /** If the type is abstract. */
+ private boolean abstractType = false;
+
+ /** The types that this is derived from. */
+ private java.util.Set superTypes;
+
+ /**
+ * Implementation hints - since this is a builder all
+ * hints are passed onto the FeatureType.
+ */
+ Map hints;
+
+ /**
+ * An empty public constructor. Subclasses should not provide a
+ * constructor.
+ * @deprecated
+ */
+ public FeatureTypeBuilder() {
+ this( Collections.EMPTY_MAP );
+ }
+
+ /**
+ * An empty public constructor. Subclasses should not provide a
+ * constructor.
+ */
+ public FeatureTypeBuilder( Map hints) {
+ this.hints = hints;
+ }
+
+ /**
+ * Returns the implementation hints. The default implementation returns en empty map.
+ * <p>
+ * Since the building of a FeatureType involves the collaboration of may
+ * Factory classes (that may be discovered over the course of the build process)
+ * we are forced to indicate that *all* hints are used.
+ * </p>
+ * <p>
+ * Strictly this is a Builder (not a factory) and has no need declair which
+ * hints are used (as one can never *keep* this builder in a factory registery.
+ * (It is stateful and cannot be used concurrently for example).
+ */
+ public Map getImplementationHints() {
+ return hints;
+ }
+ /**
+ * Create a new FeatureTypeFactory with the given typeName.
+ *
+ * @param name The typeName of the feature to create.
+ *
+ * @return A new FeatureTypeFactory instance.
+ *
+ * @throws FactoryConfigurationError If there exists a configuration error.
+ */
+ public static FeatureTypeFactory newInstance(String typeName)
+ throws FactoryConfigurationError {
+
+ // warning not sure if CommonFactoryFinder is going to cache the instance or not?
+ //
+ Hints hints = GeoTools.getDefaultHints();
+ if( hints == null ){
+ hints = new Hints( Hints.FEATURE_TYPE_FACTORY_NAME, typeName );
+ }
+ else {
+ hints.put( Hints.FEATURE_TYPE_FACTORY_NAME, typeName );
+ }
+ hints.put( Hints.FEATURE_TYPE_FACTORY_NAME, typeName );
+ return new DefaultFeatureTypeFactory();
+ }
+
+ /**
+ * Import all of the AttributeTypes from the given FeatureType into this
+ * factory.
+ *
+ * <p>
+ * If strict is true, non-uniquely named AttributeTypes will throw an
+ * exception.
+ * </p>
+ *
+ * <p>
+ * If strict is false, these will be silently ignored, but not added.
+ * </p>
+ *
+ * <p>
+ * No other information is imported.
+ * </p>
+ *
+ * @param type The FeatureType to import from.
+ * @param strict Enforce namespace restrictions.
+ *
+ * @throws IllegalArgumentException If strict is true and there are naming
+ * problems.
+ */
+ public void importType(FeatureType type, boolean strict)
+ throws IllegalArgumentException {
+ for (int i = 0, ii = type.getAttributeCount(); i < ii; i++) {
+ try {
+ addType(type.getAttributeType(i));
+ } catch (IllegalArgumentException iae) {
+ if (strict) {
+ throw iae;
+ }
+ }
+ }
+ }
+
+ /**
+ * Set the super types of this factory. The types will be copied into a
+ * Set.
+ *
+ * @param types A Collection of types.
+ */
+ public final void setSuperTypes(java.util.Collection types) {
+ superTypes = new java.util.LinkedHashSet(types);
+ }
+
+ /**
+ * Obtain the super types of this factory. Any user types will be appended
+ * to the built in types of this factory.
+ *
+ * @return A Collection representing the super types of the FeatureType
+ * this factory will create.
+ */
+ public final java.util.Collection getSuperTypes() {
+ Set supers = (superTypes == null) ? new HashSet() : superTypes;
+
+ boolean add = true;
+ for ( java.util.Iterator s = supers.iterator(); s.hasNext(); ) {
+ FeatureType superType = (FeatureType) s.next();
+ if ( superType.isDescendedFrom(ABSTRACT_FEATURE_TYPE) ) {
+ add = false;
+ }
+ }
+ if ( add ) {
+ supers.add(ABSTRACT_FEATURE_TYPE);
+ }
+
+ return supers;
+ }
+
+ /**
+ * A convienence method for importing AttributeTypes, simply calls<br>
+ * <code> importType(type,false) </code>
+ *
+ * @param type The type to import.
+ */
+ public void importType(FeatureType type) {
+ importType(type, false);
+ }
+
+ /**
+ * Set the name of the FeatureType this factory will produce.
+ *
+ * @param name The new name. May be null.
+ */
+ public void setName(String name) {
+ dirty |= isDifferent(name, this.name);
+ this.name = name;
+ }
+
+ /**
+ * Get the current configuration of the name of this factory.
+ *
+ * @return The current name. May be null.
+ */
+ public final String getName() {
+ return name;
+ }
+
+ /**
+ * Set the namespace of the FeatureType this factory will produce.
+ *
+ * @param namespace The new namespace. May be null.
+ */
+ public void setNamespace(URI namespace) {
+ dirty |= isDifferent(namespace, this.namespace);
+ this.namespace = namespace;
+ }
+
+ /**
+ * Get the current configuration of the namespace of this factory.
+ *
+ * @return The current namespace. May be null.
+ */
+ public final URI getNamespace() {
+ return namespace;
+ }
+
+ /**
+ * Is this factory configured to be abstract?
+ *
+ * @return True if it is, false if it aint.
+ */
+ public final boolean isAbstract() {
+ return abstractType;
+ }
+
+ /**
+ * Configure this factory to produce an abstract type.
+ *
+ * @param a True or false.
+ */
+ public final void setAbstract(boolean a) {
+ dirty = true;
+ this.abstractType = a;
+ }
+
+ private boolean isDifferent(String s1, String s2) {
+ if (s1 != null) {
+ return !s1.equals(s2);
+ }
+
+ if (s2 != null) {
+ return !s2.equals(s1);
+ }
+
+ return s1 != s2;
+ }
+ private boolean isDifferent(URI u1, URI u2) {
+ if (u1 != null) {
+ return !u1.equals(u2);
+ }
+
+ if (u2 != null) {
+ return !u2.equals(u1);
+ }
+
+ return u1 != u2;
+ }
+ /**
+ * Remove all the AttributeTypes in this factory.
+ */
+ public final void removeAll() {
+ int cnt = getAttributeCount();
+
+ for (int i = cnt; i > 0; i++) {
+ removeType(i - 1);
+ }
+ }
+
+ /**
+ * Add an array of AttributeTypes to this factory.
+ *
+ * @param types The types or a null array.
+ *
+ * @throws NullPointerException If any of the types are null.
+ * @throws IllegalArgumentException If there are naming problems.
+ */
+ public final void addTypes(AttributeType[] types)
+ throws NullPointerException, IllegalArgumentException {
+ if (types == null) {
+ return;
+ }
+
+ for (int i = 0; i < types.length; i++) {
+ addType(types[i]);
+ }
+ }
+
+ /**
+ * A the given AttributeType to this factory.
+ *
+ * @param type The type to add.
+ *
+ * @throws NullPointerException If the type is null.
+ * @throws IllegalArgumentException If another type exists with the same
+ * name.
+ */
+ public final void addType(AttributeType type)
+ throws NullPointerException, IllegalArgumentException {
+ if (type == null) {
+ throw new NullPointerException("type");
+ }
+
+ dirty = true;
+ check(type);
+ add(type);
+ }
+
+ /**
+ * Remove the given type from this factory.
+ *
+ * @param type The type to remove.
+ *
+ * @throws NullPointerException If the type is null.
+ */
+ public final void removeType(AttributeType type)
+ throws NullPointerException {
+ if (type == null) {
+ throw new NullPointerException("type");
+ }
+
+ dirty = true;
+
+ AttributeType removed = remove(type);
+
+ if (removed == defaultGeometry) {
+ defaultGeometry = null;
+ }
+ }
+
+ /**
+ * Insert the given type at the index specified.
+ *
+ * @param idx The index to insert at.
+ * @param type The AttributeType to insert.
+ *
+ * @throws NullPointerException If the type is null.
+ * @throws IllegalArgumentException If the AttributeType is not allowed.
+ * @throws ArrayIndexOutOfBoundsException If the index is out of range.
+ */
+ public final void addType(int idx, AttributeType type)
+ throws NullPointerException, IllegalArgumentException,
+ ArrayIndexOutOfBoundsException {
+ if (type == null) {
+ throw new NullPointerException("type");
+ }
+
+ dirty = true;
+ check(type);
+ add(idx, type);
+ }
+
+ /**
+ * Remove the AttributeType at the given index.
+ *
+ * @param idx The index to remove at.
+ *
+ * @throws ArrayIndexOutOfBoundsException If the index is out of bounds.
+ */
+ public final void removeType(int idx) throws ArrayIndexOutOfBoundsException {
+ dirty = true;
+
+ AttributeType removed = remove(idx);
+
+ if (removed == defaultGeometry) {
+ defaultGeometry = null;
+ }
+ }
+
+ /**
+ * Set the AttributeType at the given index. Overwrites the existing type.
+ *
+ * @param idx The index to use.
+ * @param type The type to use.
+ *
+ * @throws IllegalArgumentException If the type is not good.
+ * @throws NullPointerException if they type passed in is null
+ * @throws ArrayIndexOutOfBoundsException if the index is out of bounds.
+ */
+ public final void setType(int idx, AttributeType type)
+ throws IllegalArgumentException, NullPointerException,
+ ArrayIndexOutOfBoundsException {
+ if (type == null) {
+ throw new NullPointerException("type");
+ }
+
+ dirty = true;
+ check(type);
+
+ AttributeType removed = set(idx, type);
+
+ if (removed == defaultGeometry) {
+ defaultGeometry = null;
+ }
+ }
+
+ /**
+ * Swap the AttributeTypes at the given locations.
+ *
+ * @param idx1 The index of the first.
+ * @param idx2 The index of the second.
+ *
+ * @throws ArrayIndexOutOfBoundsException if either index is not in the
+ * array bounds.
+ */
+ public final void swap(int idx1, int idx2)
+ throws ArrayIndexOutOfBoundsException {
+ // implementation note:
+ // we must rely on the subclass implementation, which, hopefully does
+ // not do any checking. If we used setType, there is a name overlap.
+ AttributeType tmp = get(idx1);
+ set(idx1, get(idx2));
+ set(idx2, tmp);
+
+ // must do this!
+ dirty = true;
+ }
+
+ /**
+ * Return the AttributeType currently used as the defaultGeometry property
+ * for the FeatureType this factory will create.
+ *
+ * @return The AttributeType representing the defaultGeometry or null.
+ */
+ public final GeometryAttributeType getDefaultGeometry() {
+ return defaultGeometry;
+ }
+
+ /**
+ * Sets the defaultGeometry of this factory. If the defaultGeometry
+ * AttributeType does not exist as an AttributeType within this factory,
+ * it is added. This will overwrite the existing defaultGeometry, yet not
+ * remove it from the existing AttributeTypes.
+ *
+ * @param defaultGeometry The AttributeType to use as the defaultGeometry.
+ * May be null.
+ *
+ * @throws IllegalArgumentException if the type is not a geometry.
+ */
+ public final void setDefaultGeometry(GeometryAttributeType defaultGeometry)
+ throws IllegalArgumentException {
+ // check if Geometry
+ if ((defaultGeometry != null) && !defaultGeometry.isGeometry()) {
+ String mess = "Attempted to set a non-geometry type as "
+ + "defaultGeometry: ";
+ throw new IllegalArgumentException(mess + defaultGeometry);
+ }
+
+ dirty = true; // do this!
+ this.defaultGeometry = defaultGeometry;
+
+ // if the defaultGeometry hasn't been added, add it!
+ if ((defaultGeometry != null) && !contains(defaultGeometry)) {
+ addType(defaultGeometry);
+ }
+ }
+
+ /**
+ * Get a FeatureType which reflects the state of this factory. Any
+ * modifications to the state of the factory (adding, removing, or
+ * reordering any AttributeTypes or changing any other properties -
+ * isNillable,name,etc.), will cause the factory to "retool" itself. If
+ * the factory has not changed since a call to this method, the return
+ * value will be the same FeatureType which the previous method returned.
+ * Otherwise, a new FeatureType will be created.
+ *
+ * @return The featureType reflecting the current factory state.
+ *
+ * @throws SchemaException if name is null or blank
+ */
+ public final FeatureType getFeatureType() throws SchemaException {
+ // we're dirty, recreate the FeatureType
+ if (dirty || (type == null)) {
+ // no defaultGeometry assigned, search for one.
+ if (defaultGeometry == null) {
+ for (int i = 0, ii = getAttributeCount(); i < ii; i++) {
+ if (get(i) instanceof GeometryAttributeType) {
+ defaultGeometry = (GeometryAttributeType) get(i);
+ break;
+ }
+ }
+ }
+
+ if ((name == null) || (name.trim().length() == 0)) {
+ throw new SchemaException(
+ "Cannot create FeatureType with null or blank name");
+ }
+
+ type = createFeatureType();
+
+ // oops, the subclass messed up...
+ if (type == null) {
+ throw new NullPointerException(getClass().getName()
+ + ".createFeatureType()");
+ }
+
+ if (isAbstract() && !type.isAbstract()) {
+ throw new RuntimeException(
+ "FeatureTypeFactory poorly implemented, "
+ + "expected abstract type, received " + type);
+ }
+
+ // not dirty anymore.
+ dirty = false;
+ }
+
+ return type;
+ }
+
+ /**
+ * Returns a string representation of this factory.
+ *
+ * @return The string representing this factory.
+ */
+ public String toString() {
+ String types = "";
+
+ for (int i = 0, ii = getAttributeCount(); i < ii; i++) {
+ types += get(i);
+
+ if (i < ii) {
+ types += " , ";
+ }
+ }
+
+ return "FeatureTypeFactory(" + getClass().getName() + ") [ " + types
+ + " ]";
+ }
+
+ /**
+ * Check to see if this factory contains the given AttributeType. The
+ * comparison is done by name.
+ *
+ * @param type The AttributeType to search for by name.
+ *
+ * @return <tt>true</tt> if a like-named AttributeType exists,
+ * <tt>false</tt> otherwise.
+ */
+ public final boolean contains(AttributeType type) {
+ for (int i = 0, ii = getAttributeCount(); i < ii; i++) {
+ if (get(i).getLocalName().equals(type.getLocalName())) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ /**
+ * Checks to see if this factory already contains the type.
+ *
+ * @param type
+ *
+ * @throws IllegalArgumentException DOCUMENT ME!
+ */
+ protected void check(AttributeType type) {
+ if (contains(type)) {
+ throw new IllegalArgumentException("Duplicate AttributeTypes "
+ + type);
+ }
+ }
+
+ protected void addBaseTypes(Set types) {
+ // base class hook
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ */
+ protected abstract FeatureType createFeatureType()
+ throws SchemaException;
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param type
+ *
+ * @throws IllegalArgumentException
+ */
+ protected abstract void add(AttributeType type)
+ throws IllegalArgumentException;
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param type
+ *
+ */
+ protected abstract AttributeType remove(AttributeType type);
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param idx
+ * @param type
+ *
+ * @throws ArrayIndexOutOfBoundsException
+ * @throws IllegalArgumentException
+ */
+ protected abstract void add(int idx, AttributeType type)
+ throws ArrayIndexOutOfBoundsException, IllegalArgumentException;
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param idx
+ *
+ *
+ * @throws ArrayIndexOutOfBoundsException
+ */
+ protected abstract AttributeType remove(int idx)
+ throws ArrayIndexOutOfBoundsException;
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param idx
+ *
+ *
+ * @throws ArrayIndexOutOfBoundsException
+ */
+ public abstract AttributeType get(int idx)
+ throws ArrayIndexOutOfBoundsException;
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param idx
+ * @param type
+ *
+ *
+ * @throws ArrayIndexOutOfBoundsException
+ * @throws IllegalArgumentException
+ */
+ protected abstract AttributeType set(int idx, AttributeType type)
+ throws ArrayIndexOutOfBoundsException, IllegalArgumentException;
+
+ /**
+ * DOCUMENT ME!
+ *
+ */
+ public abstract int getAttributeCount();
+
+}
Copied: geotools/trunk/gt/modules/library/legacy/src/main/java/org/geotools/feature/FeatureTypeFactory.java (from rev 27279, geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/FeatureTypeFactory.java)
===================================================================
--- geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/FeatureTypeFactory.java 2007-09-30 22:30:23 UTC (rev 27279)
+++ geotools/trunk/gt/modules/library/legacy/src/main/java/org/geotools/feature/FeatureTypeFactory.java 2007-10-01 00:46:16 UTC (rev 27294)
@@ -0,0 +1,287 @@
+/*
+ * GeoTools - OpenSource mapping toolkit
+ * http://geotools.org
+ * (C) 2002-2006, GeoTools Project Managment Committee (PMC)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ */
+package org.geotools.feature;
+
+import java.net.URI;
+import java.util.Arrays;
+import java.util.List;
+
+import org.geotools.factory.FactoryCreator;
+import org.geotools.factory.FactoryRegistry;
+import org.geotools.factory.FactoryRegistryException;
+import org.geotools.feature.type.DefaultFeatureTypeBuilder;
+
+
+/**
+ * Replaced with use of FeatureTypeBuilder to follow standard pattern
+ * naming conventions.
+ *
+ * @deprecated Please use FeatureTypeBuilder
+ * @author Ian Schneider
+ * @source $URL$
+ * @version $Id$
+ */
+public abstract class FeatureTypeFactory extends FeatureTypeBuilder {
+ /**
+ * An empty public constructor. Subclasses should not provide a
+ * constructor.
+ */
+ public FeatureTypeFactory() {
+ // no op constructor
+ }
+
+ /**
+ * The service registry for this manager.
+ * Will be initialized only when first needed.
+ */
+ private static FactoryRegistry registry;
+
+ /**
+ * Returns the service registry. The registry will be created the first
+ * time this method is invoked.
+ */
+ private static FactoryRegistry getServiceRegistry() {
+ assert Thread.holdsLock(FeatureTypeFactory.class);
+ if (registry == null) {
+ registry = new FactoryCreator(Arrays.asList(new Class[] {
+ FeatureTypeFactory.class}));
+ }
+ return registry;
+ }
+
+ /**
+ * The most specific way to create a new FeatureType.
+ *
+ * @param types The AttributeTypes to create the FeatureType with.
+ * @param name The typeName of the FeatureType. Required, may not be null.
+ * @param ns The namespace of the FeatureType. Optional, may be null.
+ * @param isAbstract True if this created type should be abstract.
+ * @param superTypes A Collection of types the FeatureType will inherit
+ * from. Currently, all types inherit from feature in the opengis
+ * namespace.
+ *
+ * @return A new FeatureType created from the given arguments.
+ *
+ * @throws FactoryConfigurationError If there are problems creating a
+ * factory.
+ * @throws SchemaException If the AttributeTypes provided are invalid in
+ * some way.
+ */
+ public static FeatureType newFeatureType(AttributeType[] types,
+ String name, URI ns, boolean isAbstract, FeatureType[] superTypes)
+ throws FactoryRegistryException, SchemaException {
+ return newFeatureType(types, name, ns, isAbstract, superTypes, null);
+ }
+
+ /**
+ * The most specific way to create a new FeatureType.
+ *
+ * @param types The AttributeTypes to create the FeatureType with.
+ * @param name The typeName of the FeatureType. Required, may not be null.
+ * @param ns The namespace of the FeatureType. Optional, may be null.
+ * @param isAbstract True if this created type should be abstract.
+ * @param superTypes A Collection of types the FeatureType will inherit
+ * from. Currently, all types inherit from feature in the opengis
+ * namespace.
+ *
+ * @return A new FeatureType created from the given arguments.
+ *
+ * @throws FactoryRegistryException If there are problems creating a
+ * factory.
+ * @throws SchemaException If the AttributeTypes provided are invalid in
+ * some way.
+ */
+ public static FeatureType newFeatureType(AttributeType[] types,
+ String name, URI ns, boolean isAbstract, FeatureType[] superTypes, AttributeType defaultGeometry)
+ throws FactoryRegistryException, SchemaException {
+
+ return new DefaultFeatureType(name,ns, (List) Arrays.asList(types), (List) Arrays.asList(superTypes), (GeometryAttributeType) defaultGeometry);
+ }
+
+ /**
+ * The most specific way to create a new FeatureType.
+ *
+ * @param types The AttributeTypes to create the FeatureType with.
+ * @param name The typeName of the FeatureType. Required, may not be null.
+ * @param ns The namespace of the FeatureType. Optional, may be null.
+ * @param isAbstract True if this created type should be abstract.
+ * @param superTypes A Collection of types the FeatureType will inherit
+ * from. Currently, all types inherit from feature in the opengis
+ * namespace.
+ *
+ * @return A new FeatureType created from the given arguments.
+ *
+ * @throws FactoryRegistryException If there are problems creating a
+ * factory.
+ * @throws SchemaException If the AttributeTypes provided are invalid in
+ * some way.
+ */
+ public static FeatureType newFeatureType(AttributeType[] types,
+ String name, URI ns, boolean isAbstract, FeatureType[] superTypes, GeometryAttributeType defaultGeometry)
+ throws FactoryRegistryException, SchemaException {
+
+ List typeList = types == null ? null : (List) Arrays.asList(types);
+ List superTypeList = superTypes == null ? null : (List) Arrays.asList(superTypes);
+ return new DefaultFeatureType(name, ns, typeList, superTypeList, defaultGeometry);
+ }
+
+ /**
+ * Create a new FeatureType with the given AttributeTypes. A short cut for
+ * calling <code>newFeatureType(types,name,ns,isAbstract,null)</code>.
+ *
+ * @param types The AttributeTypes to create the FeatureType with.
+ * @param name The typeName of the FeatureType. Required, may not be null.
+ * @param ns The namespace of the FeatureType. Optional, may be null.
+ * @param isAbstract True if this created type should be abstract.
+ *
+ * @return A new FeatureType created from the given arguments.
+ *
+ * @throws FactoryRegistryException If there are problems creating a
+ * factory.
+ * @throws SchemaException If the AttributeTypes provided are invalid in
+ * some way.
+ */
+ public static FeatureType newFeatureType(AttributeType[] types,
+ String name, URI ns, boolean isAbstract)
+ throws FactoryRegistryException, SchemaException {
+ return newFeatureType(types, name, ns, isAbstract, null);
+ }
+
+ /**
+ * Create a new FeatureType with the given AttributeTypes. A short cut for
+ * calling <code>newFeatureType(types,name,ns,false,null)</code>.
+ *
+ * @param types The AttributeTypes to create the FeatureType with.
+ * @param name The typeName of the FeatureType. Required, may not be null.
+ * @param ns The namespace of the FeatureType. Optional, may be null.
+ *
+ * @return A new FeatureType created from the given arguments.
+ *
+ * @throws FactoryRegistryException If there are problems creating a
+ * factory.
+ * @throws SchemaException If the AttributeTypes provided are invalid in
+ * some way.
+ */
+ public static FeatureType newFeatureType(AttributeType[] types,
+ String name, URI ns)
+ throws FactoryRegistryException, SchemaException {
+ return newFeatureType(types, name, ns, false);
+ }
+
+ /**
+ * Create a new FeatureType with the given AttributeTypes. A short cut for
+ * calling <code>newFeatureType(types,name,null,false,null)</code>. Useful
+ * for test cases or datasources which may not allow a namespace.
+ *
+ * @param types The AttributeTypes to create the FeatureType with.
+ * @param name The typeName of the FeatureType. Required, may not be null.
+ *
+ * @return A new FeatureType created from the given arguments.
+ *
+ * @throws FactoryRegistryException If there are problems creating a
+ * factory.
+ * @throws SchemaException If the AttributeTypes provided are invalid in
+ * some way.
+ */
+ public static FeatureType newFeatureType(AttributeType[] types, String name)
+ throws FactoryRegistryException, SchemaException {
+ return newFeatureType(types, name, FeatureTypes.DEFAULT_NAMESPACE, false);
+ }
+
+ /**
+ * Create a new FeatureTypeFactory with the given typeName.
+ *
+ * @param name The typeName of the feature to create.
+ *
+ * @return A new FeatureTypeFactory instance.
+ *
+ * @throws FactoryRegistryException If there exists a configuration error.
+ */
+ public static synchronized FeatureTypeFactory newInstance(String name)
+ throws FactoryRegistryException {
+ FeatureTypeFactory factory = (FeatureTypeFactory) getServiceRegistry()
+ .getServiceProvider(FeatureTypeFactory.class, null, null, null);
+ FeatureTypeFactory newFactory;
+ try {
+ newFactory = (FeatureTypeFactory) factory.getClass().newInstance();
+ } catch (InstantiationException e) {
+ throw new FactoryRegistryException(e.getMessage(), e);
+ } catch (IllegalAccessException e) {
+ throw new FactoryRegistryException(e.getMessage(), e);
+ }
+ newFactory.setName(name);
+
+ return newFactory;
+ }
+
+ /**
+ * Create a FeatureTypeFactory which contains all of the AttributeTypes
+ * from the given FeatureType. This is simply a convenience method for<br>
+ * <code><pre>
+ * FeatureTypeFactory factory = FeatureTypeFactory.newInstace();
+ * factory.importType(yourTypeHere);
+ * factory.setName(original.getName());
+ * factory.setNamespace(original.getNamespace());
+ * factory.setNillable(original.isNillable());
+ * factory.setDefaultGeometry(original.getDefaultGeometry());
+ * </pre></code>
+ *
+ * @param original The FeatureType to obtain information from.
+ *
+ * @return A new FeatureTypeFactory which is initialized with the state of
+ * the original FeatureType.
+ *
+ * @throws FactoryRegistryException If a FeatureTypeFactory cannot be
+ * found.
+ */
+ public static FeatureTypeFactory createTemplate(FeatureType original)
+ throws FactoryRegistryException {
+
+ FeatureTypeFactory builder = FeatureTypeFactory.newInstance(original.getTypeName());
+ builder.importType(original);
+ builder.setNamespace(original.getNamespace());
+ builder.setDefaultGeometry(original.getDefaultGeometry());
+
+ FeatureType[] ancestors = original.getAncestors();
+
+ if (ancestors != null) {
+ builder.setSuperTypes(Arrays.asList(ancestors));
+ }
+
+ return builder;
+ }
+
+ /**
+ * Returns a string representation of this factory.
+ *
+ * @return The string representing this factory.
+ */
+ public String toString() {
+ String types = "";
+
+ for (int i = 0, ii = getAttributeCount(); i < ii; i++) {
+ types += get(i);
+
+ if (i < ii) {
+ types += " , ";
+ }
+ }
+
+ return "FeatureTypeFactory(" + getClass().getName() + ") [ " + types
+ + " ]";
+ }
+
+}
Copied: geotools/trunk/gt/modules/library/legacy/src/main/java/org/geotools/feature/GeometryAttributeType.java (from rev 27279, geotools/trunk/gt/modules/library/api/src/main/java/org/geotools/feature/GeometryAttributeType.java)
Copied: geotools/trunk/gt/modules/library/legacy/src/main/java/org/geotools/feature/MultiAttributeType.java (from rev 27279, geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/MultiAttributeType.java)
Copied: geotools/trunk/gt/modules/library/legacy/src/main/java/org/geotools/feature/PrimativeAttributeType.java (from rev 27279, geotools/trunk/gt/modules/library/api/src/main/java/org/geotools/feature/PrimativeAttributeType.java)
Copied: geotools/trunk/gt/modules/library/legacy/src/main/java/org/geotools/feature/SimpleFeature.java (from rev 27279, geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/SimpleFeature.java)
Copied: geotools/trunk/gt/modules/library/legacy/src/main/java/org/geotools/feature/SimpleFeatureType.java (from rev 27279, geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/SimpleFeatureType.java)
Copied: geotools/trunk/gt/modules/library/legacy/src/main/java/org/geotools/feature/type/ChoiceAttributeType.java (from rev 27279, geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/type/ChoiceAttributeType.java)
===================================================================
--- geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/type/ChoiceAttributeType.java 2007-09-30 22:30:23 UTC (rev 27279)
+++ geotools/trunk/gt/modules/library/legacy/src/main/java/org/geotools/feature/type/ChoiceAttributeType.java 2007-10-01 00:46:16 UTC (rev 27294)
@@ -0,0 +1,447 @@
+/*
+ * GeoTools - OpenSource mapping toolkit
+ * http://geotools.org
+ * (C) 2004-2006, GeoTools Project Managment Committee (PMC)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ */
+package org.geotools.feature.type;
+
+import com.vividsolutions.jts.geom.Geometry;
+import com.vividsolutions.jts.geom.GeometryFactory;
+import org.geotools.feature.AttributeType;
+import org.geotools.feature.DefaultAttributeType;
+import org.geotools.feature.GeometryAttributeType;
+import org.geotools.feature.IllegalAttributeException;
+import org.geotools.feature.Name;
+import org.opengis.feature.type.GeometryType;
+import org.opengis.filter.Filter;
+import org.opengis.referencing.crs.CoordinateReferenceSystem;
+import java.util.Arrays;
+
+import javax.swing.text.html.HTMLDocument.HTMLReader.IsindexAction;
+
+
+/**
+ * This represents a Choice of AttributeTypes. That means, an Attribute of this
+ * type may be one of any of this AttributeType's children. This attribute is
+ * not valid for Simple Features, and maps to the Choice construct in GML.
+ *
+ * <p>
+ * Another way to think about the ChoiceAttributeType is as a Union
+ * construction from C - it can store a number of different types of value,
+ * but it only stores the one value. The parse and validate methods try out
+ * each of the choices to see if one of them might work, since all are valid.
+ * The order that the child attributeTypes (the choices you can use) are
+ * specified is important, because some objects can parse and validate
+ * against several types. The first choice that returns true is the one that
+ * will
+ * </p>
+ *
+ * @author dzwiers
+ * @author Chris Holmes, TOPP
+ * @source $URL$
+ *
+ * @deprecated Will be removed in geotools 2.6.
+ */
+public class ChoiceAttributeType extends AttributeDescriptorImpl implements AttributeType {
+
+ private final AttributeType[] children;
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param copy
+ */
+ public ChoiceAttributeType(ChoiceAttributeType copy) {
+ super( copy.getType(), copy.getName(), copy.getMinOccurs(), copy.getMaxOccurs(), copy.isNillable(), copy.getDefaultValue() );
+
+ this.children = copyChildren(copy.getAttributeTypes());
+ }
+
+ // The field for 'Class type' should be added when GT has moved to java 1.5
+ public ChoiceAttributeType(String name, int min, int max,
+ AttributeType[] children, Filter restriction) {
+ super(DefaultAttributeType.createAttributeType(name, Object.class, restriction),
+ new Name(name),min,max,calculateNillableStatic(children),null);
+
+ //ensure immutable.
+ this.children = copyChildren(children);
+ }
+
+ public ChoiceAttributeType(String name, AttributeType[] children) {
+ this(name, 1, 1, children, Filter.EXCLUDE);
+ }
+
+ public Filter getRestriction() {
+ return DefaultAttributeType.getRestriction(this);
+ }
+
+ protected AttributeType[] copyChildren(AttributeType[] attributes) {
+ int length = attributes.length;
+ AttributeType[] returnArray = new AttributeType[length];
+ System.arraycopy(attributes, 0, returnArray, 0, length);
+ return returnArray;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getLocalName() {
+ return DefaultAttributeType.getLocalName(this);
+ }
+
+ /**
+ * Gets the class of the object. For a choice this is fairly useless, as
+ * it just returns Object, since we can not tell more than that.
+ *
+ * @return currently always returns Object.class, since we can't tell more.
+ *
+ * @task REVISIT: Perhaps we should add a getTypes() method that returns an
+ * array of classes, that would represent the classes that you can
+ * choose from.
+ * @task REVISIT: Would also be good if this could dynamically figure out
+ * the broadest class - like Number if the choices were Double and
+ * Integer.
+ *
+ * @see org.geotools.feature.AttributeType#getBinding()
+ */
+ public Class getBinding() {
+ return DefaultAttributeType.getBinding(this);
+ }
+
+ public boolean calculateNillable(AttributeType[] children) {
+ return calculateNillableStatic(children);
+ }
+
+ /**
+ * static verison of {@link #calculateNillable(AttributeType[])} which can
+ * be called from constructor.
+ */
+ private static boolean calculateNillableStatic(AttributeType[] children) {
+ for (int i = 0, ii = children.length; i < ii; i++) {
+ if (children[i].isNillable()) {
+ return true;
+ }
+ }
+
+ //none of the children can take a null, so no nulls are allowed.
+ return false;
+ }
+
+ /* (non-Javadoc)
+ * @see org.geotools.feature.AttributeType#isGeometry()
+ */
+ public boolean isGeometry() {
+ return false;
+ }
+
+ /**
+ * Goes through the children, and searches for a parser that works. This
+ * method searches in the order in which the children are specified ...
+ * please keep this in mind when creating these objects if you care about
+ * precedence.
+ *
+ * @param value The object to parse.
+ *
+ * @return The object parsed into the appropriate form for the Attribute.
+ *
+ * @throws IllegalArgumentException If the object could not be parsed by
+ * any of the child attribute Types.
+ */
+ public Object parse(Object value) throws IllegalArgumentException {
+ for (int i = 0; i < children.length; i++) {
+ try {
+ return children[i].parse(value);
+ } catch (IllegalArgumentException e) {
+ // ignore ... try the next
+ }
+ }
+
+ throw new IllegalArgumentException("Could not be parsed :(");
+ }
+
+ /**
+ * Goes through the children, and searches for a validator that works. This
+ * method searches in the order in which the children are specified ...
+ * please keep this in mind when creating these objects if you care about
+ * precedence.
+ *
+ * @param obj The object to validate.
+ *
+ * @throws IllegalArgumentException If none of the children can validate.
+ */
+ public void validate(Object obj) throws IllegalArgumentException {
+ for (int i = 0; i < children.length; i++) {
+ try {
+ children[i].validate(obj);
+
+ return; // validates
+ } catch (IllegalArgumentException e) {
+ // ignore ... try the next
+ }
+ }
+
+ throw new IllegalArgumentException("Could not be validated :(");
+ }
+
+ /**
+ * Goes through the children, and searches for a duplicator that works.
+ * This method searches in the order in which the children are specified
+ * ... please keep this in mind when creating these objects if you care
+ * about precedence.
+ *
+ * @param src The object to be duplicated.
+ *
+ * @return A deep copy of the original object.
+ *
+ * @throws IllegalAttributeException For any attribute errors.
+ * @throws IllegalArgumentException If the object could not be duplicated.
+ */
+ public Object duplicate(Object src) throws IllegalAttributeException {
+ for (int i = 0; i < children.length; i++) {
+ try {
+ return children[i].duplicate(src);
+ } catch (IllegalArgumentException e) {
+ // ignore ... try the next
+ }
+ }
+
+ throw new IllegalArgumentException("Could not be duplicated :(");
+ }
+
+ /**
+ * Returns the default value for the first child which does not throw an
+ * exception, null otherwise.
+ *
+ * @return The default value of the first choice that does not throw an
+ * exception.
+ */
+ public Object createDefaultValue() {
+ for (int i = 0; i < children.length; i++) {
+ try {
+ return children[i].createDefaultValue();
+ } catch (IllegalArgumentException e) {
+ // ignore ... try the next
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ * This is only used twice in the whole geotools code base, and one of
+ * those is for a test, so we're removing it from the interface. If
+ * getAttributeType does not have the AttributeType it will just return
+ * null. Gets the number of occurrences of this attribute.
+ *
+ * @param xPath XPath pointer to attribute type.
+ *
+ * @return Number of occurrences.
+ */
+ public boolean hasAttributeType(String xPath) {
+ return getAttributeType(xPath) != null;
+ }
+
+ /**
+ * Returns the number of attributes at the first 'level' of the schema.
+ *
+ * @return equivalent value to getAttributeTypes().length
+ */
+ public int getAttributeCount() {
+ return children.length;
+ }
+
+ /**
+ * Gets the attributeType at this xPath, if the specified attributeType
+ * does not exist then null is returned.
+ *
+ * @param xPath XPath pointer to attribute type.
+ *
+ * @return True if attribute exists.
+ */
+ public AttributeType getAttributeType(String xPath) {
+ AttributeType attType = null;
+ int idx = find(xPath);
+
+ if (idx >= 0) {
+ attType = children[idx];
+ }
+
+ return attType;
+ }
+
+ /**
+ * Find the position of a given AttributeType.
+ *
+ * @param type The type to search for.
+ *
+ * @return -1 if not found, a zero-based index if found.
+ */
+ public int find(AttributeType type) {
+ if (type == null) {
+ return -1;
+ }
+
+ int idx = find(type.getLocalName());
+
+ if ((idx < 0) || !children[idx].equals(type)) {
+ idx = -1;
+ }
+
+ return idx;
+ }
+
+ /**
+ * Find the position of an AttributeType which matches the given String.
+ *
+ * @param attName the name to look for
+ *
+ * @return -1 if not found, zero-based index otherwise
+ */
+ public int find(String attName) {
+ int i = 0;
+
+ while ((i < children.length) && !attName.equals(children[i].getLocalName()))
+ i++;
+
+ return (i == children.length) ? (-1) : i;
+ }
+
+ /**
+ * Gets the attributeType at the specified index.
+ *
+ * @param position the position of the attribute to check.
+ *
+ * @return The attribute type at the specified position.
+ */
+ public AttributeType getAttributeType(int position) {
+ return children[position];
+ }
+
+ public AttributeType[] getAttributeTypes() {
+ return (AttributeType[]) children.clone();
+ }
+
+ public boolean equals(Object other) {
+ if (other == null) {
+ return false;
+ }
+
+ if (!(other instanceof ChoiceAttributeType)) {
+ return false;
+ }
+
+ ChoiceAttributeType att = (ChoiceAttributeType) other;
+
+ if (!super.equals(att)) {
+ return false;
+ }
+
+ //hmmm... This makes the assumption that the order of the choices
+ //matters - not sure if that's true. Though the order does matter a
+ //a bit for our parse method, so this is probably right, since two
+ //with different orders could have diff. behaviors for that method.
+ if (!Arrays.equals(children, att.getAttributeTypes())) {
+ return false;
+ }
+
+ return true;
+ }
+
+ /**
+ * Override of hashCode.
+ *
+ * @return hashCode for this object.
+ */
+ public int hashCode() {
+ int hash = super.hashCode();
+
+ for (int i = 0, ii = children.length; i < ii; i++) {
+ hash ^= children[i].hashCode();
+ }
+
+ return hash;
+ }
+
+ /**
+ * Gets a representation of this object as a string.
+ *
+ * @return A representation of this object as a string
+ */
+ public String toString() {
+ String details = "name=" + name;
+ details += ((" , nillable=" + isNillable()) + ", min=" + getMinOccurs() + ", max=" + getMaxOccurs());
+ details += (", choices: " + Arrays.asList(children));
+
+ return "ChoiceAttributeType [" + details + "]";
+ }
+
+ /**
+ * A special class that is made so a Choice can serve as the Default
+ * Geometry in a FeatureType, by implementing GeometryAttributeType. It
+ * must be a choice between other GeometryAttributeTypes.
+ *
+ * @author Chris Holmes, TOPP
+ *
+ * @task TODO: Need to write code to check that all the geometry attributes
+ * are in the same crs. Right now we just blindly assume they are
+ * and return the first.
+ */
+ public static final class Geometric extends ChoiceAttributeType
+ implements GeometryAttributeType {
+ public Geometric(Geometric copy) {
+ super(copy);
+ }
+
+ // The field for 'Class type' should be added when GT has moved to java 1.5
+ public Geometric(String name, int min, int max,
+ GeometryAttributeType[] children, Filter restriction) {
+ super(name, min, max, children, restriction);
+ }
+
+ public Geometric(String name, GeometryAttributeType[] children) {
+ super(name, children);
+ }
+
+ public GeometryType getType() {
+ return new GeometryTypeImpl( getName(), Geometry.class, getCoordinateSystem(), false, false, null, null, null);
+ }
+
+
+ public CoordinateReferenceSystem getCoordinateSystem() {
+ //Hack - this is not guaranteed to be right, since right now we
+ //don't check in the constructors that all crses are the same.
+ GeometryAttributeType first = (GeometryAttributeType) getAttributeType(0);
+
+ return first.getCoordinateSystem();
+ }
+
+ public CoordinateReferenceSystem getCRS() {
+ return getCoordinateSystem();
+ }
+
+ public GeometryFactory getGeometryFactory() {
+ //Hack - this is not guaranteed to be right, since right now we
+ //don't check in the constructors that all crses are the same.
+ GeometryAttributeType first = (GeometryAttributeType) getAttributeType(0);
+
+ return first.getGeometryFactory();
+ }
+
+ /* (non-Javadoc)
+ * @see org.geotools.feature.AttributeType#isGeometry()
+ */
+ public boolean isGeometry() {
+ return true;
+ }
+ }
+}
Copied: geotools/trunk/gt/modules/library/legacy/src/main/java/org/geotools/feature/type/DefaultAttributeTypeBuilder.java (from rev 27279, geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/type/DefaultAttributeTypeBuilder.java)
Copied: geotools/trunk/gt/modules/library/legacy/src/main/java/org/geotools/feature/type/DefaultFeatureTypeBuilder.java (from rev 27279, geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/type/DefaultFeatureTypeBuilder.java)
Copied: geotools/trunk/gt/modules/library/legacy/src/main/java/org/geotools/feature/type/FeatureAttributeType.java (from rev 27279, geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/type/FeatureAttributeType.java)
Copied: geotools/trunk/gt/modules/library/legacy/src/main/java/org/geotools/feature/type/GeometricAttributeType.java (from rev 27279, geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/type/GeometricAttributeType.java)
===================================================================
--- geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/type/GeometricAttributeType.java 2007-09-30 22:30:23 UTC (rev 27279)
+++ geotools/trunk/gt/modules/library/legacy/src/main/java/org/geotools/feature/type/GeometricAttributeType.java 2007-10-01 00:46:16 UTC (rev 27294)
@@ -0,0 +1,192 @@
+/*
+ * GeoTools - OpenSource mapping toolkit
+ * http://geotools.org
+ * (C) 2004-2006, GeoTools Project Managment Committee (PMC)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ */
+package org.geotools.feature.type;
+
+import java.util.Collections;
+
+import org.geotools.feature.DefaultAttributeType;
+import org.geotools.feature.GeometryAttributeType;
+import org.geotools.feature.IllegalAttributeException;
+import org.geotools.geometry.jts.JTS;
+import org.opengis.feature.type.AttributeType;
+import org.opengis.feature.type.GeometryType;
+import org.opengis.feature.type.Name;
+import org.opengis.filter.Filter;
+import org.geotools.referencing.crs.DefaultGeocentricCRS;
+import org.opengis.referencing.crs.CoordinateReferenceSystem;
+
+import com.vividsolutions.jts.geom.Coordinate;
+import com.vividsolutions.jts.geom.Envelope;
+import com.vividsolutions.jts.geom.Geometry;
+import com.vividsolutions.jts.geom.GeometryCollection;
+import com.vividsolutions.jts.geom.GeometryFactory;
+import com.vividsolutions.jts.geom.LinearRing;
+import com.vividsolutions.jts.geom.PrecisionModel;
+import com.vividsolutions.jts.io.WKTReader;
+
+/**
+ * Provides ...TODO summary sentence
+ * <p>
+ * TODO Description
+ * </p><p>
+ * </p><p>
+ * Example Use:<pre><code>
+ * GeometryAttributeType x = new GeometryAttributeType( ... );
+ * TODO code example
+ * </code></pre>
+ * </p>
+ * @author Leprosy
+ * @since 0.3
+ * TODO: test wkt geometry parse.
+ * @source $URL$
+ *
+ * @deprecated use {@link GeometryTypeImpl}.
+ *
+ */
+public class GeometricAttributeType extends DefaultAttributeType implements org.geotools.feature.GeometryAttributeType{
+ /** CoordianteSystem used by this GeometryAttributeType */
+ //protected CoordinateReferenceSystem crs;
+ protected GeometryFactory geometryFactory;
+
+
+ public GeometricAttributeType(String name, Class type, boolean nillable, int min, int max,
+ Object defaultValue, CoordinateReferenceSystem crs, Filter filter) {
+ super(createAttributeType(name, type, crs,filter), name, nillable,min,max,defaultValue);
+
+ geometryFactory = getCoordinateSystem() == null ?
+ CSGeometryFactory.DEFAULT : new CSGeometryFactory(getCoordinateSystem());
+
+ /*
+ coordinateSystem = (cs != null) ? cs : LocalCoordinateSystem.CARTESIAN;
+ geometryFactory = (cs == LocalCoordinateSystem.CARTESIAN)
+ ? CSGeometryFactory.DEFAULT : new CSGeometryFactory(cs);
+ */
+ }
+
+ public GeometricAttributeType(String name, Class type, boolean nillable,
+ Object defaultValue, CoordinateReferenceSystem cs,Filter filter) {
+ this(name, type, nillable,1,1, defaultValue, cs,filter);
+ }
+
+ public GeometricAttributeType(GeometricAttributeType copy, CoordinateReferenceSystem override) {
+ this( copy.getLocalName(), copy.getBinding(), copy.isNillable(), copy.getMinOccurs(),copy.getMaxOccurs(), null, crs(override), copy.getRestriction() );
+
+
+ geometryFactory = (getCoordinateSystem() == DefaultGeocentricCRS.CARTESIAN)
+ ? CSGeometryFactory.DEFAULT : new CSGeometryFactory(getCoordinateSystem());
+ }
+
+
+ protected GeometricAttributeType(GeometryType type, Name name, int min, int max, boolean isNillable,Object defaultValue) {
+ super(type, name, min, max, isNillable,defaultValue);
+ }
+
+ public GeometryType getType() {
+ return (GeometryType) super.getType();
+ }
+
+ public CoordinateReferenceSystem getCoordinateSystem() {
+ return ((GeometryType)getType()).getCRS();
+ }
+
+ public CoordinateReferenceSystem getCRS() {
+ return getCoordinateSystem();
+ }
+
+ public GeometryFactory getGeometryFactory() {
+ return geometryFactory;
+ }
+
+
+ public Object duplicate(Object o) throws IllegalAttributeException {
+ if (o == null)
+ return o;
+ if (o instanceof Geometry) {
+ return ((Geometry)o).clone();
+ }
+ throw new IllegalAttributeException("Cannot duplicate " + o.getClass().getName());
+ }
+
+ public static CoordinateReferenceSystem crs( CoordinateReferenceSystem override ) {
+ CoordinateReferenceSystem crs = override;
+
+ if (override != null) {
+ crs = override;
+ }
+
+ if (crs == null) {
+ crs = DefaultGeocentricCRS.CARTESIAN;
+ }
+
+ return crs;
+ }
+
+ public static GeometryType createAttributeType(String name,Class binding,CoordinateReferenceSystem crs,Filter restriction) {
+ return new GeometryTypeImpl(
+ new org.geotools.feature.Name(name),binding,crs,false,false,
+ restriction != null ? Collections.singletonList(restriction) : Collections.EMPTY_LIST,
+ null,null);
+ }
+}
+/**
+ * Helper class used to force CS information on JTS Geometry
+ */
+class CSGeometryFactory extends GeometryFactory {
+
+ static public GeometryFactory DEFAULT = new GeometryFactory();
+ static public PrecisionModel DEFAULT_PRECISON_MODEL = new PrecisionModel();
+
+ public CSGeometryFactory(CoordinateReferenceSystem cs) {
+ super(toPrecisionModel(cs), toSRID(cs));
+ }
+
+ public GeometryCollection createGeometryCollection(Geometry[] geometries) {
+ GeometryCollection gc = super.createGeometryCollection(geometries);
+
+ // JTS14
+ //gc.setUserData( cs );
+ return gc;
+ }
+
+ public LinearRing createLinearRing(Coordinate[] coordinates) {
+ LinearRing lr = super.createLinearRing(coordinates);
+
+ // JTS14
+ //gc.setUserData( cs );
+ return lr;
+ }
+
+ //
+ // And so on
+ // Utility Functions
+ private static int toSRID(CoordinateReferenceSystem cs) {
+ if ((cs == null) || (cs == DefaultGeocentricCRS.CARTESIAN)) {
+ return 0;
+ }
+
+ // not sure how to tell SRID from CoordinateSystem?
+ return 0;
+ }
+
+ private static PrecisionModel toPrecisionModel(CoordinateReferenceSystem cs) {
+ if ((cs == null) || (cs == DefaultGeocentricCRS.CARTESIAN)) {
+ return DEFAULT_PRECISON_MODEL;
+ }
+
+ return DEFAULT_PRECISON_MODEL;
+ }
+}
+
Copied: geotools/trunk/gt/modules/library/legacy/src/main/java/org/geotools/feature/type/ListAttributeType.java (from rev 27279, geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/type/ListAttributeType.java)
Copied: geotools/trunk/gt/modules/library/legacy/src/main/java/org/geotools/feature/type/NestedAttributeType.java (from rev 27279, geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/type/NestedAttributeType.java)
Copied: geotools/trunk/gt/modules/library/legacy/src/main/java/org/geotools/feature/type/NumericAttributeType.java (from rev 27279, geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/type/NumericAttributeType.java)
Copied: geotools/trunk/gt/modules/library/legacy/src/main/java/org/geotools/feature/type/SetAttributeType.java (from rev 27279, geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/type/SetAttributeType.java)
Copied: geotools/trunk/gt/modules/library/legacy/src/main/java/org/geotools/feature/type/TemporalAttributeType.java (from rev 27279, geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/type/TemporalAttributeType.java)
Copied: geotools/trunk/gt/modules/library/legacy/src/main/java/org/geotools/feature/type/TextualAttributeType.java (from rev 27279, geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/type/TextualAttributeType.java)
Copied: geotools/trunk/gt/modules/library/legacy/src/test/java/org/geotools/feature/AttributeTypeTest.java (from rev 27279, geotools/trunk/gt/modules/library/main/src/test/java/org/geotools/feature/AttributeTypeTest.java)
===================================================================
--- geotools/trunk/gt/modules/library/main/src/test/java/org/geotools/feature/AttributeTypeTest.java 2007-09-30 22:30:23 UTC (rev 27279)
+++ geotools/trunk/gt/modules/library/legacy/src/test/java/org/geotools/feature/AttributeTypeTest.java 2007-10-01 00:46:16 UTC (rev 27294)
@@ -0,0 +1,336 @@
+/*
+ * GeoTools - OpenSource mapping toolkit
+ * http://geotools.org
+ * (C) 2003-2006, Geotools Project Managment Committee (PMC)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * Created on July 18, 2003, 12:56 PM
+ */
+package org.geotools.feature;
+
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import com.vividsolutions.jts.geom.Geometry;
+import com.vividsolutions.jts.geom.Point;
+
+/**
+ *
+ * @author jamesm
+ * @source $URL$
+ */
+public class AttributeTypeTest extends TestCase {
+
+ public AttributeTypeTest(java.lang.String testName) {
+ super(testName);
+ }
+
+ public static void main(String[] args) {
+ junit.textui.TestRunner.run(suite());
+ }
+
+ public static Test suite() {
+ TestSuite suite = new TestSuite(AttributeTypeTest.class);
+ return suite;
+ }
+
+ public void testAttributeTypeFactory(){
+ AttributeType type = AttributeTypeFactory.newAttributeType("testAttribute", Double.class);
+ assertNotNull(type);
+ type = AttributeTypeFactory.newAttributeType("testAttribute", Double.class, true);
+ assertNotNull(type);
+ type = AttributeTypeFactory.newAttributeType("testAttribute", Double.class, false);
+ assertNotNull(type);
+ }
+
+ public void testGetName(){
+ AttributeType type = AttributeTypeFactory.newAttributeType("testAttribute", Double.class);
+ assertEquals("testAttribute", type.getLocalName());
+ }
+
+ public void testGetType(){
+ AttributeType type = AttributeTypeFactory.newAttributeType("testAttribute", Double.class);
+ assertEquals(Double.class, type.getBinding());
+ }
+
+
+ public void testEquals(){
+ AttributeType typeA = AttributeTypeFactory.newAttributeType("testAttribute", Double.class);
+ AttributeType typeB = AttributeTypeFactory.newAttributeType("testAttribute", Double.class);
+ AttributeType typeC = AttributeTypeFactory.newAttributeType("differnetName", Double.class);
+ AttributeType typeD = AttributeTypeFactory.newAttributeType("testAttribute", Integer.class);
+ AttributeType typeE = AttributeTypeFactory.newAttributeType(null, Integer.class);
+ AttributeType typeF = AttributeTypeFactory.newAttributeType(null, Integer.class);
+ assertTrue(typeA.equals(typeA));
+ assertTrue(typeA.equals(typeB));
+ assertTrue(typeE.equals(typeF));
+ assertTrue(!typeA.equals(typeC));
+ assertTrue(!typeA.equals(typeD));
+ assertTrue(!typeA.equals(null));
+ assertTrue(!typeA.equals(typeE));
+ }
+
+ public void testIsNillable(){
+ AttributeType type = AttributeTypeFactory.newAttributeType("testAttribute", Double.class);
+ assertEquals(true, type.isNillable());
+ type = AttributeTypeFactory.newAttributeType("testAttribute", Double.class, true);
+ assertEquals(true, type.isNillable());
+ type = AttributeTypeFactory.newAttributeType("testAttribute", Double.class, false);
+ assertEquals(false, type.isNillable());
+ }
+
+ public void testIsGeometry(){
+ AttributeType type = AttributeTypeFactory.newAttributeType("testAttribute", Double.class);
+ assertEquals(false, type instanceof GeometryAttributeType);
+ type = AttributeTypeFactory.newAttributeType("testAttribute", Point.class);
+ assertEquals(true, type instanceof GeometryAttributeType);
+ type = AttributeTypeFactory.newAttributeType("testAttribute", Geometry.class);
+ assertEquals(true, type instanceof GeometryAttributeType);
+ }
+
+ public void testValidate(){
+ AttributeType type = AttributeTypeFactory.newAttributeType("testAttribute", Double.class, true);
+ try{
+ type.validate(new Double(3));
+ }
+ catch(IllegalArgumentException iae){
+ fail();
+ }
+ try{
+ type.validate(new Integer(3));
+ fail("Integer should not be validated by a Double type");
+ }
+ catch(IllegalArgumentException iae){
+
+ }
+ try{
+ type.validate(null);
+ }
+ catch(IllegalArgumentException iae){
+ fail("null should have been allowed as type is Nillable");
+ }
+ type = AttributeTypeFactory.newAttributeType("testAttribute", Double.class, false);
+ try{
+ type.validate(null);
+ type.validate((Double)null);
+ fail("null should not have been allowed as type is not Nillable");
+ }
+ catch(IllegalArgumentException iae){
+
+ }
+
+
+ type = AttributeTypeFactory.newAttributeType("testAttribute", List.class, true);
+ try{
+ type.validate(new ArrayList());
+ }
+ catch(IllegalArgumentException iae){
+ fail("decended types should be allowed");
+ }
+
+
+ }
+
+ public void testFeatureConstruction() throws Exception {
+ FeatureType a = FeatureTypeFactory.newFeatureType(new AttributeType[]{},"noAttribs");
+ FeatureType b = FeatureTypeFactory.newFeatureType(new AttributeType[]{AttributeTypeFactory.newAttributeType("testAttribute", Double.class)},"oneAttribs");
+ //Direct construction should never be used like this, however it is the only way to test
+ //the code fully
+ AttributeType feat = AttributeTypeFactory.newAttributeType( "good",a, false);
+ }
+
+ public void testFeatureValidate() throws SchemaException {
+// try{
+// //FeatureType b = FeatureTypeFactory.newFeatureType(new AttributeType[]{AttributeTypeFactory.newAttributeType("testAttribute", Double.class)},"oneAttribs");
+//
+// FeatureType type = FeatureTypeFactory.newFeatureType(new AttributeType[]{},"noAttribs");
+// AttributeType feat = AttributeTypeFactory.newAttributeType("foo", type);
+// Feature good = type.create(new Object[]{});
+// feat.validate(good);
+// }
+// catch(IllegalAttributeException iae){
+// fail();
+// }
+// Feature bad = null;
+// FeatureType b = FeatureTypeFactory.newFeatureType(new AttributeType[]{AttributeTypeFactory.newAttributeType("testAttribute", Double.class)},"oneAttribs");
+//
+// try{
+// bad = b.create(new Object[]{new Double(4)});
+// }
+// catch(IllegalAttributeException iae){
+// fail();
+// }
+//
+
+// try{
+// FeatureType type = FeatureTypeFactory.newFeatureType(new AttributeType[]{},"noAttribs");
+// AttributeType feat = AttributeTypeFactory.newAttributeType("foo", type);
+// feat.validate(bad);
+// fail();
+// }
+// catch(IllegalArgumentException iae){
+//
+// }
+
+
+
+ }
+
+
+ public void testNumericConstruction(){
+ //Direct construction should never be used like this, however it is the only way to test
+ //the code fully
+ AttributeType num = AttributeTypeFactory.newAttributeType("good", Double.class, false, 0,new Double(0));
+
+ try{
+ num = AttributeTypeFactory.newAttributeType("bad", String.class, false,0,new Double(0));
+ fail("Numeric type should not be constructable with type String");
+ }
+ catch(IllegalArgumentException iae){
+ }
+ }
+
+
+ public void testIsNested(){
+ AttributeType type = AttributeTypeFactory.newAttributeType("testAttribute", Double.class, true);
+// assertEquals(false, type.isNested());
+ }
+
+
+ public void testParse(){
+ AttributeType type = AttributeTypeFactory.newAttributeType("testAttribute", Double.class, true);
+ assertEquals(null, type.parse(null));
+ assertEquals(new Double(1.1),(Double)type.parse(new Double(1.1)));
+
+ type = AttributeTypeFactory.newAttributeType("testAttribute", Integer.class, true);
+ assertEquals(new Integer(10),(Integer)type.parse(new Integer(10)));
+
+ type = AttributeTypeFactory.newAttributeType("testAttribute", String.class, true);
+ assertEquals("foo",type.parse("foo"));
+
+ type = AttributeTypeFactory.newAttributeType("testAttribute", Number.class, true);
+ assertEquals(3d,((Number)type.parse(new Long(3))).doubleValue(),0);
+ assertEquals(4.4d,((Number)type.parse("4.4")).doubleValue(),0);
+ type = AttributeTypeFactory.newAttributeType("testAttribute", Number.class, true);
+
+
+ }
+
+ public void testParseNumberSubclass() throws Exception {
+
+ AttributeType type = AttributeTypeFactory.newAttributeType("testbigdecimal", BigDecimal.class,true);
+
+ Object value = type.parse(new BigDecimal(111.111));
+
+ // I modified this test to pass using BigDecimal. -IanS
+// assertEquals(new Double(111.111),value);
+// assertEquals(Double.class,value.getClass());
+
+ assertEquals(new BigDecimal(111.111),value);
+ assertEquals(BigDecimal.class,value.getClass());
+ }
+
+ public void testBigNumberSupport() throws Exception {
+ AttributeType decimal = AttributeTypeFactory.newAttributeType("decimal", BigDecimal.class,true);
+ AttributeType integer = AttributeTypeFactory.newAttributeType("integer", BigInteger.class,true);
+
+ BigDecimal decimalValue = new BigDecimal("200");
+ BigInteger integerValue = new BigInteger("200");
+ Object[] vals = new Object[] {
+ "200",
+ new Integer(200),
+ new Double(200),
+ new Long(200),
+ decimalValue
+ };
+
+
+ // BigDecimal tests
+ for (int i = 0, ii = vals.length; i < ii; i++) {
+ checkNumericAttributeSetting(decimal, vals[i], decimalValue);
+ }
+
+
+ // BigInteger tests
+ for (int i = 0, ii = vals.length; i < ii; i++) {
+ checkNumericAttributeSetting(decimal, vals[i], integerValue);
+ }
+
+ checkNull(decimal);
+ checkNull(integer);
+ }
+
+ private void checkNull(AttributeType type) {
+ if (type.isNillable()) {
+ assertNull(type.parse(null));
+ type.validate(null);
+ }
+ }
+
+ private void checkNumericAttributeSetting(AttributeType type,Object value,Number expected) {
+ Number parsed = (Number) type.parse(value);
+ type.validate(parsed);
+ assertEquals(parsed.intValue(),expected.intValue());
+ }
+
+ public void testTextualSupport() throws Exception {
+ AttributeType textual = AttributeTypeFactory.newAttributeType("textual",String.class,true);
+
+ Object[] vals = new Object[] {
+ "stringValue",
+ new StringBuffer("stringValue"),
+ new Date(System.currentTimeMillis()),
+ new Long(1000000)
+ };
+ for (int i = 0, ii = vals.length; i < ii; i++) {
+ Object p = textual.parse(vals[i]);
+ textual.validate(p);
+ assertEquals(p.getClass(),String.class);
+ }
+
+ checkNull(textual);
+ }
+
+ public void textTemporalSupport() throws Exception {
+ AttributeType temporal = AttributeTypeFactory.newAttributeType("temporal",Date.class,true);
+
+ Date d = new Date();
+
+ Object[] vals = new Object[] {
+ new String(d.toString()),
+ new Date(),
+ new Long(d.getTime())
+ };
+
+ for (int i = 0, ii = vals.length; i < ii; i++) {
+ checkTemporalAttributeSetting(temporal, vals[i], d);
+ }
+
+ checkNull(temporal);
+ }
+
+ private void checkTemporalAttributeSetting(AttributeType type,Object value,Date expected) {
+ Object p = type.parse(value);
+ type.validate(p);
+ assertEquals(expected,p);
+ }
+
+
+
+}
Copied: geotools/trunk/gt/modules/library/legacy/src/test/java/org/geotools/feature/FeatureTypeFactoryTest.java (from rev 27279, geotools/trunk/gt/modules/library/main/src/test/java/org/geotools/feature/FeatureTypeFactoryTest.java)
Copied: geotools/trunk/gt/modules/library/legacy/src/test/java/org/geotools/feature/FlatFeatureFactorySpiTest.java (from rev 27279, geotools/trunk/gt/modules/library/main/src/test/java/org/geotools/feature/FlatFeatureFactorySpiTest.java)
Added: geotools/trunk/gt/modules/library/legacy/src/test/java/org/geotools/feature/type/DefaultFeatureTypeBuilderTest.java
===================================================================
--- geotools/trunk/gt/modules/library/legacy/src/test/java/org/geotools/feature/type/DefaultFeatureTypeBuilderTest.java 2007-10-01 00:43:34 UTC (rev 27293)
+++ geotools/trunk/gt/modules/library/legacy/src/test/java/org/geotools/feature/type/DefaultFeatureTypeBuilderTest.java 2007-10-01 00:46:16 UTC (rev 27294)
@@ -0,0 +1,43 @@
+package org.geotools.feature.type;
+
+import junit.framework.TestCase;
+
+import org.geotools.feature.AttributeType;
+import org.geotools.feature.DefaultFeatureType;
+
+import com.vividsolutions.jts.geom.Point;
+
+public class DefaultFeatureTypeBuilderTest extends TestCase {
+
+ static final String URI = "gopher://localhost/test";
+
+ DefaultFeatureTypeBuilder builder;
+
+ protected void setUp() throws Exception {
+ builder = new DefaultFeatureTypeBuilder();
+ }
+
+ public void testSanity() {
+ builder.setName( "testName" );
+ builder.setNamespaceURI( "testNamespaceURI" );
+ builder.add( "point", Point.class );
+ builder.add( "integer", Integer.class );
+
+ DefaultFeatureType type = (DefaultFeatureType) builder.buildFeatureType();
+ assertNotNull( type );
+
+ assertEquals( 2, type.getAttributeCount() );
+
+ AttributeType t = type.getAttributeType( "point" );
+ assertNotNull( t );
+ assertEquals( Point.class, t.getBinding() );
+
+ t = type.getAttributeType( "integer" );
+ assertNotNull( t );
+ assertEquals( Integer.class, t.getBinding() );
+
+ t = type.getDefaultGeometry();
+ assertNotNull( t );
+ assertEquals( Point.class, t.getBinding() );
+ }
+}
Modified: geotools/trunk/gt/modules/library/main/pom.xml
===================================================================
--- geotools/trunk/gt/modules/library/main/pom.xml 2007-10-01 00:43:34 UTC (rev 27293)
+++ geotools/trunk/gt/modules/library/main/pom.xml 2007-10-01 00:46:16 UTC (rev 27294)
@@ -268,6 +268,19 @@
</execution>
</executions>
</plugin>
+
+ <!-- build test jar so that tests can be shared with legacy feature model module -->
+ <plugin>
+ <artifactId>maven-jar-plugin</artifactId>
+ <executions>
+ <execution>
+ <phase>package</phase>
+ <goals>
+ <goal>test-jar</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
</plugins>
</build>
Modified: geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/AttributeImpl.java
===================================================================
--- geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/AttributeImpl.java 2007-10-01 00:43:34 UTC (rev 27293)
+++ geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/AttributeImpl.java 2007-10-01 00:46:16 UTC (rev 27294)
@@ -6,6 +6,7 @@
import java.util.Map;
import org.geotools.feature.IllegalAttributeException;
+import org.geotools.feature.simple.SimpleFeatureBuilder;
import org.geotools.feature.type.AttributeDescriptorImpl;
import org.geotools.feature.type.Descriptors;
import org.geotools.feature.type.Types;
@@ -41,8 +42,10 @@
String id) {
super( content, descriptor );
- //set the id
- this.id = id;
+ if(id == null && getType().isIdentified())
+ this.id = SimpleFeatureBuilder.createDefaultFeatureId();
+ else //set the id
+ this.id = id;
//if the content is null and the descriptor says isNillable is false,
// then set the default value
@@ -50,6 +53,7 @@
setValue(descriptor.getDefaultValue());
}
+ Types.validate(this, getValue());
}
public AttributeImpl(Object content, AttributeType type, String id) {
Modified: geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/AttributeTypeBuilder.java
===================================================================
--- geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/AttributeTypeBuilder.java 2007-10-01 00:43:34 UTC (rev 27293)
+++ geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/AttributeTypeBuilder.java 2007-10-01 00:46:16 UTC (rev 27294)
@@ -196,7 +196,7 @@
restrictions = null;
description = null;
isIdentifiable = false;
- binding = Object.class;
+ binding = null;
defaultValue = null;
superType = null;
crs = null;
@@ -443,6 +443,8 @@
* @see #buildDescriptor(String, AttributeType)
*/
public AttributeDescriptor buildDescriptor( String name ) {
+ if(binding == null)
+ throw new IllegalStateException("No binding has been provided for this attribute");
if ( crs != null || Geometry.class.isAssignableFrom(binding)) {
return buildDescriptor(name, buildGeometryType());
}
Deleted: geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/AttributeTypeFactory.java
===================================================================
--- geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/AttributeTypeFactory.java 2007-10-01 00:43:34 UTC (rev 27293)
+++ geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/AttributeTypeFactory.java 2007-10-01 00:46:16 UTC (rev 27294)
@@ -1,285 +0,0 @@
-/*
- * GeoTools - OpenSource mapping toolkit
- * http://geotools.org
- * (C) 2002-2006, GeoTools Project Managment Committee (PMC)
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation;
- * version 2.1 of the License.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- */
-package org.geotools.feature;
-
-import java.util.Collections;
-import java.util.Map;
-
-import org.geotools.factory.CommonFactoryFinder;
-import org.geotools.factory.Factory;
-import org.geotools.factory.GeoTools;
-import org.opengis.filter.Filter;
-
-
-/**
- * Abstract class for AttributeType factories. Extending classes need only
- * implement createAttributeType
- *
- * @author Ian Schneider, USDA-ARS
- * @source $URL$
- * @version $Id$
- */
-public abstract class AttributeTypeFactory implements Factory {
-
- /**
- * Returns the default attribute factory for the system - constucting a new
- * one if this is first time the method has been called.
- *
- * @return the default instance of AttributeTypeFactory.
- */
- public static AttributeTypeFactory defaultInstance() {
- // depend on CommonFactoryFinder to keep singleton cached
- //
- return CommonFactoryFinder.getAttributeTypeFactory( GeoTools.getDefaultHints() );
- }
-
- /**
- * Returns a new instance of the current AttributeTypeFactory.
- * <p>
- * If no implementations are found then DefaultAttributeTypeFactory is returned.
- * </p>
- * @return A new instance of an AttributeTypeFactory.
- * @deprecated Please use CommonFactoryFinder
- */
- public static AttributeTypeFactory newInstance() {
- return new DefaultAttributeTypeFactory(); // only need new instance if factory stateful?
- }
-
- /**
- * Creates a new AttributeType with the given name, class and nillable
- * values.
- *
- * @param name The name of the AttributeType to be created.
- * @param clazz The class that objects will validate against.
- * @param isNillable If nulls are allowed (will force min=0)
- *
- * @return A new AttributeType of name, clazz and isNillable.
- */
- public static AttributeType newAttributeType(String name, Class clazz,
- boolean isNillable,int fieldLength,Object defaultValue) {
- return defaultInstance().createAttributeType(name, clazz, isNillable,fieldLength, defaultValue);
- }
- /**
- * Creates a new AttributeType with the addition of metadata like CRS.
- * <p>
- * Currently MetaData is used to supply the CoordinateSequence
- * when making a GeometryAttributeType.
- * </p>
- * @param name name of the attribute type to be created
- * @param clazz Class that objects will validate against
- * @param isNillable If nulls are allowed (will force min=0)
- * @param fieldLength A common restriction (this will produce a Filter)
- * @param defaultValue Initial valid value for new Feature
- * @param metaData Additional information (example a CoordinateReferenceSystem for a Geometry)
- *
- * @return Created AttributeType
- */
- public static AttributeType newAttributeType(String name, Class clazz,
- boolean isNillable,int fieldLength,Object defaultValue, Object metaData) {
- return defaultInstance().createAttributeType(name, clazz, isNillable,fieldLength, defaultValue, metaData);
- }
- /**
- * Creates a new AttributeType with the addition of metadata like CRS.
- *
- * @param name name of the attribute type to be created
- * @param clazz Class that objects will validate against
- * @param isNillable If nulls are allowed (will force min=0)
- * @param restriction Filter restricting valid content
- * @param defaultValue Initial valid value for new Feature
- * @param metaData Additional information (example a CoordinateReferenceSystem for a Geometry)
- *
- * @return Created AttributeType
- */
- public static AttributeType newAttributeType(String name, Class clazz,
- boolean isNillable, Filter restriction,Object defaultValue, Object metaData) {
- return defaultInstance().createAttributeType(name, clazz, isNillable, restriction, defaultValue, metaData);
- }
-
- /**
- * Creates a new AttributeType.
- *
- * @param name name of the attribute type to be created
- * @param clazz Class that objects will validate against
- * @param isNillable If nulls are allowed (will force min=0)
- * @param restriction
- * @param defaultValue
- * @param metaData metaData Additional information (example a CoordinateReferenceSystem for a Geometry)
- * @param min minimum number of occurances for an array class
- * @param max maximum number of occurances for an array class
- * @return Created AttributeType
- */
- public static AttributeType newAttributeType(String name, Class clazz,
- boolean isNillable, Filter restriction,Object defaultValue, Object metaData, int min, int max ) {
- return defaultInstance().createAttributeType(name, clazz, isNillable, restriction, defaultValue, metaData, min, max);
- }
- /**
- * Creates a new AttributeType with the given name, class and nillable
- * values.
- *
- * @param name The name of the AttributeType to be created.
- * @param clazz The class that objects will validate against.
- * @param isNillable If nulls are allowed (will force min=0)
- *
- * @return A new AttributeType of name, clazz and isNillable.
- */
- public static AttributeType newAttributeType(String name, Class clazz,
- boolean isNillable,int fieldLength) {
- return defaultInstance().createAttributeType(name, clazz, isNillable,fieldLength);
- }
-
- /**
- * Creates a new AttributeType with the given name, class and nillable
- * values.
- *
- * @param name The name of the AttributeType to be created.
- * @param clazz The class that objects will validate against.
- * @param isNillable If nulls are allowed (will force min=0)
- *
- * @return A new AttributeType of name, clazz and isNillable.
- */
- public static AttributeType newAttributeType(String name, Class clazz,
- boolean isNillable) {
- return defaultInstance().createAttributeType(name, clazz, isNillable,Integer.MAX_VALUE);
- }
-
- /**
- * Convenience method to just specify name and class. Nulls are allowed as
- * attributes by default (isNillable = <code>true</code>).
- *
- * @param name The name of the AttributeType to be created.
- * @param clazz The class that objects will validate against.
- *
- * @return A new AttributeType of name and clazz.
- */
- public static AttributeType newAttributeType(String name, Class clazz) {
- return newAttributeType(name, clazz, true);
- }
-
- /**
- * Constucts a new AttributeType that accepts Features (specified by a
- * FeatureType)
- *
- * @param name The name of the AttributeType to be created.
- * @param type the FeatureType that features will validate agist
- * @param isNillable If nulls are allowed (will force min=0)
- *
- * @return A new AttributeType of name, type, and isNillable.
- */
- public static AttributeType newAttributeType(String name, FeatureType type,
- boolean isNillable) {
- return defaultInstance().createAttributeType(name, type, isNillable);
- }
-
- /**
- * Constucts a new AttributeType that accepts Feature (specified by a
- * FeatureType). Nulls are allowed as attributes by default (isNillable =
- * <code>true</code>).
- *
- * @param name The name of the AttributeType to be created.
- * @param type the FeatureType that features will validate agist
- *
- * @return A new AttributeType of name and type.
- */
- public static AttributeType newAttributeType(String name, FeatureType type) {
- return newAttributeType(name, type, true);
- }
-
- /**
- * Create an AttributeType with the given name, Class, nillability,
- * fieldLength, and provided defaultValue.
- *
- * @param name The name of the AttributeType to be created.
- * @param clazz The class that objects will validate against.
- * @param isNillable if nulls are allowed in the new type.
- *
- * @return the new AttributeType
- * @throws IllegalArgumentException If the field is not nillable, yet
- */
- protected abstract AttributeType createAttributeType(String name,
- Class clazz, boolean isNillable, int fieldLength, Object defaultValue);
-
- /**
- * Create an AttributeType with the given name, Class, nillability,
- * fieldLength, and provided defaultValue.
- *
- * @param name The name of the AttributeType to be created.
- * @param clazz The class that objects will validate against.
- * @param isNillable if nulls are allowed in the new type.
- * @param restriction Used to limit the valid values
- * @return the new AttributeType
- * @throws IllegalArgumentException If the field is not nillable, yet
- */
- protected abstract AttributeType createAttributeType(String name,
- Class clazz, boolean isNillable, Filter restriction, Object defaultValue, Object metadata);
-
- /**
- * Create an AttributeType with the given name, Class, nillability,
- * fieldLength, and provided defaultValue.
- *
- * @param name The name of the AttributeType to be created.
- * @param clazz The class that objects will validate against.
- * @param isNillable if nulls are allowed in the new type.
- * @param restriction Used to limit the valid values
- * @param min the minimum number of occurences of the attribute
- * @param max the maximum number of occurences of the attribute
- * @return the new AttributeType
- * @throws IllegalArgumentException If the field is not nillable, yet
- */
- protected abstract AttributeType createAttributeType(
- String name, Class type, boolean isNillable, Filter restriction, Object defaultValue,
- Object metaData, int min, int max
- );
-
- /**
- * Create an AttributeType with the given name, Class, nillability, and
- * fieldLength, defering the defaultValue to the type of Attribute.
- */
- protected abstract AttributeType createAttributeType(String name,
- Class clazz, boolean isNillable, int fieldLength);
-
- /**
- * Create a Feature AttributeType which holds the a Feature instance which
- * is of the given FeatureType or null if any arbitrary Feature can be held.
- *
- * @param name The name of the AttributeType to be created.
- * @param type The FeatureType that Features will validate against.
- * @param isNillable if nulls are allowed in the new type.
- *
- * @return the new AttributeType
- */
- protected abstract AttributeType createAttributeType(String name,
- FeatureType type, boolean isNillable);
-
- /**
- * Create a Feature AttributeType which holds the a Feature instance which
- * is of the given FeatureType or null if any arbitrary Feature can be held.
- *
- * @param name The name of the AttributeType to be created.
- * @param type The FeatureType that Features will validate against.
- * @param isNillable if nulls are allowed in the new type.
- * @param defaultValue default value, may be null if isNilable is true
- * @param metaData metadata for attribute type (such as CoordianteReferenceSystem)
- * @return the new AttributeType
- */
- protected abstract AttributeType createAttributeType( String name, Class type, boolean isNillable, int fieldLength, Object defaultValue, Object metaData );
-
- /**
- * Returns the implementation hints. The default implementation returns en empty map.
- */
- public Map getImplementationHints() {
- return Collections.EMPTY_MAP;
- }
-}
Deleted: geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/DefaultAttributeType.java
===================================================================
--- geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/DefaultAttributeType.java 2007-10-01 00:43:34 UTC (rev 27293)
+++ geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/DefaultAttributeType.java 2007-10-01 00:46:16 UTC (rev 27294)
@@ -1,419 +0,0 @@
-/*
- * GeoTools - OpenSource mapping toolkit
- * http://geotools.org
- * (C) 2002-2006, GeoTools Project Managment Committee (PMC)
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation;
- * version 2.1 of the License.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- */
-package org.geotools.feature;
-
-import java.lang.reflect.Array;
-import java.net.URI;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import org.geotools.feature.type.AttributeDescriptorImpl;
-import org.geotools.feature.type.AttributeTypeImpl;
-import org.geotools.util.Converters;
-
-import org.opengis.filter.Filter;
-import org.opengis.coverage.grid.GridCoverage;
-
-import com.vividsolutions.jts.geom.Geometry;
-
-
-/**
- * Simple, immutable class to store attributes. This class should be
- * sufficient for all simple (ie. non-schema) attribute implementations of
- * this interface.
- *
- * @author Rob Hranac, VFNY
- * @author Chris Holmes, TOPP
- * @author Ian Schneider
- * @source $URL$
- * @version $Id$
- */
-public class DefaultAttributeType extends AttributeDescriptorImpl
- implements AttributeType {
-
- /**
- * Constructor with name and type.
- *
- * @param name Name of this attribute.
- * @param type Class type of this attribute.
- * @param nillable If nulls are allowed for the attribute of this type.
- * @param min
- * @param max
- * @param defaultValue default value when none is suppled
- * @param f
- *
- * @task REVISIT: make this protected? I think it's only used by facotries
- * at this time.
- */
- protected DefaultAttributeType(String name, Class type, boolean nillable, int min, int max,
- Object defaultValue, Filter f) {
- this(createAttributeType(name, type != null ? type : Object.class, f),name,nillable,min,max,defaultValue);
- }
-
- protected DefaultAttributeType(org.opengis.feature.type.AttributeType type,String name,boolean nillable,int min,int max, Object defaultValue) {
- super(type,new Name((name == null) ? "" : name),min,max,nillable,defaultValue);
-
- if(defaultValue!=null && !type.getBinding().isAssignableFrom(defaultValue.getClass()))
- throw new IllegalArgumentException("Default value does not match type");
- }
-
- protected DefaultAttributeType(String name, Class type, boolean nillable, int min, int max,
- Object defaultValue) {
- this(name,type,nillable,min,max,defaultValue,Filter.INCLUDE);
- }
-
- protected DefaultAttributeType(String name, Class type, boolean nillable,
- Object defaultValue) {
- this(name, type, nillable, 1, 1, defaultValue,Filter.INCLUDE);
- }
-
- protected DefaultAttributeType(AttributeType copy) {
- super(copy.getType(),copy.getName(),copy.getMinOccurs(),copy.getMaxOccurs(),copy.isNillable(),copy.getDefaultValue());
- }
-
- public DefaultAttributeType(org.opengis.feature.type.AttributeType type, org.opengis.feature.type.Name name, int min, int max, boolean isNillable,Object defaultValue) {
- super(type, name, min, max, isNillable,defaultValue);
- }
-
- /**
- * Gets the name of this attribute.
- *
- * @return The name of this attribute.
- */
- public String getLocalName() {
- return getName().getLocalPart();
- }
-
- /**
- * Gets the type of this attribute. All attributes that are assigned to
- * this AttributeType must be an instance of this class. Subclasses are
- * allowed as well.
- *
- * @return The class that the attribute must match to be valid for this
- * AttributeType.
- */
- public Class getBinding() {
- return getType().getBinding();
- }
-
- /**
- * Return a safe Object copy.
- * <p>
- * Obtain a duplicate Object if the object is mutable, or the same Object
- * reference if it is immutable.
- * </p>
- * @return A duplicated Object if the type is mutable or the same Object
- * if it is immutable or null if the passed Object is null.
- * @throws IllegalAttributeException if the Object cannot be duplicated.
- *
- */
- public Object duplicate(Object src) throws IllegalAttributeException {
- //JD: this method really needs to be replaced with somethign better
-
- if (src == null) {
- return null;
- }
-
- //
- // The following are things I expect
- // Features will contain.
- //
- if (src instanceof String || src instanceof Integer
- || src instanceof Double || src instanceof Float
- || src instanceof Byte || src instanceof Boolean
- || src instanceof Short || src instanceof Long
- || src instanceof Character || src instanceof Number) {
- return src;
- }
-
- if (src instanceof Date) {
- return new Date( ((Date)src).getTime() );
- }
-
- if (src instanceof URL || src instanceof URI ) {
- return src; //immutable
- }
-
- if (src instanceof Object[]) {
- Object[] array = (Object[]) src;
- Object[] copy = new Object[array.length];
-
- for (int i = 0; i < array.length; i++) {
- copy[i] = duplicate(array[i]);
- }
-
- return copy;
- }
-
- if (src instanceof Geometry) {
- Geometry geometry = (Geometry) src;
-
- return geometry.clone();
- }
-
- if (src instanceof org.geotools.feature.Feature) {
- org.geotools.feature.Feature feature = (org.geotools.feature.Feature) src;
-
- return feature.getFeatureType().duplicate(feature);
- }
-
- //
- // We are now into diminishing returns
- // I don't expect Features to contain these often
- // (eveything is still nice and recursive)
- //
- Class type = src.getClass();
-
- if (type.isArray() && type.getComponentType().isPrimitive()) {
- int length = Array.getLength(src);
- Object copy = Array.newInstance(type.getComponentType(), length);
- System.arraycopy(src, 0, copy, 0, length);
-
- return copy;
- }
-
- if (type.isArray()) {
- int length = Array.getLength(src);
- Object copy = Array.newInstance(type.getComponentType(), length);
-
- for (int i = 0; i < length; i++) {
- Array.set(copy, i, duplicate(Array.get(src, i)));
- }
-
- return copy;
- }
-
- if (src instanceof List) {
- List list = (List) src;
- List copy = new ArrayList(list.size());
-
- for (Iterator i = list.iterator(); i.hasNext();) {
- copy.add(duplicate(i.next()));
- }
-
- return Collections.unmodifiableList(copy);
- }
-
- if (src instanceof Map) {
- Map map = (Map) src;
- Map copy = new HashMap(map.size());
-
- for (Iterator i = map.entrySet().iterator(); i.hasNext();) {
- Map.Entry entry = (Map.Entry) i.next();
- copy.put(entry.getKey(), duplicate(entry.getValue()));
- }
-
- return Collections.unmodifiableMap(copy);
- }
-
- if( src instanceof GridCoverage ){
- return src; // inmutable
- }
-
-
- //
- // I have lost hope and am returning the orgional reference
- // Please extend this to support additional classes.
- //
- // And good luck getting Cloneable to work
- throw new IllegalAttributeException("Do not know how to deep copy "
- + type.getName());
- }
-
- /**
- * Override of hashCode.
- *
- * @return hashCode for this object.
- */
- public int hashCode() {
- return super.hashCode() ^ type.hashCode();
- }
-
- /**
- * Override of equals.
- *
- * @param other the object to be tested for equality.
- *
- * @return whether other is equal to this attribute Type.
- */
- public boolean equals(Object other) {
- if (other == null) {
- return false;
- }
-
- if( !(other instanceof AttributeType) ){
- return false;
- }
-
- AttributeType att = (AttributeType) other;
-
- if (!super.equals(att)) {
- return false;
- }
-
- if (!getBinding().equals(att.getBinding())) {
- return false;
- }
-
- return true;
- }
-
- /**
- * Returns whether the attribute is a geometry.
- *
- * @return true if the attribute's type is a geometry.
- */
- public boolean isGeometry() {
- return Geometry.class.isAssignableFrom(getBinding());
- }
-
- /**
- * Gets a representation of this object as a string.
- *
- * @return A representation of this object as a string
- */
- public String toString() {
- String details = "name=" + name;
- details += (" , type=" + type);
- details += (" , nillable=" + isNillable()) + ", min=" + getMinOccurs()
- + ", max=" + getMaxOccurs();
-
- return "DefaultAttributeType [" + details + "]";
- }
-
- /**
- * Allows this AttributeType to convert an argument to its prefered storage
- * type. If no parsing is possible, returns the original value. If a parse
- * is attempted, yet fails (i.e. a poor decimal format) throw the
- * Exception. This is mostly for use internally in Features, but
- * implementors should simply follow the rules to be safe.
- *
- * @param value the object to attempt parsing of.
- *
- * @return <code>value</code> converted to the preferred storage of this
- * <code>AttributeType</code>. If no parsing was possible then
- * the same object is returned.
- *
- * @throws IllegalArgumentException if parsing is attempted and is
- * unsuccessful.
- */
- public final Object parse(Object value) throws IllegalArgumentException {
- if ( value == null || getBinding().isAssignableFrom(value.getClass()) ) {
- return value;
- }
-
- Object parsed = Converters.convert(value, getBinding());
- if( parsed == null ) {
- throw new IllegalArgumentException("Could not convert " + parsed + " to type " + getBinding().getName() );
- }
-
- return parsed;
- }
-
- /**
- * Whether the tested object passes the validity constraints of this
- * AttributeType. At a minimum it should be of the correct class
- * specified by {@link #getBinding()}, non-null if isNillable is
- * <tt>false</tt>, and a geometry if isGeometry is <tt>true</tt>. If The
- * object does not validate then an IllegalArgumentException reporting the
- * error in validation should be thrown.
- *
- * @param attribute The object to be tested for validity.
- *
- * @throws IllegalArgumentException if the object does not validate.
- */
- public void validate(Object attribute) throws IllegalArgumentException {
- if (attribute == null) {
- if (!isNillable()) {
- throw new IllegalArgumentException(getLocalName()
- + " is not nillable");
- }
-
- return;
- } else if (getBinding() != attribute.getClass() && !getBinding().isAssignableFrom(attribute.getClass())) {
- throw new IllegalArgumentException(attribute.getClass().getName()
- + " is not an acceptable class for " + getLocalName()
- + " as it is not assignable from " + type);
- }
- }
-
- public Object createDefaultValue() {
- return defaultValue;
- }
-
- /* (non-Javadoc)
- * @see org.geotools.feature.AttributeType#getRestriction()
- */
- public Filter getRestriction() {
- if ( !getType().getRestrictions().isEmpty() ) {
- return (Filter) getType().getRestrictions().iterator().next();
- }
-
- return null;
- }
-
- //
- // The following methods are called by org.geotools.feature.AttributeType
- // implementations while they transition to implement the geoapi AttributeDescriptor
- // interface.
- //
-
- /**
- * Method for geotools AttributeType implementations to create a geoapi
- * attribute type.
- * <p>
- * This method is usually called from the constructors of the old AttributeType
- * implememtnations.
- * </p>
- * @param name THe attribute type name.
- * @param binding The attribute type binding.
- * @param restriction Restriction on the attribute type.
- *
- * @return A geoapi attribute type.
- *
- * @since 2.5
- */
- public static org.opengis.feature.type.AttributeType createAttributeType(String name,Class binding,Filter restriction) {
- return new AttributeTypeImpl(
- new org.geotools.feature.Name(name),binding,false,false,
- restriction != null ? Collections.singletonList(restriction) : Collections.EMPTY_LIST,
- null,null);
- }
-
- public static String getLocalName( AttributeType type ) {
- return type.getName().getLocalPart();
- }
-
- public static Class getBinding( AttributeType type ) {
- return type.getType().getBinding();
- }
-
- public static Filter getRestriction( AttributeType type ) {
- if ( type.getType() != null && type.getType().getRestrictions() != null
- && !type.getType().getRestrictions().isEmpty() ) {
-
- return (Filter) type.getType().getRestrictions().iterator().next();
- }
-
- return null;
- }
-}
Deleted: geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/DefaultAttributeTypeFactory.java
===================================================================
--- geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/DefaultAttributeTypeFactory.java 2007-10-01 00:43:34 UTC (rev 27293)
+++ geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/DefaultAttributeTypeFactory.java 2007-10-01 00:46:16 UTC (rev 27294)
@@ -1,171 +0,0 @@
-/*
- * GeoTools - OpenSource mapping toolkit
- * http://geotools.org
- * (C) 2002-2006, GeoTools Project Managment Committee (PMC)
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation;
- * version 2.1 of the License.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- */
-package org.geotools.feature;
-
-import org.geotools.factory.CommonFactoryFinder;
-import org.geotools.feature.type.FeatureAttributeType;
-import org.geotools.feature.type.GeometricAttributeType;
-import org.geotools.feature.type.NumericAttributeType;
-import org.geotools.feature.type.TemporalAttributeType;
-import org.geotools.feature.type.TextualAttributeType;
-import org.geotools.filter.IllegalFilterException;
-import org.geotools.filter.LengthFunction;
-import org.opengis.filter.Filter;
-import org.opengis.filter.FilterFactory;
-import org.opengis.filter.expression.Expression;
-import org.opengis.referencing.crs.CoordinateReferenceSystem;
-
-import com.vividsolutions.jts.geom.Geometry;
-
-/**
- * Factory for creating DefaultAttributeTypes.
- *
- * @author Ian Schneider
- * @source $URL$
- * @version $Id$
- */
-public class DefaultAttributeTypeFactory extends AttributeTypeFactory {
- private FilterFactory ff;
- public DefaultAttributeTypeFactory(){
- this(CommonFactoryFinder.getFilterFactory(null));
- }
- public DefaultAttributeTypeFactory( FilterFactory factory ){
- ff = factory;
- }
- public void setFilterFactory( FilterFactory factory ){
- ff = factory;
- }
- /**
- * Create an AttributeType with the given name, Class, nillability, and
- * fieldLength meta-data. This method will itself call <code>
- * createAttributeType(String,Class,boolean,int,Object) </code> with null
- * as the default value. To use your own default value, use the above
- * method, providing your default value.
- *
- * @param name The name of the AttributeType to create.
- * @param clazz the class of the AttributeType to create.
- * @param isNillable whether the AttributeType should allow nulls.
- *
- * @return the newly created AttributeType
- */
- protected AttributeType createAttributeType(String name, Class clazz,
- boolean isNillable, int fieldLength) {
-
- return createAttributeType(name,clazz,isNillable,fieldLength,null);
- }
-
- /**
- * Creates the DefaultAttributeType.Feature
- *
- * @param name The name of the AttributeType to create.
- * @param type To use for validation.
- * @param isNillable whether the AttributeType should allow nulls.
- *
- * @return the newly created feature AttributeType.
- */
- protected AttributeType createAttributeType(String name, FeatureType type,
- boolean isNillable) {
-
- return new FeatureAttributeType(name, type, isNillable, minOccurs(isNillable) ,1);
- }
-
- protected Filter length(int fieldLength, String attributeXPath){
- if ( fieldLength < 0 ) {
- return null;
- }
- LengthFunction length = (LengthFunction)ff.function("LengthFunction",
- new Expression[]{ff.property(attributeXPath)});
- if( length == null ) {
- // TODO: Help Richard! ff.createFunctionExpression cannot find Length!
- return null;
- }
-
- Filter cf = null;
- try {
- //cf = ff.equals(length, ff.literal(fieldLength));
- cf = ff.lessOrEqual(length, ff.literal(fieldLength));
- } catch (IllegalFilterException e) {
- // TODO something
- }
- return cf == null ? Filter.EXCLUDE : cf;
- }
-
- /**
- * Implementation of AttributeType creation.
- */
- protected AttributeType createAttributeType(String name, Class clazz,
- boolean isNillable, int fieldLength, Object defaultValue) {
- Filter f = length( fieldLength, name );
-
- int minOccurs = minOccurs(isNillable);
- int maxOccurs = 1;
- if (Number.class.isAssignableFrom(clazz)) {
- return new NumericAttributeType(
- name, clazz, isNillable, minOccurs,maxOccurs,defaultValue,f);
- } else if (CharSequence.class.isAssignableFrom(clazz)) {
- return new TextualAttributeType(name,isNillable,minOccurs,maxOccurs,defaultValue,f);
- } else if (java.util.Date.class.isAssignableFrom(clazz)) {
- return new TemporalAttributeType(name,clazz,isNillable,minOccurs,maxOccurs,defaultValue,f);
- } else if (Geometry.class.isAssignableFrom( clazz )){
- return new GeometricAttributeType(name,clazz,isNillable,minOccurs,maxOccurs, defaultValue,null,f);
- }
- return new DefaultAttributeType(name, clazz, isNillable,minOccurs, maxOccurs,defaultValue, f);
- }
-
- /**
- * Implementation of AttributeType creation.
- */
- protected AttributeType createAttributeType(String name, Class clazz,
- boolean isNillable, Filter filter, Object defaultValue, Object metadata) {
-
- return createAttributeType( name, clazz, isNillable, filter, defaultValue, metadata, minOccurs( isNillable ), 1);
- }
- protected AttributeType createAttributeType(String name, Class clazz,
- boolean isNillable, Filter filter, Object defaultValue, Object metadata, int min, int max) {
-
- if (Number.class.isAssignableFrom(clazz)) {
- return new NumericAttributeType(
- name, clazz, isNillable,min,max,defaultValue, filter);
- } else if (CharSequence.class.isAssignableFrom(clazz)) {
- return new TextualAttributeType(name,isNillable,min,max,defaultValue,filter);
- } else if (java.util.Date.class.isAssignableFrom(clazz)) {
- //return new TemporalAttributeType(name,isNillable,min,max,defaultValue,filter);
- return new TemporalAttributeType(name,clazz,isNillable,min,max,defaultValue,filter);
- } else if (Geometry.class.isAssignableFrom( clazz )){
- if( metadata instanceof CoordinateReferenceSystem )
- return new GeometricAttributeType(name,clazz,isNillable,min,max,
- defaultValue,(CoordinateReferenceSystem) metadata,filter);
- else
- return new GeometricAttributeType(name,clazz,isNillable,min,max, defaultValue,null,filter);
- }
- return new DefaultAttributeType(name, clazz, isNillable,min,max,defaultValue,filter);
- }
-
- protected AttributeType createAttributeType( String name, Class clazz,
- boolean isNillable, int fieldLength, Object defaultValue,
- Object metaData ){
-
- if( Geometry.class.isAssignableFrom( clazz) && metaData instanceof CoordinateReferenceSystem ){
- Filter f = length(fieldLength,name);
- return new GeometricAttributeType(name,clazz,isNillable,minOccurs(isNillable),1, defaultValue, (CoordinateReferenceSystem) metaData,f);
- }
- return createAttributeType( name, clazz, isNillable, fieldLength, defaultValue );
- }
-
- private int minOccurs(boolean nillable) {
- return nillable ? 0 : 1;
- }
-}
Deleted: geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/DefaultFeature.java
===================================================================
--- geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/DefaultFeature.java 2007-10-01 00:43:34 UTC (rev 27293)
+++ geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/DefaultFeature.java 2007-10-01 00:46:16 UTC (rev 27294)
@@ -1,817 +0,0 @@
-/*
- * GeoTools - OpenSource mapping toolkit
- * http://geotools.org
- * (C) 2002-2006, GeoTools Project Managment Committee (PMC)
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation;
- * version 2.1 of the License.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- */
-package org.geotools.feature;
-
-import java.rmi.server.UID;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-import java.util.regex.Pattern;
-
-import org.geotools.feature.simple.SimpleFeatureImpl;
-import org.geotools.feature.type.DefaultFeatureTypeBuilder;
-import org.geotools.feature.type.GeometricAttributeType;
-import org.geotools.geometry.jts.ReferencedEnvelope;
-import org.opengis.feature.simple.SimpleFeatureType;
-import org.opengis.feature.type.AttributeDescriptor;
-import org.opengis.util.Cloneable;
-
-import com.vividsolutions.jts.geom.Envelope;
-import com.vividsolutions.jts.geom.Geometry;
-
-
-/**
- * Provides a more efficient feature representation for the flat and complex
- * features. This implementation actually not only enforces feature type
- * synchronization, it also enforces the use of its accessor methods to change
- * the state of internal object representations. In this case, the
- * implementation is trivial, since all allowed attribute objects (from the
- * feature type) are immutable.
- *
- * @author Chris Holmes, TOPP <br>
- * @author Rob Hranac, TOPP
- * @author Ian Schneider ARS-USDA
- *
- * @task TODO: look at synchronization (or locks as IanS thinks)
- * @task REVISIT: Right now we always validate, which means whenever a Feature
- * is created or a new value set then an operation must be performed.
- * One thing we should consider is to allow a Feature to turn off its
- * its validation - which would likely improve performance with large
- * datasets. If you are reading from a database, with a FeatureType you
- * got from the database, it is probably a reasonable assumption that
- * the Features contained in it will properly validate. I am not sure
- * if this should with a switch in DefaultFeature, or perhaps an
- * interface that says if it is validating or not, or maybe even an
- * option in Feature. But it would be a nice option to have - if
- * datastore implementors could at least create their features without
- * validating (though probably should return Features that will check
- * for validity if someone else tries to change them).
- * @source $URL$
- */
-public class DefaultFeature extends SimpleFeatureImpl
- implements SimpleFeature, Cloneable {
-// /** The unique id of this feature */
-// protected String featureId;
-//
-// /** Flat feature type schema for this feature. */
-// private final DefaultFeatureType schema;
-//
-// /** Attributes for the feature. */
-// private Object[] attributes;
-//
-// /** The bounds of this feature. */
-// private Envelope bounds;
-
- /** The collection that this Feature is a member of */
- private FeatureCollection parent;
-
-// private static final Pattern NON_WORD_PATTERN = Pattern.compile(":");
-
- /**
- * Creates a new instance of flat feature, which must take a flat feature
- * type schema and all attributes as arguments.
- *
- * @param schema Feature type schema for this flat feature.
- * @param attributes Initial attributes for this feature.
- * @param featureID The unique ID for this feature.
- *
- * @throws IllegalAttributeException Attribtues do not conform to feature
- * type schema.
- * @throws NullPointerException if schema is null.
- */
- protected DefaultFeature(DefaultFeatureType schema, Object[] attributes,
- String featureID) throws IllegalAttributeException, NullPointerException {
- //super( Arrays.asList(attributes), schema, featureID );
- super(wrapValues(attributes,schema), schema, featureID );
-
- if (schema == null) {
- throw new NullPointerException("schema");
- }
-
-// this.schema = schema;
-// this.featureId = (featureID == null) ? defaultID() : featureID;
-// this.attributes = new Object[schema.getAttributeCount()];
-//
-// setAttributes(attributes);
- }
-
-
-/**
- * wraps an array of raw values in attributes.
- *
- */
- static List wrapValues( Object[] values, DefaultFeatureType schema ) {
- ArrayList atts = new ArrayList(values.length);
- for ( int i = 0; i < values.length; i++ ) {
- atts.add(
- new AttributeImpl( values[i], schema.getAttribute(i),null) {
- public void set(Object newValue) throws IllegalArgumentException, IllegalStateException {
- newValue = parse(newValue);
- value = newValue;
- }
- }
- );
- }
-
- return atts;
- }
-
- /**
- * Creates a new instance of flat feature, which must take a flat feature
- * type schema and all attributes as arguments.
- *
- * @param schema Feature type schema for this flat feature.
- * @param attributes Initial attributes for this feature.
- *
- * @throws IllegalAttributeException Attribtues do not conform to feature
- * type schema.
- *
- * @task REVISIT: should we allow this? Force users to explicitly set
- * featureID to null?
- */
- protected DefaultFeature(DefaultFeatureType schema, Object[] attributes)
- throws IllegalAttributeException {
- this(schema, attributes, null);
- }
-
- public DefaultFeature(List/*<Attribute>*/ attributes,DefaultFeatureType schema, String id ) {
- super( attributes, schema, id );
- }
- /**
- * Creates an ID from a hashcode.
- *
- * @return an id for the feature.
- */
- String defaultID() {
- // According to GML and XML schema standards, FID is a XML ID
- // (http://www.w3.org/TR/xmlschema-2/#ID), whose acceptable values are those that match an
- // NCNAME production (http://www.w3.org/TR/1999/REC-xml-names-19990114/#NT-NCName):
- // NCName ::= (Letter | '_') (NCNameChar)* /* An XML Name, minus the ":" */
- // NCNameChar ::= Letter | Digit | '.' | '-' | '_' | CombiningChar | Extender
- // We have to fix the generated UID replacing all non word chars with an _ (it seems
- // they area all ":")
-// return "fid-" + NON_WORD_PATTERN.matcher(new UID().toString()).replaceAll("_");
- // optimization, since the UID toString uses only ":" and converts long and integers
- // to strings for the rest, so the only non word character is really ":"
- return "fid-" + new UID().toString().replace(':', '_');
- }
-
- /**
- * Gets a reference to the feature type schema for this feature.
- *
- * @return A copy of this feature's metadata in the form of a feature type
- * schema.
- */
- public FeatureType getFeatureType() {
- return (FeatureType) getType();
- }
-
- /**
- * Gets the unique indentification string of this Feature.
- *
- * @return The unique id.
- */
-// public String getID() {
-// return featureId;
-// }
-
- /**
- * Copy all the attributes of this Feature into the given array. If the
- * argument array is null, a new one will be created. Gets all attributes
- * from this feature, returned as a complex object array. This array
- * comes with no metadata, so to interpret this collection the caller
- * class should ask for the schema as well.
- *
- * @param array The array to copy the attributes into.
- *
- * @return The array passed in, or a new one if null.
- */
- public Object[] getAttributes(Object[] array) {
- Object[] retArray;
-
- List values = getAttributes();
- if (array == null) {
- //retArray = new Object[attributes.length];
- retArray = new Object[values.size()];
- } else {
- retArray = array;
- }
-
- //System.arraycopy(attributes, 0, retArray, 0, attributes.length);
- //return retArray;
- return values.toArray( retArray );
- }
-
- /**
- * Gets an attribute for this feature at the location specified by xPath.
- *
- * @param xPath XPath representation of attribute location.
- *
- * @return Attribute.
- */
-// public Object getAttribute(String xPath) {
-//
-// int idx = schema.find(xPath);
-//
-// if (idx == -1) {
-// return null;
-// }
-//
-// return attributes[idx];
-// }
-
- /**
- * Gets an attribute by the given zero-based index.
- *
- * @param index the position of the attribute to retrieve.
- *
- * @return The attribute at the given index.
- */
-// public Object getAttribute(int index) {
-// return attributes[index];
-// }
-
- /**
- * Sets the attribute at position to val.
- *
- * @param position the index of the attribute to set.
- * @param val the new value to give the attribute at position.
- *
- * @throws IllegalAttributeException if the passed in val does not validate
- * against the AttributeType at that position.
- */
- public void setAttribute(int position, Object val) {
- try {
- super.setAttribute(position, val);
- }
- catch( IndexOutOfBoundsException ioobe ) {
- throw ioobe;
- }
- catch( Exception e ) {
- throw (IllegalAttributeException) new IllegalAttributeException(e.getLocalizedMessage()).initCause(e);
- }
-// AttributeType type = schema.getAttributeType(position);
-//
-// try {
-// if ((val == null) && !type.isNillable()) val = type.createDefaultValue();
-// Object parsed = type.parse(val);
-// type.validate(parsed);
-// setAttributeValue(position, parsed);
-// } catch (IllegalArgumentException iae) {
-// throw new IllegalAttributeException(type, val, iae);
-// }
- }
-
- /**
- * Sets the attribute value at a given position, performing no parsing or
- * validation. This is so subclasses can have access to setting the array,
- * without opening it up completely.
- *
- * @param position the index of the attribute to set.
- * @param val the new value to give the attribute at position.
- */
-// protected void setAttributeValue(int position, Object val) {
-// attributes[position] = val;
-// }
-
- /**
- * Sets all attributes for this feature, passed as an array. All
- * attributes are checked for validity before adding.
- *
- * @param attributes All feature attributes.
- *
- * @throws IllegalAttributeException Passed attributes do not match feature
- * type.
- */
- public void setAttributes(Object[] attributes)
- throws IllegalAttributeException {
- try {
- super.setAttributes(attributes);
- }
- catch( Exception e ) {
- throw (IllegalAttributeException) new IllegalAttributeException(e.getLocalizedMessage()).initCause(e);
- }
-//
-//
-// // the passed in attributes were null, lets make that a null array
-// Object[] newAtts = attributes;
-//
-// if (attributes == null) {
-// newAtts = new Object[this.attributes.length];
-// }
-//
-// if (newAtts.length != this.attributes.length) {
-// throw new IllegalAttributeException(
-// "Wrong number of attributes expected "
-// + schema.getAttributeCount() + " got " + newAtts.length);
-// }
-//
-// for (int i = 0, ii = newAtts.length; i < ii; i++) {
-// setAttribute(i, newAtts[i]);
-// }
- }
-
- /**
- * Sets a single attribute for this feature, passed as a complex object. If
- * the attribute does not exist or the object does not conform to the
- * internal feature type, an exception is thrown.
- *
- * @param xPath XPath representation of attribute location.
- * @param attribute Feature attribute to set.
- *
- * @throws IllegalAttributeException Passed attribute does not match
- * feature type
- */
- public void setAttribute(String xPath, Object attribute)
- throws IllegalAttributeException {
- try {
- super.setAttribute(xPath, attribute);
- }
- catch( Exception e ) {
- throw (IllegalAttributeException) new IllegalAttributeException(e.getLocalizedMessage()).initCause(e);
- }
- // int idx = schema.find(xPath);
-//
-// if (idx < 0) {
-// throw new IllegalAttributeException("No attribute named " + xPath);
-// }
-//
-// setAttribute(idx, attribute);
- }
-
- /**
- * Gets the geometry for this feature.
- *
- * @return Geometry for this feature.
- * @deprecated use {@link #getDefaultGeometry()}.
- */
- public Geometry getDefaultGeometry() {
- return (Geometry) super.getDefaultGeometry();
-// int idx = schema.defaultGeomIdx;
-//
-// if (idx == -1) {
-// return null;
-// }
-//
-// return (Geometry) attributes[idx];
- }
-
- /**
- * Modifies the geometry.
- *
- * @param geometry All feature attributes.
- *
- * @throws IllegalAttributeException if the feature does not have a
- * geometry.
- * @deprecated use {@link #setDefaultGeometry(Geometry)}.
- */
- public void setDefaultGeometry(Geometry geometry) throws IllegalAttributeException {
- try {
- super.setDefaultGeometry(geometry);
- }
- catch( Exception e ) {
- throw (IllegalAttributeException) new IllegalAttributeException(e.getLocalizedMessage()).initCause(e);
- }
-
-
-// int idx = schema.defaultGeomIdx;
-//
-// if (idx < 0) {
-// throw new IllegalAttributeException(
-// "Feature does not have geometry");
-// }
-//
-// attributes[idx] = geometry;
-// bounds = null;
- }
-
- /**
- * Get the number of attributes this feature has. This is simply a
- * convenience method for calling
- * getFeatureType().getNumberOfAttributes();
- *
- * @return The total number of attributes this Feature contains.
- */
- public int getNumberOfAttributes() {
- return getAttributeCount();
- //return attributes.length;
- }
-
- /**
- * Get the total bounds of this feature which is calculated by doing a
- * union of the bounds of each geometry this feature is associated with.
- *
- * @return An Envelope containing the total bounds of this Feature.
- *
- * @task REVISIT: what to return if there are no geometries in the feature?
- * For now we'll return a null envelope, make this part of
- * interface? (IanS - by OGC standards, all Feature must have geom)
- */
- public ReferencedEnvelope getBounds() {
- return (ReferencedEnvelope) super.getBounds();
-// if (bounds == null) {
-// bounds = new Envelope();
-//
-// for (int i = 0, n = schema.getAttributeCount(); i < n; i++) {
-// if (schema.getAttributeType(i) instanceof GeometryAttributeType ) {
-// Geometry g = (Geometry) attributes[i];
-//
-// // IanS - check for null geometry!
-// if (g == null) {
-// continue;
-// }
-//
-// Envelope e = g.getEnvelopeInternal();
-//
-// // IanS
-// // as of JTS 1.3, expandToInclude does not check to see if
-// // Envelope is "null", and simply adds the flagged values.
-// // This ensures that this behavior does not occur.
-// if (!e.isNull()) {
-// bounds.expandToInclude(e);
-// }
-// }
-// }
-// }
-//
-// // lets be defensive
-// if (schema.getPrimaryGeometry() != null) {
-// return new ReferencedEnvelope(bounds,schema.getPrimaryGeometry().getCoordinateSystem());
-// }
-// return new ReferencedEnvelope(bounds,null);
- }
-
- /**
- * Creates an exact copy of this feature.
- *
- * @return A default feature.
- *
- * @throws RuntimeException DOCUMENT ME!
- */
- public Object clone() {
- try {
- DefaultFeature clone = (DefaultFeature) super.clone();
- clone.setValue(getValue());
-
-// for (int i = 0; i < values.size(); i++) {
-// try {
-// clone.setAttribute(i
-// } catch (IllegalAttributeException e1) {
-// throw new RuntimeException("The impossible has happened", e1);
-// }
-// }
-
- return clone;
- } catch (CloneNotSupportedException e) {
- throw new RuntimeException("The impossible has happened", e);
- }
- }
-
- /**
- * Returns a string representation of this feature.
- *
- * @return A representation of this feature as a string.
- */
- public String toString() {
- String retString = "Feature[ id=" + getID() + " , ";
- FeatureType featType = getFeatureType();
-
- List attributes = getValue();
- for (int i = 0, n = attributes.size(); i < n; i++) {
- retString += (featType.getAttributeType(i).getLocalName() + "=");
- retString += attributes.get(i);
-
- if ((i + 1) < n) {
- retString += " , ";
- }
- }
-
- return retString += " ]";
- }
-
- /**
- * returns a unique code for this feature
- *
- * @return A unique int
- */
-// public int hashCode() {
-// return featureId.hashCode() * schema.hashCode();
-// }
-
- /**
- * override of equals. Returns if the passed in object is equal to this.
- *
- * @param obj the Object to test for equality.
- *
- * @return <code>true</code> if the object is equal, <code>false</code>
- * otherwise.
- */
- public boolean equals(Object obj) {
- if (obj == null) {
- return false;
- }
-
- if (obj == this) {
- return true;
- }
-
- if (!(obj instanceof Feature)) {
- return false;
- }
-
- return super.equals( obj );
-// Feature feat = (Feature) obj;
-//
-// if (!feat.getFeatureType().equals(schema)) {
-// return false;
-// }
-//
-// // this check shouldn't exist, by contract,
-// //all features should have an ID.
-// if (featureId == null) {
-// if (feat.getID() != null) {
-// return false;
-// }
-// }
-//
-// if (!featureId.equals(feat.getID())) {
-// return false;
-// }
-//
-// for (int i = 0, ii = attributes.length; i < ii; i++) {
-// Object otherAtt = feat.getAttribute(i);
-//
-// if (attributes[i] == null) {
-// if (otherAtt != null) {
-// return false;
-// }
-// } else {
-// if (!attributes[i].equals(otherAtt)) {
-// if (attributes[i] instanceof Geometry
-// && otherAtt instanceof Geometry) {
-// // we need to special case Geometry
-// // as JTS is broken
-// // Geometry.equals( Object ) and Geometry.equals( Geometry )
-// // are different
-// // (We should fold this knowledge into AttributeType...)
-// //
-// if (!((Geometry) attributes[i]).equals(
-// (Geometry) otherAtt)) {
-// return false;
-// }
-// } else {
-// return false;
-// }
-// }
-// }
-// }
-//
-// return true;
- }
-
- /**
- * Gets the feature collection this feature is stored in.
- *
- * @return the collection that is the parent of this feature.
- */
- public FeatureCollection getParent() {
- return parent;
- }
-
- /**
- * Sets the parent collection this feature is stored in, if it is not
- * already set. If it is set then this method does nothing.
- *
- * @param collection the collection to be set as parent.
- */
- public void setParent(FeatureCollection collection) {
- if (parent == null) {
- parent = collection;
- }
- }
-
- public Feature toComplex() {
- try {
- return new ComplexWrapper(this);
- } catch (IllegalAttributeException iae) {
- throw new RuntimeException("the impossible has happened: ", iae);
- }
- }
-
- /**
- * This class will wrap a DefaultFeature (which is a {@link SimpleFeature}
- * into a Feature with multiplicity - which is to say it will always
- * return a List of its attributes when they are requested. These will
- * always be singleton Lists, since the min/max of attributes in a
- * DefaultFeature is 1. But this is important so that clients can deal
- * with all Features in the same way - always expecting Lists.
- *
- * @author Chris Holmes, Fulbright
- */
- static final class ComplexWrapper extends DefaultFeature
- {
- /**
- * Private constructor to wrap the attributes in list. Could consider
- * making this public, but for now it seems better to keep it private
- * since we do no check to make sure tha attribute array isn't already
- * complex - and thus if it was we would wrap it in Lists again.
- *
- * @param fType DOCUMENT ME!
- * @param atts DOCUMENT ME!
- * @param fid DOCUMENT ME!
- *
- * @throws IllegalAttributeException DOCUMENT ME!
- */
- private ComplexWrapper(DefaultFeatureType fType, Object[] atts,
- String fid) throws IllegalAttributeException {
- super(wrapValuesComplex(atts,makeComplex(fType)), makeComplex(fType), fid );
- }
-
- public ComplexWrapper(DefaultFeatureType fType, Object[] atts)
- throws IllegalAttributeException {
- this(fType, atts, null);
- }
-
- //This could be problematic, not sure if all SimpleFeatures will have
- //DefaultFeatureTypes.
- public ComplexWrapper(SimpleFeature feature)
- throws IllegalAttributeException {
- this((DefaultFeatureType) feature.getFeatureType(),
- feature.getAttributes(null), feature.getID());
- }
-
- /**
- * Sets the attribute Object at the given index. As this is a complex
- * feature - one with multiplicity - then all attributes passed in
- * must be Lists. Since this is just a wrapped SimpleFeature, the
- * List passed in will only ever be a singleton, but we must abide by
- * the contract of a ComplexFeature.
- *
- * @param index The attribute to set.
- * @param value A Singleton List of the attribute to set.
- *
- * @throws IllegalAttributeException If the value is not a singleton
- * List.
- *
- * @task REVISIT: Make List explicit in Java 1.5
- * @task REVISIT: We could consider accepting none list objects, and
- * justify it as part of the parse method - that is to say that
- * most calls to setAttribute will turn the Object into the
- * proper form, so why not here? For a true Complex Feature this
- * has implications of letting people blow away their multiple
- * attributes, but for here there are no such dangers. -ch
- */
- public void setAttribute(int index, Object value) {
-
- checkList(value);
-
- List valList = (List) value;
- int listSize = valList.size();
-
- if (listSize == 0) {
- super.setAttribute(index, wrapInList(null));
- } else {
- AttributeType type = super.getFeatureType().getAttributeType(index);
- Object val = valList.get(0);
-
- try {
- Object parsed = type.parse(val);
- type.validate(parsed);
- super.setAttribute(index, wrapInList(parsed));
- } catch (IllegalArgumentException iae) {
- throw new IllegalAttributeException(type, val, iae);
- }
- }
- }
-
- private void checkList(Object value) throws IllegalAttributeException {
- if (value instanceof List) {
- List valList = (List) value;
- int listSize = valList.size();
-
- if (listSize > 1) {
- String errMsg = "The attribute: " + valList + " has more "
- + "attributes (" + listSize
- + ") than is allowed by an "
- + " attributeType in a Simple Feature (1)";
- throw new IllegalAttributeException(errMsg);
- }
- } else {
- String errMsg = "All objects set in a ComplexFeature must be "
- + "Lists, to account for multiplicity";
- throw new IllegalAttributeException(errMsg);
- }
- }
-
- /**
- * Sets the attribute at the given xPath. Note that right now this
- * just does the name, and will fail on anything other than the name.
- *
- * @param xPath The name of the attribute to Set.
- * @param attribute The value to set - must be a List, for this Complex
- * Feature.
- *
- * @throws IllegalAttributeException DOCUMENT ME!
- *
- * @task TODO: Revisit xPath stuff - get it working or do external
- * implementation.
- */
- public void setAttribute(String xPath, Object attribute) {
-
- int idx = super.getFeatureType().find(xPath);
-
- if (idx < 0) {
- throw new IllegalAttributeException("No attribute named "
- + xPath);
- }
-
- setAttribute(idx, attribute);
-
- }
- /**
- * Takes the raw arrayof values provided and returns them as a bunch
- * of Singleton Lists.
- * @param values
- * @param schema
- * @return
- */
- static List wrapValuesComplex( Object[] values, DefaultFeatureType schema ) {
- ArrayList atts = new ArrayList(values.length);
- for ( int i = 0; i < values.length; i++ ) {
- atts.add(
- new AttributeImpl( wrapInList(values[i]), schema.getAttribute(i),null) {
- public void setValue(Object newValue) throws IllegalArgumentException, IllegalStateException {
- newValue = parse(newValue);
- value = newValue;
- }
-
- protected Object parse(Object value) throws IllegalArgumentException {
- return value;
- }
- }
- );
- }
- return atts;
- }
-
- protected static List wrapInList(Object attribute) {
- return java.util.Collections.singletonList(attribute);
- }
-
- protected static Object[] wrapInList(Object[] attributes,
- int defaultSize) {
- Object[] retArray = attributes;
-
- if (attributes == null) {
- retArray = new Object[defaultSize];
- } else {
- retArray = attributes;
- }
-
- for (int i = 0; i < attributes.length; i++) {
- retArray[i] = wrapInList(attributes[i]);
- }
-
- return retArray;
- }
-
- protected static DefaultFeatureType makeComplex( DefaultFeatureType original ) {
-
- DefaultFeatureTypeBuilder builder = new DefaultFeatureTypeBuilder() {
- protected AttributeDescriptor createAttributeDescriptor(String name, final Class binding) {
- return new DefaultAttributeType( name, List.class, true, 1,1, null, null ){
- public void validate(Object attribute) throws IllegalArgumentException {
- if ( !binding.isAssignableFrom(attribute.getClass())) {
- throw new IllegalArgumentException();
- }
- }
-
- };
- };
- };
- builder.setName( original.getName().getLocalPart() );
- builder.setNamespaceURI(original.getName().getNamespaceURI());
-
- for ( int i = 0; i < original.getAttributeCount(); i++ ) {
- AttributeType attributeType = original.getAttributeType(i);
- builder.add( attributeType.getLocalName(), attributeType.getBinding() );
- }
-
- return (DefaultFeatureType) builder.buildFeatureType();
- }
- }
-}
Deleted: geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/DefaultFeatureBuilder.java
===================================================================
--- geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/DefaultFeatureBuilder.java 2007-10-01 00:43:34 UTC (rev 27293)
+++ geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/DefaultFeatureBuilder.java 2007-10-01 00:46:16 UTC (rev 27294)
@@ -1,10 +0,0 @@
-package org.geotools.feature;
-
-import org.geotools.feature.simple.SimpleFeatureBuilder;
-
-public class DefaultFeatureBuilder extends SimpleFeatureBuilder {
-
- public DefaultFeatureBuilder() {
- super( new DefaultFeatureFactory() );
- }
-}
Deleted: geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/DefaultFeatureFactory.java
===================================================================
--- geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/DefaultFeatureFactory.java 2007-10-01 00:43:34 UTC (rev 27293)
+++ geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/DefaultFeatureFactory.java 2007-10-01 00:46:16 UTC (rev 27294)
@@ -1,28 +0,0 @@
-package org.geotools.feature;
-
-import java.util.List;
-
-import org.opengis.feature.simple.SimpleFeature;
-
-import org.opengis.feature.simple.SimpleFeatureType;
-
-/**
- * An extension of {@link SimpleFeatureFactoryImpl} which creates
- * {@link DefaultFeature} instances.
- *
- * @author Justin Deoliveira, The Open Planning Project, jdeolive@...
- *
- * @deprecated use {@link SimpleFeatureFactory}, this class is only provided to
- * maintain backwards compatability for transition to geoapi feature model and
- * will be removed in subsequent versions.
- *
- * @since 2.5
- *
- */
-public class DefaultFeatureFactory extends FeatureFactoryImpl {
-
- public SimpleFeature createSimpleFeature(List properties, SimpleFeatureType type, String id) {
- return new DefaultFeature( properties, (DefaultFeatureType) type, id );
- }
-
-}
Deleted: geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/DefaultFeatureType.java
===================================================================
--- geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/DefaultFeatureType.java 2007-10-01 00:43:34 UTC (rev 27293)
+++ geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/DefaultFeatureType.java 2007-10-01 00:46:16 UTC (rev 27294)
@@ -1,578 +0,0 @@
-/*
- * GeoTools - OpenSource mapping toolkit
- * http://geotools.org
- * (C) 2002-2006, GeoTools Project Managment Committee (PMC)
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation;
- * version 2.1 of the License.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- */
-package org.geotools.feature;
-
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.List;
-
-import org.geotools.feature.simple.SimpleFeatureTypeImpl;
-import org.geotools.resources.Utilities;
-import org.opengis.feature.type.AttributeDescriptor;
-import org.opengis.feature.type.GeometryDescriptor;
-import org.opengis.util.InternationalString;
-
-/**
- * A basic implementation of FeatureType.
- *
- * @author Ian Schneider
- * @source $URL$
- * @version $Id$
- */
-public class DefaultFeatureType extends SimpleFeatureTypeImpl implements FeatureType {
-
- /** The name of this FeatureType. */
- //private final String typeName;
-
- /** The namespace to uniquely identify this FeatureType. */
- //private final URI namespace;
-
- /** The array of types that this FeatureType can have as attributes. */
- //private final AttributeType[] types;
-
- /** The FeatureTypes this is descended from. */
- //private final FeatureType[] ancestors;
-
- /** The default geometry AttributeType. */
- //private final GeometryAttributeType defaultGeom;
-
- private final int hashCode;
-
- /** The position of the default Geometry
- * Leave as package protected for use by DefaultFeature
- */
- //final int defaultGeomIdx;
-
- /** An feature type with no attributes */
- public static final FeatureType EMPTY = new DefaultFeatureType();
-
- /** attname:string -> position:int */
- //private final java.util.Map attLookup;
-
- private final static URI toURI( String namespace ) throws SchemaException {
- try {
- return new URI( namespace );
- } catch (URISyntaxException badNamespace ) {
- throw new SchemaException( badNamespace );
- }
- }
- public DefaultFeatureType(String typeName, String namespace,
- Collection types, Collection superTypes, GeometryAttributeType defaultGeom)
- throws SchemaException, NullPointerException {
- this( typeName, toURI(namespace ), types, superTypes, defaultGeom );
- }
- public DefaultFeatureType(String typeName, URI namespace,
- Collection types, Collection superTypes, GeometryAttributeType defaultGeom)
- throws NullPointerException {
- this( namespace != null ? new Name( namespace.toString(), typeName ) : new Name( FeatureTypes.DEFAULT_NAMESPACE.toString(), typeName ),
- types, superTypes, defaultGeom );
- }
- private static final <T> List<T> toList( Collection<T> collection ){
- if( collection == null ){
- return new ArrayList<T>();
- }
- else {
- return new ArrayList<T>(collection);
- }
- }
- private static final FeatureType toFeatureType( Collection types ){
- if( types == null || types.isEmpty() ){
- return null;
- }
- if ( types.size() > 1 ) {
- throw new IllegalArgumentException("May only specify a single parent");
- }
-
- return (FeatureType) types.iterator().next();
-
- }
- /**
- * Constructs a new DefaultFeatureType.
- *
- * <p>
- * Attributes from the superTypes will be copied to the list of attributes
- * for this feature type.
- *
- * @param typeName The name to give this FeatureType.
- * @param namespace The namespace of the new FeatureType.
- * @param types The attributeTypes to use for validation.
- * @param superTypes The ancestors of this FeatureType.
- * @param defaultGeom The attributeType to set as the defaultGeometry.
- *
- * @throws SchemaException For problems making the FeatureType.
- * @throws NullPointerException If typeName is null.
- */
- public DefaultFeatureType( org.opengis.feature.type.Name name,
- Collection types, Collection superTypes, GeometryAttributeType defaultGeom)
- throws NullPointerException {
- super( name, (List)types, defaultGeom, false, null, toFeatureType(superTypes), null );
-
- if (name == null) {
- throw new NullPointerException("Name required");
- }
-
-// this.typeName = typeName;
-// this.namespace = namespace == null ? FeatureTypes.DEFAULT_NAMESPACE : namespace;
-// this.ancestors = toFeatureTypes( superTypes );
-//
-// Collection attributes = new java.util.ArrayList( types );
-// for (int i = 0, ii = ancestors.length; i < ii; i++) {
-// FeatureType ancestor = ancestors[i];
-// for (int j = 0, jj = ancestor.getAttributeCount(); j < jj; j++) {
-// attributes.add(ancestor.getAttributeType(j));
-// }
-// }
-// if(attributes.size()!=0)
-// this.types = (AttributeType[]) attributes.toArray(new AttributeType[attributes.size()]);
-// else
-// this.types = new AttributeType[0];
-//
-// this.defaultGeom = defaultGeom;
-
- //attLookup = new java.util.HashMap(this.types.length);
- //attLookup = new java.util.HashMap(types.size());
- //for (int i = 0, ii = this.types.length; i < ii; i++) {
-// int i = 0;
-// for( Iterator t = types.iterator(); t.hasNext(); ) {
-// AttributeType type = (AttributeType) t.next();
-// //attLookup.put(this.types[i].getLocalName(),new Integer(i));
-// attLookup.put(type.getLocalName(),new Integer(i++));
-// }
-
- //this.defaultGeomIdx = find(defaultGeom);
-
- hashCode = computeHash();
- }
-
-
- public DefaultFeatureType(
- org.opengis.feature.type.Name name, List schema, GeometryDescriptor defaultGeometry,
- boolean isAbstract, List restrictions,org.opengis.feature.type.AttributeType superType,
- InternationalString description) {
-
- super(name, schema, defaultGeometry,isAbstract, restrictions,superType, description);
-
- hashCode = computeHash();
- }
- /**
- * Builds an empty feature type, useful for testing
- * @throws SchemaException
- */
- private DefaultFeatureType() {
- this("emptyFeatreType", FeatureTypes.DEFAULT_NAMESPACE, Collections.EMPTY_LIST, Collections.EMPTY_LIST, null );
-// this.typeName = "emptyFeatureType";
-// namespace = FeatureTypes.DEFAULT_NAMESPACE;
-// this.types = new AttributeType[0];
-// this.ancestors = new FeatureType[0];
-// this.defaultGeomIdx = -1;
-// this.defaultGeom = null;
-// hashCode = computeHash();
-// attLookup = java.util.Collections.EMPTY_MAP;
- }
-
- /*
- * additional initialization shared among constructors.
- */
- private void init() {
-
- }
-
- /**
- * Creates a new feature, with a generated unique featureID. This is less
- * than ideal, as a FeatureID should be persistant over time, generally
- * created by a datasource. This method is more for testing that doesn't
- * need featureID.
- *
- * @param attributes the array of attribute values
- *
- * @return The created feature with this as its feature type.
- *
- * @throws IllegalAttributeException if this FeatureType does not validate
- * the attributes.
- */
- public Feature create(Object[] attributes) throws IllegalAttributeException {
- return create(attributes, null);
- }
-
- /**
- * Creates a new feature, with the proper featureID, using this
- * FeatureType.
- *
- * @param attributes the array of attribute values.
- * @param featureID the feature ID.
- *
- * @return the created feature.
- *
- * @throws IllegalAttributeException if this FeatureType does not validate
- * the attributes.
- */
- public Feature create(Object[] attributes, String featureID)
- throws IllegalAttributeException {
- if ( attributes == null && getAttributeCount() != 0 ) {
- throw new IllegalAttributeException("attributes null");
- }
-
- try {
- DefaultFeatureBuilder builder = new DefaultFeatureBuilder( this );
- builder.add( attributes );
-
- return (Feature) builder.buildFeature(featureID);
- }
- catch( Exception e ) {
- throw (IllegalAttributeException) new IllegalAttributeException("illegal attribute").initCause(e);
- }
-
- //return new DefaultFeature(this, attributes, featureID);
- }
-
- public Feature duplicate(Feature original) throws IllegalAttributeException{
- if( original == null ) return null;
- FeatureType featureType = original.getFeatureType();
- if (!featureType.equals(this)) {
- throw new IllegalAttributeException("Feature type " + featureType
- + " does not match " + this);
- }
-
- try {
- DefaultFeatureBuilder builder = new DefaultFeatureBuilder();
- builder.init( original );
-
- return (Feature) builder.buildFeature(original.getID());
- }
- catch( Exception e ) {
- throw (IllegalAttributeException) new IllegalAttributeException("illegal attribute").initCause(e);
- }
-
-// String id = original.getID();
-// int numAtts = featureType.getAttributeCount();
-// Object attributes[] = new Object[numAtts];
-// for (int i = 0; i < numAtts; i++) {
-// AttributeType curAttType = getAttributeType(i);
-// attributes[i] = curAttType.duplicate(original.getAttribute(i));
-// }
-// return featureType.create(attributes, id );
- }
-
- /**
- * Gets the primary geometry AttributeType. If the FeatureType has more
- * one geometry it is up to the implementor to determine which geometry is
- * the default. If working with multiple geometries it is best to get the
- * attributeTypes and iterate through them, checking isGeometry on each.
- * This should just be used a convenience method when it is known that the
- * features are flat.
- *
- * @return The attribute type of the default geometry, which will contain
- * the position.
- */
- public GeometryAttributeType getDefaultGeometry() {
-// return defaultGeom;
- return (GeometryAttributeType) super.getDefaultGeometry();
- }
-
- /**
- * Gets the attributeType at this xPath, if the specified attributeType
- * does not exist then null is returned.
- *
- * @param xPath XPath pointer to attribute type.
- *
- * @return True if attribute exists.
- */
- public AttributeType getAttributeType(String xPath) {
- return (AttributeType) getAttribute(xPath);
-// AttributeType attType = null;
-// int idx = find(xPath);
-// if (idx >= 0)
-// attType = types[idx];
-// return attType;
- }
-
- /**
- * Find the position of a given AttributeType.
- *
- * @param type The type to search for.
- *
- * @return -1 if not found, a zero-based index if found.
- */
- public int find(AttributeType type) {
-
- if (type == null) return -1;
- int idx = find(type.getLocalName());
- if (idx < 0 || !getAttributes().get(idx).equals(type))
- idx = -1;
- return idx;
- }
-
- /**
- * Find the position of an AttributeType which matches the given String.
- * @param attName the name to look for
- * @return -1 if not found, zero-based index otherwise
- */
- public int find(String attName) {
- return indexOf(attName);
-// Integer idx = (Integer) attLookup.get(attName);
-// return idx == null ? -1 : idx.intValue();
- }
-
- /**
- * Gets the attributeType at the specified index.
- *
- * @param position the position of the attribute to check.
- *
- * @return The attribute type at the specified position.
- */
- public AttributeType getAttributeType(int position) {
-// return types[position];
- return (AttributeType) getAttributes().get(position);
- }
-
- public AttributeType[] getAttributeTypes() {
-// return (AttributeType[]) types.clone();
- return (AttributeType[]) getAttributes().toArray( new AttributeType[ getAttributes().size()]);
- }
-
- /**
- * Gets the global schema namespace.
- *
- * @return Namespace of schema.
- */
- public URI getNamespace() {
-// return namespace;
- try {
- return getName().getNamespaceURI() != null ? new URI( getName().getNamespaceURI() ) : null;
- }
- catch (URISyntaxException e) {
- //dont have to worry, would have thrown an exception in constructor
- return null;
- }
- }
-
- /**
- * Gets the type name for this schema.
- *
- * @return Namespace of schema.
- */
- public String getTypeName() {
-// return typeName;
- return getName().getLocalPart();
- }
-
- /**
- * This is only used twice in the whole geotools code base, and one of
- * those is for a test, so we're removing it from the interface. If
- * getAttributeType does not have the AttributeType it will just return
- * null. Gets the number of occurrences of this attribute.
- *
- * @param xPath XPath pointer to attribute type.
- *
- * @return Number of occurrences.
- */
- public boolean hasAttributeType(String xPath) {
- return getAttributeType(xPath) != null;
- }
-
- /**
- * Returns the number of attributes at the first 'level' of the schema.
- *
- * @return the total number of first level attributes.
- */
- public int getAttributeCount() {
-// return types.length;
- return getAttributes().size();
- }
-
-// public boolean equals(FeatureType other) {
-// if(other == this)
-// return true;
-//
-// if (other == null) {
-// return false;
-// }
-//
-// if ((typeName == null) && (other.getTypeName() != null)) {
-// return false;
-// } else if (!typeName.equals(other.getTypeName())) {
-// return false;
-// }
-//
-// if ((namespace == null) && (other.getNamespace() != null)) {
-// return false;
-// } else if (!namespace.equals(other.getNamespace())) {
-// return false;
-// }
-//
-// if (types.length != other.getAttributeCount()) {
-// return false;
-// }
-//
-// for (int i = 0, ii = types.length; i < ii; i++) {
-// if (!types[i].equals(other.getAttributeType(i))) {
-// return false;
-// }
-// }
-//
-// return true;
-// }
-
- private int computeHash() {
-// int hash = typeName.hashCode() ^ namespace.hashCode();
-// for (int i = 0, ii = types.length; i < ii; i++) {
-// hash ^= types[i].hashCode();
-// }
-// return hash;
- return super.hashCode();
- }
-
- public int hashCode() {
- return hashCode;
- }
-
-// public String toString() {
-// String info = "name=" + typeName;
-// info += (" , namespace=" + namespace);
-// info += (" , abstract=" + isAbstract());
-//
-// String types1 = "types=(";
-//
-// for (int i = 0, ii = this.types.length; i < ii; i++) {
-// types1 += this.types[i].toString();
-//
-// if (i < ii) {
-// types1 += ",";
-// }
-// }
-//
-// types1 += ")";
-// info += (" , " + types1);
-//
-// return "DefaultFeatureType [" + info + "]";
-// }
-
- public boolean equals(Object other) {
- if (other instanceof FeatureType)
- return super.equals((FeatureType) other);
-
- return false;
- }
-
- /**
- * Obtain an array of this FeatureTypes ancestors. Implementors should
- * return a non-null array (may be of length 0).
- *
- * @return An array of ancestors.
- */
- public FeatureType[] getAncestors() {
-// return ancestors;
- return null;
- }
-
- /**
- * Is this FeatureType an abstract type?
- *
- * @return true if abstract, false otherwise.
- */
- public boolean isAbstract() {
- return false;
- }
-
- /**
- * A convenience method for calling<br>
- * <code> FeatureType f1; FeatureType f2;
- * f1.isDescendedFrom(f2.getNamespace(),f2.getName()); </code>
- *
- * @param type The type to compare to.
- *
- * @return true if descendant, false otherwise.
- */
- public boolean isDescendedFrom(FeatureType type) {
- return isDescendedFrom(type.getNamespace(), type.getTypeName());
- }
-
- /**
- * Test to determine whether this FeatureType is descended from the given
- * FeatureType. Think of this relationship likes the "extends"
- * relationship in java.
- *
- * @param nsURI The namespace URI to use.
- * @param typeName1 The typeName.
- *
- * @return true if descendant, false otherwise.
- *
- * @task HACK: if nsURI is null only typeName is tested.
- */
- public boolean isDescendedFrom(URI nsURI, String typeName1) {
- FeatureType superType = (FeatureType) getSuper();
- while( superType != null ) {
- if ( nsURI == null ) {
- //dont match on namespace
- if ( Utilities.equals(superType.getTypeName(), typeName1) ) {
- return true;
- }
- }
- else {
- if ( Utilities.equals(superType.getNamespace(),nsURI) &&
- Utilities.equals(superType.getTypeName(), typeName1)) {
- return true;
- }
- }
-
-
- superType = (FeatureType) superType.getSuper();
- }
-
- //one more effort, if no
- return false;
- }
-
- static final class Abstract extends DefaultFeatureType {
- public Abstract(String typeName, URI namespace, Collection types,
- Collection superTypes, GeometryAttributeType defaultGeom)
- throws SchemaException {
- super(typeName, namespace, types, superTypes, defaultGeom);
-
- Iterator st = superTypes.iterator();
-
- while (st.hasNext()) {
- FeatureType ft = (FeatureType) st.next();
-
- //JD: removing this check, as its not the case in xml
- //if (!ft.isAbstract()) {
- // throw new SchemaException(
- // "Abstract type cannot descend from no abstract type : "
- // + ft);
- //}
- }
- }
-
- public final boolean isAbstract() {
- return true;
- }
-
- public Feature create(Object[] atts) throws IllegalAttributeException {
- throw new UnsupportedOperationException("Abstract Type");
- }
-
- public Feature create(Object[] atts, String id)
- throws IllegalAttributeException {
- throw new UnsupportedOperationException("Abstract Type");
- }
-
- }
-
-}
Deleted: geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/DefaultFeatureTypeFactory.java
===================================================================
--- geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/DefaultFeatureTypeFactory.java 2007-10-01 00:43:34 UTC (rev 27293)
+++ geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/DefaultFeatureTypeFactory.java 2007-10-01 00:46:16 UTC (rev 27294)
@@ -1,88 +0,0 @@
-/*
- * GeoTools - OpenSource mapping toolkit
- * http://geotools.org
- * (C) 2002-2006, GeoTools Project Managment Committee (PMC)
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation;
- * version 2.1 of the License.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- */
-package org.geotools.feature;
-
-
-// J2SE dependencies
-import java.util.ArrayList;
-import java.util.List;
-
-
-/**
- * A simple DefaultFeatureTypeFactory which stores its Attributes in a list.
- * Oppurtunistic reuse is easy! Simply subclass this and override the method
- * <code>createFeatureType</code> to return whatever type of FeatureType you
- * want.
- *
- * @author Ian Schneider, USDA-ARS
- * @source $URL$
- * @version $Id$
- */
-public class DefaultFeatureTypeFactory extends FeatureTypeFactory {
- private List attributeTypes = new ArrayList();
-
- protected void add(AttributeType type) throws IllegalArgumentException {
- attributeTypes.add(type);
- }
-
- protected void add(int idx, AttributeType type)
- throws ArrayIndexOutOfBoundsException, IllegalArgumentException {
- attributeTypes.add(idx, type);
- }
-
- protected FeatureType createFeatureType() throws SchemaException {
- if (isAbstract()) {
- return createAbstractType();
- }
-
- return new DefaultFeatureType(getName(), getNamespace(),
- attributeTypes, getSuperTypes(), getDefaultGeometry());
- }
-
- public AttributeType get(int idx) throws ArrayIndexOutOfBoundsException {
- return (AttributeType) attributeTypes.get(idx);
- }
-
- public int getAttributeCount() {
- return attributeTypes.size();
- }
-
- protected AttributeType remove(int idx)
- throws ArrayIndexOutOfBoundsException {
- return (AttributeType) attributeTypes.remove(idx);
- }
-
- protected AttributeType remove(AttributeType type) {
- if (attributeTypes.remove(type)) {
- return type;
- }
-
- return null;
- }
-
- protected AttributeType set(int idx, AttributeType type)
- throws ArrayIndexOutOfBoundsException, IllegalArgumentException {
- AttributeType former = get(idx);
- attributeTypes.set(idx, type);
-
- return former;
- }
-
- protected FeatureType createAbstractType() throws SchemaException {
- return new DefaultFeatureType.Abstract(getName(), getNamespace(),
- attributeTypes, getSuperTypes(), getDefaultGeometry());
- }
-}
Deleted: geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/DefaultFeatureTypeFactory2.java
===================================================================
--- geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/DefaultFeatureTypeFactory2.java 2007-10-01 00:43:34 UTC (rev 27293)
+++ geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/DefaultFeatureTypeFactory2.java 2007-10-01 00:46:16 UTC (rev 27294)
@@ -1,36 +0,0 @@
-package org.geotools.feature;
-
-import java.util.List;
-
-import org.geotools.feature.type.FeatureTypeFactoryImpl;
-import org.opengis.feature.simple.SimpleFeatureType;
-import org.opengis.feature.type.AttributeDescriptor;
-import org.opengis.feature.type.AttributeType;
-import org.opengis.feature.type.GeometryDescriptor;
-import org.opengis.feature.type.GeometryType;
-import org.opengis.feature.type.Name;
-import org.opengis.filter.Filter;
-import org.opengis.util.InternationalString;
-
-/**
- * Extension of FeatureTypeFactoryImpl which creates instances of DefaultFeatureType.
- * <p>
- * The point of this class is to maintain backwards compatability internally and
- * it should not be used by any client code.
- * </p>
- * @author Justin Deoliveira, The Open Planning Project
- *
- * @deprecated
- * @since 2.5
- */
-public class DefaultFeatureTypeFactory2 extends FeatureTypeFactoryImpl {
-
- public SimpleFeatureType createSimpleFeatureType(Name name,
- List<AttributeDescriptor> schema,
- GeometryDescriptor defaultGeometry, boolean isAbstract,
- List<Filter> restrictions, AttributeType superType,
- InternationalString description) {
- return new DefaultFeatureType(name, schema, defaultGeometry, isAbstract,
- restrictions, superType, description);
- }
-}
Deleted: geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/FeatureTypeBuilder.java
===================================================================
--- geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/FeatureTypeBuilder.java 2007-10-01 00:43:34 UTC (rev 27293)
+++ geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/FeatureTypeBuilder.java 2007-10-01 00:46:16 UTC (rev 27294)
@@ -1,701 +0,0 @@
-/*
- * GeoTools - OpenSource mapping toolkit
- * http://geotools.org
- * (C) 2002-2006, GeoTools Project Managment Committee (PMC)
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation;
- * version 2.1 of the License.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- */
-package org.geotools.feature;
-
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-
-import javax.swing.text.html.HTMLDocument.Iterator;
-
-import org.geotools.factory.CommonFactoryFinder;
-import org.geotools.factory.Factory;
-import org.geotools.factory.FactoryConfigurationError;
-import org.geotools.factory.GeoTools;
-import org.geotools.factory.Hints;
-
-/**
- * A schema builder, because FeatureTypes are meant to be immutable, this
- * object is mutable.
- *
- * <p>
- * The basic idea for usage is that you configure the builder to whatever state
- * is desired, setting properties and adding AttributeTypes. When the desired
- * state is acheived, the expected FeatureType can be retrieved by calling<br>
- * <code>getFeatureType()</code>
- * </p>
- * <p>
- * Repeated calls to getFeatureType will return the <i>same</i> FeatureType
- * given that no calls which modify the state of the factory are made.
- * </p>
- *
- * <p>
- * Here's an example of how to use this:
- * <code><pre>
- * FeatureTypeBuilder build = FeatureTypeFactory.newInstance();
- * build.addType(...);
- * build.setName(...);
- * build.setNamespace(...);
- * FeatureType type = build.getFeatureType();
- * </pre></code>
- * There are also a set of convenience methods for creation of FeatureTypes.
- * These are the various newFeatureType methods.
- * </p>
- *
- * </p>
- *
- * @author Ian Schneider
- * @source $URL$
- * @version $Id$
- */
-public abstract class FeatureTypeBuilder extends FeatureTypes implements Factory {
-
- /** If the base types have been initialized */
- private static boolean initialized;
-
- /** The name to give the FeatureType to be created. */
- private String name;
-
- /** The namespace to give the FeatureType to be created. */
- private URI namespace;
-
- /** If something in the factory has changed. */
- private boolean dirty = true;
-
- /** The type created. */
- private FeatureType type = null;
-
- /** The current defaultGeometry of the FeatureType returned. */
- private GeometryAttributeType defaultGeometry = null;
-
- /** If the type is abstract. */
- private boolean abstractType = false;
-
- /** The types that this is derived from. */
- private java.util.Set superTypes;
-
- /**
- * Implementation hints - since this is a builder all
- * hints are passed onto the FeatureType.
- */
- Map hints;
-
- /**
- * An empty public constructor. Subclasses should not provide a
- * constructor.
- * @deprecated
- */
- public FeatureTypeBuilder() {
- this( Collections.EMPTY_MAP );
- }
-
- /**
- * An empty public constructor. Subclasses should not provide a
- * constructor.
- */
- public FeatureTypeBuilder( Map hints) {
- this.hints = hints;
- }
-
- /**
- * Returns the implementation hints. The default implementation returns en empty map.
- * <p>
- * Since the building of a FeatureType involves the collaboration of may
- * Factory classes (that may be discovered over the course of the build process)
- * we are forced to indicate that *all* hints are used.
- * </p>
- * <p>
- * Strictly this is a Builder (not a factory) and has no need declair which
- * hints are used (as one can never *keep* this builder in a factory registery.
- * (It is stateful and cannot be used concurrently for example).
- */
- public Map getImplementationHints() {
- return hints;
- }
- /**
- * Create a new FeatureTypeFactory with the given typeName.
- *
- * @param name The typeName of the feature to create.
- *
- * @return A new FeatureTypeFactory instance.
- *
- * @throws FactoryConfigurationError If there exists a configuration error.
- */
- public static FeatureTypeFactory newInstance(String typeName)
- throws FactoryConfigurationError {
-
- // warning not sure if CommonFactoryFinder is going to cache the instance or not?
- //
- Hints hints = GeoTools.getDefaultHints();
- if( hints == null ){
- hints = new Hints( Hints.FEATURE_TYPE_FACTORY_NAME, typeName );
- }
- else {
- hints.put( Hints.FEATURE_TYPE_FACTORY_NAME, typeName );
- }
- hints.put( Hints.FEATURE_TYPE_FACTORY_NAME, typeName );
- return CommonFactoryFinder.getFeatureTypeFactory( hints );
- }
-
- /**
- * Import all of the AttributeTypes from the given FeatureType into this
- * factory.
- *
- * <p>
- * If strict is true, non-uniquely named AttributeTypes will throw an
- * exception.
- * </p>
- *
- * <p>
- * If strict is false, these will be silently ignored, but not added.
- * </p>
- *
- * <p>
- * No other information is imported.
- * </p>
- *
- * @param type The FeatureType to import from.
- * @param strict Enforce namespace restrictions.
- *
- * @throws IllegalArgumentException If strict is true and there are naming
- * problems.
- */
- public void importType(FeatureType type, boolean strict)
- throws IllegalArgumentException {
- for (int i = 0, ii = type.getAttributeCount(); i < ii; i++) {
- try {
- addType(type.getAttributeType(i));
- } catch (IllegalArgumentException iae) {
- if (strict) {
- throw iae;
- }
- }
- }
- }
-
- /**
- * Set the super types of this factory. The types will be copied into a
- * Set.
- *
- * @param types A Collection of types.
- */
- public final void setSuperTypes(java.util.Collection types) {
- superTypes = new java.util.LinkedHashSet(types);
- }
-
- /**
- * Obtain the super types of this factory. Any user types will be appended
- * to the built in types of this factory.
- *
- * @return A Collection representing the super types of the FeatureType
- * this factory will create.
- */
- public final java.util.Collection getSuperTypes() {
- Set supers = (superTypes == null) ? new HashSet() : superTypes;
-
- boolean add = true;
- for ( java.util.Iterator s = supers.iterator(); s.hasNext(); ) {
- FeatureType superType = (FeatureType) s.next();
- if ( superType.isDescendedFrom(ABSTRACT_FEATURE_TYPE) ) {
- add = false;
- }
- }
- if ( add ) {
- supers.add(ABSTRACT_FEATURE_TYPE);
- }
-
- return supers;
- }
-
- /**
- * A convienence method for importing AttributeTypes, simply calls<br>
- * <code> importType(type,false) </code>
- *
- * @param type The type to import.
- */
- public void importType(FeatureType type) {
- importType(type, false);
- }
-
- /**
- * Set the name of the FeatureType this factory will produce.
- *
- * @param name The new name. May be null.
- */
- public void setName(String name) {
- dirty |= isDifferent(name, this.name);
- this.name = name;
- }
-
- /**
- * Get the current configuration of the name of this factory.
- *
- * @return The current name. May be null.
- */
- public final String getName() {
- return name;
- }
-
- /**
- * Set the namespace of the FeatureType this factory will produce.
- *
- * @param namespace The new namespace. May be null.
- */
- public void setNamespace(URI namespace) {
- dirty |= isDifferent(namespace, this.namespace);
- this.namespace = namespace;
- }
-
- /**
- * Get the current configuration of the namespace of this factory.
- *
- * @return The current namespace. May be null.
- */
- public final URI getNamespace() {
- return namespace;
- }
-
- /**
- * Is this factory configured to be abstract?
- *
- * @return True if it is, false if it aint.
- */
- public final boolean isAbstract() {
- return abstractType;
- }
-
- /**
- * Configure this factory to produce an abstract type.
- *
- * @param a True or false.
- */
- public final void setAbstract(boolean a) {
- dirty = true;
- this.abstractType = a;
- }
-
- private boolean isDifferent(String s1, String s2) {
- if (s1 != null) {
- return !s1.equals(s2);
- }
-
- if (s2 != null) {
- return !s2.equals(s1);
- }
-
- return s1 != s2;
- }
- private boolean isDifferent(URI u1, URI u2) {
- if (u1 != null) {
- return !u1.equals(u2);
- }
-
- if (u2 != null) {
- return !u2.equals(u1);
- }
-
- return u1 != u2;
- }
- /**
- * Remove all the AttributeTypes in this factory.
- */
- public final void removeAll() {
- int cnt = getAttributeCount();
-
- for (int i = cnt; i > 0; i++) {
- removeType(i - 1);
- }
- }
-
- /**
- * Add an array of AttributeTypes to this factory.
- *
- * @param types The types or a null array.
- *
- * @throws NullPointerException If any of the types are null.
- * @throws IllegalArgumentException If there are naming problems.
- */
- public final void addTypes(AttributeType[] types)
- throws NullPointerException, IllegalArgumentException {
- if (types == null) {
- return;
- }
-
- for (int i = 0; i < types.length; i++) {
- addType(types[i]);
- }
- }
-
- /**
- * A the given AttributeType to this factory.
- *
- * @param type The type to add.
- *
- * @throws NullPointerException If the type is null.
- * @throws IllegalArgumentException If another type exists with the same
- * name.
- */
- public final void addType(AttributeType type)
- throws NullPointerException, IllegalArgumentException {
- if (type == null) {
- throw new NullPointerException("type");
- }
-
- dirty = true;
- check(type);
- add(type);
- }
-
- /**
- * Remove the given type from this factory.
- *
- * @param type The type to remove.
- *
- * @throws NullPointerException If the type is null.
- */
- public final void removeType(AttributeType type)
- throws NullPointerException {
- if (type == null) {
- throw new NullPointerException("type");
- }
-
- dirty = true;
-
- AttributeType removed = remove(type);
-
- if (removed == defaultGeometry) {
- defaultGeometry = null;
- }
- }
-
- /**
- * Insert the given type at the index specified.
- *
- * @param idx The index to insert at.
- * @param type The AttributeType to insert.
- *
- * @throws NullPointerException If the type is null.
- * @throws IllegalArgumentException If the AttributeType is not allowed.
- * @throws ArrayIndexOutOfBoundsException If the index is out of range.
- */
- public final void addType(int idx, AttributeType type)
- throws NullPointerException, IllegalArgumentException,
- ArrayIndexOutOfBoundsException {
- if (type == null) {
- throw new NullPointerException("type");
- }
-
- dirty = true;
- check(type);
- add(idx, type);
- }
-
- /**
- * Remove the AttributeType at the given index.
- *
- * @param idx The index to remove at.
- *
- * @throws ArrayIndexOutOfBoundsException If the index is out of bounds.
- */
- public final void removeType(int idx) throws ArrayIndexOutOfBoundsException {
- dirty = true;
-
- AttributeType removed = remove(idx);
-
- if (removed == defaultGeometry) {
- defaultGeometry = null;
- }
- }
-
- /**
- * Set the AttributeType at the given index. Overwrites the existing type.
- *
- * @param idx The index to use.
- * @param type The type to use.
- *
- * @throws IllegalArgumentException If the type is not good.
- * @throws NullPointerException if they type passed in is null
- * @throws ArrayIndexOutOfBoundsException if the index is out of bounds.
- */
- public final void setType(int idx, AttributeType type)
- throws IllegalArgumentException, NullPointerException,
- ArrayIndexOutOfBoundsException {
- if (type == null) {
- throw new NullPointerException("type");
- }
-
- dirty = true;
- check(type);
-
- AttributeType removed = set(idx, type);
-
- if (removed == defaultGeometry) {
- defaultGeometry = null;
- }
- }
-
- /**
- * Swap the AttributeTypes at the given locations.
- *
- * @param idx1 The index of the first.
- * @param idx2 The index of the second.
- *
- * @throws ArrayIndexOutOfBoundsException if either index is not in the
- * array bounds.
- */
- public final void swap(int idx1, int idx2)
- throws ArrayIndexOutOfBoundsException {
- // implementation note:
- // we must rely on the subclass implementation, which, hopefully does
- // not do any checking. If we used setType, there is a name overlap.
- AttributeType tmp = get(idx1);
- set(idx1, get(idx2));
- set(idx2, tmp);
-
- // must do this!
- dirty = true;
- }
-
- /**
- * Return the AttributeType currently used as the defaultGeometry property
- * for the FeatureType this factory will create.
- *
- * @return The AttributeType representing the defaultGeometry or null.
- */
- public final GeometryAttributeType getDefaultGeometry() {
- return defaultGeometry;
- }
-
- /**
- * Sets the defaultGeometry of this factory. If the defaultGeometry
- * AttributeType does not exist as an AttributeType within this factory,
- * it is added. This will overwrite the existing defaultGeometry, yet not
- * remove it from the existing AttributeTypes.
- *
- * @param defaultGeometry The AttributeType to use as the defaultGeometry.
- * May be null.
- *
- * @throws IllegalArgumentException if the type is not a geometry.
- */
- public final void setDefaultGeometry(GeometryAttributeType defaultGeometry)
- throws IllegalArgumentException {
- // check if Geometry
- if ((defaultGeometry != null) && !defaultGeometry.isGeometry()) {
- String mess = "Attempted to set a non-geometry type as "
- + "defaultGeometry: ";
- throw new IllegalArgumentException(mess + defaultGeometry);
- }
-
- dirty = true; // do this!
- this.defaultGeometry = defaultGeometry;
-
- // if the defaultGeometry hasn't been added, add it!
- if ((defaultGeometry != null) && !contains(defaultGeometry)) {
- addType(defaultGeometry);
- }
- }
-
- /**
- * Get a FeatureType which reflects the state of this factory. Any
- * modifications to the state of the factory (adding, removing, or
- * reordering any AttributeTypes or changing any other properties -
- * isNillable,name,etc.), will cause the factory to "retool" itself. If
- * the factory has not changed since a call to this method, the return
- * value will be the same FeatureType which the previous method returned.
- * Otherwise, a new FeatureType will be created.
- *
- * @return The featureType reflecting the current factory state.
- *
- * @throws SchemaException if name is null or blank
- */
- public final FeatureType getFeatureType() throws SchemaException {
- // we're dirty, recreate the FeatureType
- if (dirty || (type == null)) {
- // no defaultGeometry assigned, search for one.
- if (defaultGeometry == null) {
- for (int i = 0, ii = getAttributeCount(); i < ii; i++) {
- if (get(i) instanceof GeometryAttributeType) {
- defaultGeometry = (GeometryAttributeType) get(i);
- break;
- }
- }
- }
-
- if ((name == null) || (name.trim().length() == 0)) {
- throw new SchemaException(
- "Cannot create FeatureType with null or blank name");
- }
-
- type = createFeatureType();
-
- // oops, the subclass messed up...
- if (type == null) {
- throw new NullPointerException(getClass().getName()
- + ".createFeatureType()");
- }
-
- if (isAbstract() && !type.isAbstract()) {
- throw new RuntimeException(
- "FeatureTypeFactory poorly implemented, "
- + "expected abstract type, received " + type);
- }
-
- // not dirty anymore.
- dirty = false;
- }
-
- return type;
- }
-
- /**
- * Returns a string representation of this factory.
- *
- * @return The string representing this factory.
- */
- public String toString() {
- String types = "";
-
- for (int i = 0, ii = getAttributeCount(); i < ii; i++) {
- types += get(i);
-
- if (i < ii) {
- types += " , ";
- }
- }
-
- return "FeatureTypeFactory(" + getClass().getName() + ") [ " + types
- + " ]";
- }
-
- /**
- * Check to see if this factory contains the given AttributeType. The
- * comparison is done by name.
- *
- * @param type The AttributeType to search for by name.
- *
- * @return <tt>true</tt> if a like-named AttributeType exists,
- * <tt>false</tt> otherwise.
- */
- public final boolean contains(AttributeType type) {
- for (int i = 0, ii = getAttributeCount(); i < ii; i++) {
- if (get(i).getLocalName().equals(type.getLocalName())) {
- return true;
- }
- }
-
- return false;
- }
-
- /**
- * Checks to see if this factory already contains the type.
- *
- * @param type
- *
- * @throws IllegalArgumentException DOCUMENT ME!
- */
- protected void check(AttributeType type) {
- if (contains(type)) {
- throw new IllegalArgumentException("Duplicate AttributeTypes "
- + type);
- }
- }
-
- protected void addBaseTypes(Set types) {
- // base class hook
- }
-
- /**
- * DOCUMENT ME!
- *
- */
- protected abstract FeatureType createFeatureType()
- throws SchemaException;
-
- /**
- * DOCUMENT ME!
- *
- * @param type
- *
- * @throws IllegalArgumentException
- */
- protected abstract void add(AttributeType type)
- throws IllegalArgumentException;
-
- /**
- * DOCUMENT ME!
- *
- * @param type
- *
- */
- protected abstract AttributeType remove(AttributeType type);
-
- /**
- * DOCUMENT ME!
- *
- * @param idx
- * @param type
- *
- * @throws ArrayIndexOutOfBoundsException
- * @throws IllegalArgumentException
- */
- protected abstract void add(int idx, AttributeType type)
- throws ArrayIndexOutOfBoundsException, IllegalArgumentException;
-
- /**
- * DOCUMENT ME!
- *
- * @param idx
- *
- *
- * @throws ArrayIndexOutOfBoundsException
- */
- protected abstract AttributeType remove(int idx)
- throws ArrayIndexOutOfBoundsException;
-
- /**
- * DOCUMENT ME!
- *
- * @param idx
- *
- *
- * @throws ArrayIndexOutOfBoundsException
- */
- public abstract AttributeType get(int idx)
- throws ArrayIndexOutOfBoundsException;
-
- /**
- * DOCUMENT ME!
- *
- * @param idx
- * @param type
- *
- *
- * @throws ArrayIndexOutOfBoundsException
- * @throws IllegalArgumentException
- */
- protected abstract AttributeType set(int idx, AttributeType type)
- throws ArrayIndexOutOfBoundsException, IllegalArgumentException;
-
- /**
- * DOCUMENT ME!
- *
- */
- public abstract int getAttributeCount();
-
-}
Deleted: geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/FeatureTypeFactory.java
===================================================================
--- geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/FeatureTypeFactory.java 2007-10-01 00:43:34 UTC (rev 27293)
+++ geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/FeatureTypeFactory.java 2007-10-01 00:46:16 UTC (rev 27294)
@@ -1,284 +0,0 @@
-/*
- * GeoTools - OpenSource mapping toolkit
- * http://geotools.org
- * (C) 2002-2006, GeoTools Project Managment Committee (PMC)
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation;
- * version 2.1 of the License.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- */
-package org.geotools.feature;
-
-import java.net.URI;
-import java.util.Arrays;
-
-import org.geotools.factory.FactoryCreator;
-import org.geotools.factory.FactoryRegistry;
-import org.geotools.factory.FactoryRegistryException;
-import org.geotools.feature.type.DefaultFeatureTypeBuilder;
-
-
-/**
- * Replaced with use of FeatureTypeBuilder to follow standard pattern
- * naming conventions.
- *
- * @deprecated Please use FeatureTypeBuilder
- * @author Ian Schneider
- * @source $URL$
- * @version $Id$
- */
-public abstract class FeatureTypeFactory extends FeatureTypeBuilder {
- /**
- * An empty public constructor. Subclasses should not provide a
- * constructor.
- */
- public FeatureTypeFactory() {
- // no op constructor
- }
-
- /**
- * The service registry for this manager.
- * Will be initialized only when first needed.
- */
- private static FactoryRegistry registry;
-
- /**
- * Returns the service registry. The registry will be created the first
- * time this method is invoked.
- */
- private static FactoryRegistry getServiceRegistry() {
- assert Thread.holdsLock(FeatureTypeFactory.class);
- if (registry == null) {
- registry = new FactoryCreator(Arrays.asList(new Class[] {
- FeatureTypeFactory.class}));
- }
- return registry;
- }
-
- /**
- * The most specific way to create a new FeatureType.
- *
- * @param types The AttributeTypes to create the FeatureType with.
- * @param name The typeName of the FeatureType. Required, may not be null.
- * @param ns The namespace of the FeatureType. Optional, may be null.
- * @param isAbstract True if this created type should be abstract.
- * @param superTypes A Collection of types the FeatureType will inherit
- * from. Currently, all types inherit from feature in the opengis
- * namespace.
- *
- * @return A new FeatureType created from the given arguments.
- *
- * @throws FactoryConfigurationError If there are problems creating a
- * factory.
- * @throws SchemaException If the AttributeTypes provided are invalid in
- * some way.
- */
- public static FeatureType newFeatureType(AttributeType[] types,
- String name, URI ns, boolean isAbstract, FeatureType[] superTypes)
- throws FactoryRegistryException, SchemaException {
- return newFeatureType(types, name, ns, isAbstract, superTypes, null);
- }
-
- /**
- * The most specific way to create a new FeatureType.
- *
- * @param types The AttributeTypes to create the FeatureType with.
- * @param name The typeName of the FeatureType. Required, may not be null.
- * @param ns The namespace of the FeatureType. Optional, may be null.
- * @param isAbstract True if this created type should be abstract.
- * @param superTypes A Collection of types the FeatureType will inherit
- * from. Currently, all types inherit from feature in the opengis
- * namespace.
- *
- * @return A new FeatureType created from the given arguments.
- *
- * @throws FactoryRegistryException If there are problems creating a
- * factory.
- * @throws SchemaException If the AttributeTypes provided are invalid in
- * some way.
- */
- public static FeatureType newFeatureType(AttributeType[] types,
- String name, URI ns, boolean isAbstract, FeatureType[] superTypes, AttributeType defaultGeometry)
- throws FactoryRegistryException, SchemaException {
-
- return FeatureTypes.newFeatureType(types,name,ns,isAbstract,superTypes,defaultGeometry);
- }
-
- /**
- * The most specific way to create a new FeatureType.
- *
- * @param types The AttributeTypes to create the FeatureType with.
- * @param name The typeName of the FeatureType. Required, may not be null.
- * @param ns The namespace of the FeatureType. Optional, may be null.
- * @param isAbstract True if this created type should be abstract.
- * @param superTypes A Collection of types the FeatureType will inherit
- * from. Currently, all types inherit from feature in the opengis
- * namespace.
- *
- * @return A new FeatureType created from the given arguments.
- *
- * @throws FactoryRegistryException If there are problems creating a
- * factory.
- * @throws SchemaException If the AttributeTypes provided are invalid in
- * some way.
- */
- public static FeatureType newFeatureType(AttributeType[] types,
- String name, URI ns, boolean isAbstract, FeatureType[] superTypes, GeometryAttributeType defaultGeometry)
- throws FactoryRegistryException, SchemaException {
-
- return FeatureTypes.newFeatureType(types, name, ns, isAbstract, superTypes, defaultGeometry);
- }
-
- /**
- * Create a new FeatureType with the given AttributeTypes. A short cut for
- * calling <code>newFeatureType(types,name,ns,isAbstract,null)</code>.
- *
- * @param types The AttributeTypes to create the FeatureType with.
- * @param name The typeName of the FeatureType. Required, may not be null.
- * @param ns The namespace of the FeatureType. Optional, may be null.
- * @param isAbstract True if this created type should be abstract.
- *
- * @return A new FeatureType created from the given arguments.
- *
- * @throws FactoryRegistryException If there are problems creating a
- * factory.
- * @throws SchemaException If the AttributeTypes provided are invalid in
- * some way.
- */
- public static FeatureType newFeatureType(AttributeType[] types,
- String name, URI ns, boolean isAbstract)
- throws FactoryRegistryException, SchemaException {
- return newFeatureType(types, name, ns, isAbstract, null);
- }
-
- /**
- * Create a new FeatureType with the given AttributeTypes. A short cut for
- * calling <code>newFeatureType(types,name,ns,false,null)</code>.
- *
- * @param types The AttributeTypes to create the FeatureType with.
- * @param name The typeName of the FeatureType. Required, may not be null.
- * @param ns The namespace of the FeatureType. Optional, may be null.
- *
- * @return A new FeatureType created from the given arguments.
- *
- * @throws FactoryRegistryException If there are problems creating a
- * factory.
- * @throws SchemaException If the AttributeTypes provided are invalid in
- * some way.
- */
- public static FeatureType newFeatureType(AttributeType[] types,
- String name, URI ns)
- throws FactoryRegistryException, SchemaException {
- return newFeatureType(types, name, ns, false);
- }
-
- /**
- * Create a new FeatureType with the given AttributeTypes. A short cut for
- * calling <code>newFeatureType(types,name,null,false,null)</code>. Useful
- * for test cases or datasources which may not allow a namespace.
- *
- * @param types The AttributeTypes to create the FeatureType with.
- * @param name The typeName of the FeatureType. Required, may not be null.
- *
- * @return A new FeatureType created from the given arguments.
- *
- * @throws FactoryRegistryException If there are problems creating a
- * factory.
- * @throws SchemaException If the AttributeTypes provided are invalid in
- * some way.
- */
- public static FeatureType newFeatureType(AttributeType[] types, String name)
- throws FactoryRegistryException, SchemaException {
- return newFeatureType(types, name, FeatureTypes.DEFAULT_NAMESPACE, false);
- }
-
- /**
- * Create a new FeatureTypeFactory with the given typeName.
- *
- * @param name The typeName of the feature to create.
- *
- * @return A new FeatureTypeFactory instance.
- *
- * @throws FactoryRegistryException If there exists a configuration error.
- */
- public static synchronized FeatureTypeFactory newInstance(String name)
- throws FactoryRegistryException {
- FeatureTypeFactory factory = (FeatureTypeFactory) getServiceRegistry()
- .getServiceProvider(FeatureTypeFactory.class, null, null, null);
- FeatureTypeFactory newFactory;
- try {
- newFactory = (FeatureTypeFactory) factory.getClass().newInstance();
- } catch (InstantiationException e) {
- throw new FactoryRegistryException(e.getMessage(), e);
- } catch (IllegalAccessException e) {
- throw new FactoryRegistryException(e.getMessage(), e);
- }
- newFactory.setName(name);
-
- return newFactory;
- }
-
- /**
- * Create a FeatureTypeFactory which contains all of the AttributeTypes
- * from the given FeatureType. This is simply a convenience method for<br>
- * <code><pre>
- * FeatureTypeFactory factory = FeatureTypeFactory.newInstace();
- * factory.importType(yourTypeHere);
- * factory.setName(original.getName());
- * factory.setNamespace(original.getNamespace());
- * factory.setNillable(original.isNillable());
- * factory.setDefaultGeometry(original.getDefaultGeometry());
- * </pre></code>
- *
- * @param original The FeatureType to obtain information from.
- *
- * @return A new FeatureTypeFactory which is initialized with the state of
- * the original FeatureType.
- *
- * @throws FactoryRegistryException If a FeatureTypeFactory cannot be
- * found.
- */
- public static FeatureTypeFactory createTemplate(FeatureType original)
- throws FactoryRegistryException {
-
- FeatureTypeFactory builder = FeatureTypeFactory.newInstance(original.getTypeName());
- builder.importType(original);
- builder.setNamespace(original.getNamespace());
- builder.setDefaultGeometry(original.getDefaultGeometry());
-
- FeatureType[] ancestors = original.getAncestors();
-
- if (ancestors != null) {
- builder.setSuperTypes(Arrays.asList(ancestors));
- }
-
- return builder;
- }
-
- /**
- * Returns a string representation of this factory.
- *
- * @return The string representing this factory.
- */
- public String toString() {
- String types = "";
-
- for (int i = 0, ii = getAttributeCount(); i < ii; i++) {
- types += get(i);
-
- if (i < ii) {
- types += " , ";
- }
- }
-
- return "FeatureTypeFactory(" + getClass().getName() + ") [ " + types
- + " ]";
- }
-
-}
Deleted: geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/MultiAttributeType.java
===================================================================
--- geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/MultiAttributeType.java 2007-10-01 00:43:34 UTC (rev 27293)
+++ geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/MultiAttributeType.java 2007-10-01 00:46:16 UTC (rev 27294)
@@ -1,172 +0,0 @@
-/*
- * GeoTools - OpenSource mapping toolkit
- * http://geotools.org
- * (C) 2004-2006, GeoTools Project Managment Committee (PMC)
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation;
- * version 2.1 of the License.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- */
-package org.geotools.feature;
-
-import java.util.Iterator;
-import java.util.List;
-
-
-/**
- * Class to handle more than one occurance of an attribute. There may be
- * better ways to do this, but this seems to work.
- *
- * @author Chris Holmes
- * @source $URL$
- * @version $Id$
- *
- * @deprecated Will be removed in geotools 2.6
- */
-public class MultiAttributeType extends DefaultAttributeType {
- /** Number of instances of this attribute in the schema. */
- private int maxOccur = 1;
-
- /** The AttributeType to check each object of the list against. */
- private AttributeType validator;
-
- /** The minimum number of occurances of this attribute to validate. */
- private int minOccur = 1;
-
- /**
- * Constructor with validator.
- *
- * @param validator Name of this attribute.
- */
- public MultiAttributeType(AttributeType validator) {
- super(validator.getLocalName(), List.class, false,1,1,null);
- this.validator = validator;
- }
-
- /**
- * Constructor with validator and maxOccurs
- *
- * @param validator Name of this attribute.
- * @param maxOccur Number of instances of this attribute in the schema.
- */
- public MultiAttributeType(AttributeType validator, int maxOccur) {
- this(validator);
- this.maxOccur = maxOccur;
- }
-
- /**
- * Constructor with validator, minOccurs and maxOccurs
- *
- * @param validator Name of this attribute.
- * @param maxOccur Number of instances of this attribute in the schema.
- * @param minOccur Class type of this attribute.
- */
- public MultiAttributeType(AttributeType validator, int maxOccur,
- int minOccur) {
- this(validator, maxOccur);
- this.minOccur = minOccur;
- }
-
- /**
- * Gets the maxOccur of this attribute.
- *
- * @return MaxOccur.
- */
- public int getMaxOccurs() {
- return maxOccur;
- }
-
- /**
- * Gets the minimum number of elements that pass the validator that must be
- * in the list to validate.
- *
- * @return MaxOccur.
- */
- public int getMinOccurs() {
- return minOccur;
- }
-
- /**
- * Returns whether the attribute is a geometry. Should this be false? Even
- * if the attributes are geometries? Because this itself isn't actually a
- * geometry, so it can't be used as a geometry.
- *
- * @return true if the attribute's type is a geometry.
- */
- public boolean isGeometry() {
- return false;
- }
-
- /**
- * Returns a clone of this object.
- *
- * @return a copy of this attribute type.
- *
- * @throws CloneNotSupportedException if clone is not supported.
- */
- public Object clone() throws CloneNotSupportedException {
- return super.clone();
- }
-
- /**
- * Whether the tested object is a Feature and its attributes validate
- * against the featureType. An IllegalArgumentException reporting the
- * error in validation is thrown if validation fails..
- *
- * @param attribute The object to be tested for validity.
- *
- * @throws IllegalArgumentException if the object does not validate.
- */
- public void validate(Object attribute) throws IllegalArgumentException {
- super.validate(attribute);
-
- if (attribute instanceof List) {
- int occurs = ((List) attribute).size();
-
- if (occurs < minOccur) {
- String mesg = "The list of attributes is " + occurs + " long."
- + " It must not be less than minOccurs: " + minOccur;
- throw new IllegalArgumentException(mesg);
- }
-
- if (occurs > maxOccur) {
- String mesg = "The list of attributes is " + occurs + " long."
- + " It must not be greater than maxOccurs: " + maxOccur;
- throw new IllegalArgumentException(mesg);
- }
-
- for (Iterator iter = ((List) attribute).iterator(); iter.hasNext();) {
- validator.validate(iter.next());
- }
- } else {
- //REVISIT: allow just one if it's not in a list?
- String msg = attribute.getClass().getName()
- + " is not an accetable"
- + " class for a multiAttributeType. Must be of type List";
-
- throw new IllegalArgumentException(msg);
- }
- }
-
- /**
- * Gets a representation of this object as a string.
- *
- * @return A representation of this object as a string
- */
- public String toString() {
- StringBuffer returnString = new StringBuffer("MultiAttributeType [ ");
-
- returnString.append("name=").append(name).append(',');
- returnString.append("type=").append(type.getName()).append(',');
- returnString.append("maxOccurs=").append(maxOccur).append(',');
- returnString.append("minOccur=").append(minOccur).append(" ]");
-
- return returnString.toString();
- }
-}
Deleted: geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/SimpleFeature.java
===================================================================
--- geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/SimpleFeature.java 2007-10-01 00:43:34 UTC (rev 27293)
+++ geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/SimpleFeature.java 2007-10-01 00:46:16 UTC (rev 27294)
@@ -1,163 +0,0 @@
-/*
- * GeoTools - OpenSource mapping toolkit
- * http://geotools.org
- * (C) 2004-2006, GeoTools Project Managment Committee (PMC)
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation;
- * version 2.1 of the License.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- */
-package org.geotools.feature;
-
-/**
- * A simple feature is one that does not have any nested attributes, and that
- * has no multiplicity for each attribute. In non xml speak this means that
- * the attributes returned are guaranteed to be the Objects you would expect -
- * not Lists as is the case when Features are non-simple. This is thus a
- * constraining extension - it essentially allows you to make a few more
- * assumptions about the nature of the {@link Feature} you are getting back.
- *
- * <p>
- * The notion of a Simple Feature is drawn from the OGC's Simple Features for
- * SQL specification - where a simple feature represents a single row in a
- * database table. This extends beyond databases though, to flat files, for
- * example. A database does not necessarily only return simple features -
- * indeed by relying on foreign keys much more complex structures can be
- * created. But at the time of the creation of this class all GeoTools
- * datastores return Simple Features - they just were not explicitly called
- * that. Making explicit that they are Simple should hopefully encourage more
- * complex Features to be returned.
- * </p>
- *
- * <p>
- * The assumptions one can make with Simple Features are as follows:
- * </p>
- *
- * <ul>
- * <li>
- * If {@link #getAttribute(int)} is called then it will always return an
- * actual object, instead of a List, as is common in the parent Feature
- * class. That is to say a Simple Feature will never have more than one
- * attribute in any of its positions, so the interface just assumes that you
- * want the actual object, instead of a List containing just the object.
- * </li>
- * <li>
- * If {@link #setAttribute(int, Object)} is called then a similar assumption is
- * made about the object being set - it need be a List, will default to
- * setting the attribute itself.
- * </li>
- * <li>
- * {@link #getAttribute(String)} and {@link #setAttribute(String, Object)}
- * implicitly append a [0], as that's the behavior implementors expect - to
- * name an attribute and get it back.
- * </li>
- * </ul>
- *
- * <p>
- * To figure out if a Feature is a SimpleFeature one may call instanceof. For
- * a number of Features returned from a DataStore it will save much energy if
- * instanceof is called on the FeatureType, to check if it is a {@link
- * SimpleFeatureType}. And in the future we should have FeatureCollections
- * that know their types.
- * </p>
- *
- * @author David Zwiers, Refractions
- * @author Chris Holmes, TOPP
- * @source $URL$
- * @version $Id$
- *
- * @task REVISIT: I am not sure that I like getAttribute returning the object
- * straight away. It might be better to have a getFirstAttribute()
- * method in Feature.java, and move people to get used to calling that,
- * or else to expect a List (which in a SimpleFeature would always only
- * contain one Object). This would seem to make the api a bit cleaner
- * in my mind.
- * @since 2.1
- *
- * @deprecated use {@link org.opengis.feature.simple.SimpleFeature}
- */
-public interface SimpleFeature extends Feature {
- /**
- * Gets a reference to the schema for this feature. This method should
- * always return DefaultFeatureType Object. This will be explicitly
- * posible in Java 1.5 (dz)
- *
- * @return A reference to this simple feature's schema.
- */
- FeatureType getFeatureType();
-
- /**
- * Sets all attributes for this feature, passed as a complex object array.
- * Note that this array must conform to the internal schema for this
- * feature, or it will throw an exception. Checking this is, of course,
- * left to the feature to do internally. Well behaved features should
- * always fully check the passed attributes against thier schema before
- * adding them. Since this is a SimpleFeature, the number of attributes
- * will be exactly the same as the number of attribute types. Attribute
- * values will be paired with attribute types based on array indexes.
- *
- * @param attributes All feature attributes.
- *
- * @throws IllegalAttributeException Passed attributes do not match schema.
- */
- void setAttributes(Object[] attributes) throws IllegalAttributeException;
-
- /**
- * This is the same as the parent declaration, except that when the
- * instance is not specified for the xPath, [0] will be added as there is
- * only ever one Attribute value for an AttributeType
- *
- * @param xPath XPath representation of attribute location.
- *
- * @return A copy of the requested attribute, null if the requested xpath
- * is not found, or NULL_ATTRIBUTE.
- *
- * @see Feature#getAttribute(String)
- */
- Object getAttribute(String xPath);
-
- /**
- * Gets an attribute by the given zero-based index. Unlike the parent
- * interface, this index is guaranteed to match the index of
- * AttributeType in the FeatureType.
- *
- * @param index The requested index. Must be 0 <= idx <
- * getNumberOfAttributes().
- *
- * @return A copy of the requested attribute, or NULL_ATTRIBUTE.
- */
- Object getAttribute(int index);
-
- /**
- * Sets an attribute by the given zero-based index. Unlike the parent
- * interface, this index is guaranteed to match the index of
- * AttributeType in the FeatureType.
- *
- * @param position The requested index. Must be 0 <= idx <
- * getNumberOfAttributes()
- * @param val An object representing the attribute being set
- *
- * @throws IllegalAttributeException if the passed in val does not validate
- * against the AttributeType at that position.
- * @throws ArrayIndexOutOfBoundsException if an invalid position is given
- */
- void setAttribute(int position, Object val)
- throws IllegalAttributeException, IndexOutOfBoundsException;
-
- /**
- * Allows this feature to turn itself to a Complex Feature - that is one
- * with multiplicity. This is used so that clients can choose to deal
- * with all Complex Features if they would like - always getting lists
- * back when they ask for objects. Of course when a SimpleFeature turns
- * itself into a Complex Feature then all its lists will be of length 1.
- * Am leaving this commented out since it's approved in the api yet -ch
- */
-
- //Feature toComplex();
-}
Deleted: geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/SimpleFeatureType.java
===================================================================
--- geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/SimpleFeatureType.java 2007-10-01 00:43:34 UTC (rev 27293)
+++ geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/SimpleFeatureType.java 2007-10-01 00:46:16 UTC (rev 27294)
@@ -1,69 +0,0 @@
-/*
- * GeoTools - OpenSource mapping toolkit
- * http://geotools.org
- * (C) 2004-2006, GeoTools Project Managment Committee (PMC)
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation;
- * version 2.1 of the License.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- */
-package org.geotools.feature;
-
-import java.net.URI;
-import java.util.Collection;
-
-/**
- * A basic implementation of FeatureType.
- *
- * @author Ian Schneider
- * @source $URL$
- * @version $Id$
- * @deprecated use {@link SimpleFeatureType}.
- */
-public class SimpleFeatureType extends DefaultFeatureType{
-
- /**
- * @deprecated use SimpleFeatureType(String,URI,Collection,Collection,GeometryAttributeType)
- * @param typeName
- * @param namespace
- * @param types
- * @param superTypes
- * @param defaultGeom
- * @throws SchemaException
- * @throws NullPointerException
- */
- public SimpleFeatureType(String typeName, String namespace,
- Collection types, Collection superTypes, GeometryAttributeType defaultGeom)
- throws SchemaException, NullPointerException {
- super(typeName,namespace,types,superTypes,defaultGeom);
- // TODO check for simplicity here;
- }
- /**
- * Constructs a new SimpleFeatureType.
- *
- * <p>
- * Attributes from the superTypes will be copied to the list of attributes
- * for this feature type.
- *
- * @param typeName The name to give this FeatureType.
- * @param namespace The namespace of the new FeatureType.
- * @param types The attributeTypes to use for validation.
- * @param superTypes The ancestors of this FeatureType.
- * @param defaultGeom The attributeType to set as the defaultGeometry.
- *
- * @throws SchemaException For problems making the FeatureType.
- * @throws NullPointerException If typeName is null.
- */
- public SimpleFeatureType(String typeName, URI namespace,
- Collection types, Collection superTypes, GeometryAttributeType defaultGeom)
- throws NullPointerException {
- super(typeName,namespace,types,superTypes,defaultGeom);
- // TODO check for simplicity here;
- }
-}
Modified: geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/simple/SimpleFeatureBuilder.java
===================================================================
--- geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/simple/SimpleFeatureBuilder.java 2007-10-01 00:43:34 UTC (rev 27293)
+++ geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/simple/SimpleFeatureBuilder.java 2007-10-01 00:46:16 UTC (rev 27294)
@@ -179,6 +179,9 @@
*/
public void add(Object value) {
//get the descriptor from the type
+ if(attributes().size() >= featureType.getAttributeCount())
+ throw new IllegalArgumentException("Too many attribute values, this feature " +
+ "type has only " + featureType.getAttributeCount() + " attributes");
AttributeDescriptor descriptor = featureType.getAttribute(attributes().size());
Attribute attribute = null;
@@ -246,7 +249,7 @@
* </code>
* </p>
*/
- public void add(Object[] values ) {
+ public void addAll(Object[] values ) {
if ( values == null ) {
return;
}
@@ -355,7 +358,7 @@
/**
* Internal method for creating feature id's when none is specified.
*/
- protected String createDefaultFeatureId() {
+ public static String createDefaultFeatureId() {
// According to GML and XML schema standards, FID is a XML ID
// (http://www.w3.org/TR/xmlschema-2/#ID), whose acceptable values are those that match an
// NCNAME production (http://www.w3.org/TR/1999/REC-xml-names-19990114/#NT-NCName):
@@ -398,7 +401,7 @@
*/
public static SimpleFeature build( SimpleFeatureType type, Object[] values, String id ) {
SimpleFeatureBuilder builder = new SimpleFeatureBuilder(type);
- builder.add(values);
+ builder.addAll(values);
return builder.buildFeature(id);
}
Deleted: geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/type/ChoiceAttributeType.java
===================================================================
--- geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/type/ChoiceAttributeType.java 2007-10-01 00:43:34 UTC (rev 27293)
+++ geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/type/ChoiceAttributeType.java 2007-10-01 00:46:16 UTC (rev 27294)
@@ -1,443 +0,0 @@
-/*
- * GeoTools - OpenSource mapping toolkit
- * http://geotools.org
- * (C) 2004-2006, GeoTools Project Managment Committee (PMC)
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation;
- * version 2.1 of the License.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- */
-package org.geotools.feature.type;
-
-import com.vividsolutions.jts.geom.Geometry;
-import com.vividsolutions.jts.geom.GeometryFactory;
-import org.geotools.feature.AttributeType;
-import org.geotools.feature.DefaultAttributeType;
-import org.geotools.feature.GeometryAttributeType;
-import org.geotools.feature.IllegalAttributeException;
-import org.geotools.feature.Name;
-import org.opengis.feature.type.GeometryType;
-import org.opengis.filter.Filter;
-import org.opengis.referencing.crs.CoordinateReferenceSystem;
-import java.util.Arrays;
-
-import javax.swing.text.html.HTMLDocument.HTMLReader.IsindexAction;
-
-
-/**
- * This represents a Choice of AttributeTypes. That means, an Attribute of this
- * type may be one of any of this AttributeType's children. This attribute is
- * not valid for Simple Features, and maps to the Choice construct in GML.
- *
- * <p>
- * Another way to think about the ChoiceAttributeType is as a Union
- * construction from C - it can store a number of different types of value,
- * but it only stores the one value. The parse and validate methods try out
- * each of the choices to see if one of them might work, since all are valid.
- * The order that the child attributeTypes (the choices you can use) are
- * specified is important, because some objects can parse and validate
- * against several types. The first choice that returns true is the one that
- * will
- * </p>
- *
- * @author dzwiers
- * @author Chris Holmes, TOPP
- * @source $URL$
- *
- * @deprecated Will be removed in geotools 2.6.
- */
-public class ChoiceAttributeType extends AttributeDescriptorImpl implements AttributeType {
-
- private final AttributeType[] children;
-
- /**
- * DOCUMENT ME!
- *
- * @param copy
- */
- public ChoiceAttributeType(ChoiceAttributeType copy) {
- super( copy.getType(), copy.getName(), copy.getMinOccurs(), copy.getMaxOccurs(), copy.isNillable(), copy.getDefaultValue() );
-
- this.children = copyChildren(copy.getAttributeTypes());
- }
-
- // The field for 'Class type' should be added when GT has moved to java 1.5
- public ChoiceAttributeType(String name, int min, int max,
- AttributeType[] children, Filter restriction) {
- super(DefaultAttributeType.createAttributeType(name, Object.class, restriction),
- new Name(name),min,max,calculateNillableStatic(children),null);
-
- //ensure immutable.
- this.children = copyChildren(children);
- }
-
- public ChoiceAttributeType(String name, AttributeType[] children) {
- this(name, 1, 1, children, Filter.EXCLUDE);
- }
-
- public Filter getRestriction() {
- return DefaultAttributeType.getRestriction(this);
- }
-
- protected AttributeType[] copyChildren(AttributeType[] attributes) {
- int length = attributes.length;
- AttributeType[] returnArray = new AttributeType[length];
- System.arraycopy(attributes, 0, returnArray, 0, length);
- return returnArray;
- }
-
- /**
- * {@inheritDoc}
- */
- public String getLocalName() {
- return DefaultAttributeType.getLocalName(this);
- }
-
- /**
- * Gets the class of the object. For a choice this is fairly useless, as
- * it just returns Object, since we can not tell more than that.
- *
- * @return currently always returns Object.class, since we can't tell more.
- *
- * @task REVISIT: Perhaps we should add a getTypes() method that returns an
- * array of classes, that would represent the classes that you can
- * choose from.
- * @task REVISIT: Would also be good if this could dynamically figure out
- * the broadest class - like Number if the choices were Double and
- * Integer.
- *
- * @see org.geotools.feature.AttributeType#getBinding()
- */
- public Class getBinding() {
- return DefaultAttributeType.getBinding(this);
- }
-
- public boolean calculateNillable(AttributeType[] children) {
- return calculateNillableStatic(children);
- }
-
- /**
- * static verison of {@link #calculateNillable(AttributeType[])} which can
- * be called from constructor.
- */
- private static boolean calculateNillableStatic(AttributeType[] children) {
- for (int i = 0, ii = children.length; i < ii; i++) {
- if (children[i].isNillable()) {
- return true;
- }
- }
-
- //none of the children can take a null, so no nulls are allowed.
- return false;
- }
-
- /* (non-Javadoc)
- * @see org.geotools.feature.AttributeType#isGeometry()
- */
- public boolean isGeometry() {
- return false;
- }
-
- /**
- * Goes through the children, and searches for a parser that works. This
- * method searches in the order in which the children are specified ...
- * please keep this in mind when creating these objects if you care about
- * precedence.
- *
- * @param value The object to parse.
- *
- * @return The object parsed into the appropriate form for the Attribute.
- *
- * @throws IllegalArgumentException If the object could not be parsed by
- * any of the child attribute Types.
- */
- public Object parse(Object value) throws IllegalArgumentException {
- for (int i = 0; i < children.length; i++) {
- try {
- return children[i].parse(value);
- } catch (IllegalArgumentException e) {
- // ignore ... try the next
- }
- }
-
- throw new IllegalArgumentException("Could not be parsed :(");
- }
-
- /**
- * Goes through the children, and searches for a validator that works. This
- * method searches in the order in which the children are specified ...
- * please keep this in mind when creating these objects if you care about
- * precedence.
- *
- * @param obj The object to validate.
- *
- * @throws IllegalArgumentException If none of the children can validate.
- */
- public void validate(Object obj) throws IllegalArgumentException {
- for (int i = 0; i < children.length; i++) {
- try {
- children[i].validate(obj);
-
- return; // validates
- } catch (IllegalArgumentException e) {
- // ignore ... try the next
- }
- }
-
- throw new IllegalArgumentException("Could not be validated :(");
- }
-
- /**
- * Goes through the children, and searches for a duplicator that works.
- * This method searches in the order in which the children are specified
- * ... please keep this in mind when creating these objects if you care
- * about precedence.
- *
- * @param src The object to be duplicated.
- *
- * @return A deep copy of the original object.
- *
- * @throws IllegalAttributeException For any attribute errors.
- * @throws IllegalArgumentException If the object could not be duplicated.
- */
- public Object duplicate(Object src) throws IllegalAttributeException {
- for (int i = 0; i < children.length; i++) {
- try {
- return children[i].duplicate(src);
- } catch (IllegalArgumentException e) {
- // ignore ... try the next
- }
- }
-
- throw new IllegalArgumentException("Could not be duplicated :(");
- }
-
- /**
- * Returns the default value for the first child which does not throw an
- * exception, null otherwise.
- *
- * @return The default value of the first choice that does not throw an
- * exception.
- */
- public Object createDefaultValue() {
- for (int i = 0; i < children.length; i++) {
- try {
- return children[i].createDefaultValue();
- } catch (IllegalArgumentException e) {
- // ignore ... try the next
- }
- }
-
- return null;
- }
-
- /**
- * This is only used twice in the whole geotools code base, and one of
- * those is for a test, so we're removing it from the interface. If
- * getAttributeType does not have the AttributeType it will just return
- * null. Gets the number of occurrences of this attribute.
- *
- * @param xPath XPath pointer to attribute type.
- *
- * @return Number of occurrences.
- */
- public boolean hasAttributeType(String xPath) {
- return getAttributeType(xPath) != null;
- }
-
- /**
- * Returns the number of attributes at the first 'level' of the schema.
- *
- * @return equivalent value to getAttributeTypes().length
- */
- public int getAttributeCount() {
- return children.length;
- }
-
- /**
- * Gets the attributeType at this xPath, if the specified attributeType
- * does not exist then null is returned.
- *
- * @param xPath XPath pointer to attribute type.
- *
- * @return True if attribute exists.
- */
- public AttributeType getAttributeType(String xPath) {
- AttributeType attType = null;
- int idx = find(xPath);
-
- if (idx >= 0) {
- attType = children[idx];
- }
-
- return attType;
- }
-
- /**
- * Find the position of a given AttributeType.
- *
- * @param type The type to search for.
- *
- * @return -1 if not found, a zero-based index if found.
- */
- public int find(AttributeType type) {
- if (type == null) {
- return -1;
- }
-
- int idx = find(type.getLocalName());
-
- if ((idx < 0) || !children[idx].equals(type)) {
- idx = -1;
- }
-
- return idx;
- }
-
- /**
- * Find the position of an AttributeType which matches the given String.
- *
- * @param attName the name to look for
- *
- * @return -1 if not found, zero-based index otherwise
- */
- public int find(String attName) {
- int i = 0;
-
- while ((i < children.length) && !attName.equals(children[i].getLocalName()))
- i++;
-
- return (i == children.length) ? (-1) : i;
- }
-
- /**
- * Gets the attributeType at the specified index.
- *
- * @param position the position of the attribute to check.
- *
- * @return The attribute type at the specified position.
- */
- public AttributeType getAttributeType(int position) {
- return children[position];
- }
-
- public AttributeType[] getAttributeTypes() {
- return (AttributeType[]) children.clone();
- }
-
- public boolean equals(Object other) {
- if (other == null) {
- return false;
- }
-
- if (!(other instanceof ChoiceAttributeType)) {
- return false;
- }
-
- ChoiceAttributeType att = (ChoiceAttributeType) other;
-
- if (!super.equals(att)) {
- return false;
- }
-
- //hmmm... This makes the assumption that the order of the choices
- //matters - not sure if that's true. Though the order does matter a
- //a bit for our parse method, so this is probably right, since two
- //with different orders could have diff. behaviors for that method.
- if (!Arrays.equals(children, att.getAttributeTypes())) {
- return false;
- }
-
- return true;
- }
-
- /**
- * Override of hashCode.
- *
- * @return hashCode for this object.
- */
- public int hashCode() {
- int hash = super.hashCode();
-
- for (int i = 0, ii = children.length; i < ii; i++) {
- hash ^= children[i].hashCode();
- }
-
- return hash;
- }
-
- /**
- * Gets a representation of this object as a string.
- *
- * @return A representation of this object as a string
- */
- public String toString() {
- String details = "name=" + name;
- details += ((" , nillable=" + isNillable()) + ", min=" + getMinOccurs() + ", max=" + getMaxOccurs());
- details += (", choices: " + Arrays.asList(children));
-
- return "ChoiceAttributeType [" + details + "]";
- }
-
- /**
- * A special class that is made so a Choice can serve as the Default
- * Geometry in a FeatureType, by implementing GeometryAttributeType. It
- * must be a choice between other GeometryAttributeTypes.
- *
- * @author Chris Holmes, TOPP
- *
- * @task TODO: Need to write code to check that all the geometry attributes
- * are in the same crs. Right now we just blindly assume they are
- * and return the first.
- */
- public static final class Geometric extends ChoiceAttributeType
- implements GeometryAttributeType {
- public Geometric(Geometric copy) {
- super(copy);
- }
-
- // The field for 'Class type' should be added when GT has moved to java 1.5
- public Geometric(String name, int min, int max,
- GeometryAttributeType[] children, Filter restriction) {
- super(name, min, max, children, restriction);
- }
-
- public Geometric(String name, GeometryAttributeType[] children) {
- super(name, children);
- }
-
- public GeometryType getType() {
- return new GeometryTypeImpl( getName(), Geometry.class, getCoordinateSystem(), false, false, null, null, null);
- }
-
-
- public CoordinateReferenceSystem getCoordinateSystem() {
- //Hack - this is not guaranteed to be right, since right now we
- //don't check in the constructors that all crses are the same.
- GeometryAttributeType first = (GeometryAttributeType) getAttributeType(0);
-
- return first.getCoordinateSystem();
- }
-
- public GeometryFactory getGeometryFactory() {
- //Hack - this is not guaranteed to be right, since right now we
- //don't check in the constructors that all crses are the same.
- GeometryAttributeType first = (GeometryAttributeType) getAttributeType(0);
-
- return first.getGeometryFactory();
- }
-
- /* (non-Javadoc)
- * @see org.geotools.feature.AttributeType#isGeometry()
- */
- public boolean isGeometry() {
- return true;
- }
- }
-}
Deleted: geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/type/DefaultAttributeTypeBuilder.java
===================================================================
--- geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/type/DefaultAttributeTypeBuilder.java 2007-10-01 00:43:34 UTC (rev 27293)
+++ geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/type/DefaultAttributeTypeBuilder.java 2007-10-01 00:46:16 UTC (rev 27294)
@@ -1,28 +0,0 @@
-package org.geotools.feature.type;
-
-import org.geotools.feature.AttributeTypeBuilder;
-import org.geotools.feature.DefaultAttributeType;
-import org.opengis.feature.type.AttributeDescriptor;
-import org.opengis.feature.type.AttributeType;
-import org.opengis.feature.type.GeometryDescriptor;
-import org.opengis.feature.type.GeometryType;
-import org.opengis.feature.type.Name;
-
-public class DefaultAttributeTypeBuilder extends AttributeTypeBuilder {
-
- public DefaultAttributeTypeBuilder() {
- super( new DefaultTypeFactory() );
- }
-
- private static class DefaultTypeFactory extends FeatureTypeFactoryImpl {
- public AttributeDescriptor createAttributeDescriptor(AttributeType type, Name name, int minOccurs, int maxOccurs, boolean isNillable, Object defaultValue) {
- return new DefaultAttributeType( type, name, minOccurs, maxOccurs, isNillable,defaultValue );
- }
-
- public GeometryDescriptor createGeometryDescriptor(GeometryType type,
- Name name, int minOccurs, int maxOccurs, boolean isNillable,
- Object defaultValue) {
- return new GeometricAttributeType(type,name,minOccurs,maxOccurs,isNillable,defaultValue);
- }
- }
-}
Deleted: geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/type/DefaultFeatureTypeBuilder.java
===================================================================
--- geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/type/DefaultFeatureTypeBuilder.java 2007-10-01 00:43:34 UTC (rev 27293)
+++ geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/type/DefaultFeatureTypeBuilder.java 2007-10-01 00:46:16 UTC (rev 27294)
@@ -1,78 +0,0 @@
-package org.geotools.feature.type;
-
-import org.geotools.feature.AttributeType;
-import org.geotools.feature.DefaultFeatureType;
-import org.geotools.feature.DefaultFeatureTypeFactory2;
-import org.geotools.feature.GeometryAttributeType;
-import org.geotools.feature.simple.SimpleFeatureTypeBuilder;
-import org.opengis.feature.type.AttributeDescriptor;
-import org.opengis.referencing.crs.CoordinateReferenceSystem;
-
-import com.vividsolutions.jts.geom.Geometry;
-
-/**
- * Feature Type Builder which creates instances of the old model.
- * <p>
- * This class should not be used outside of geotools itself by client code.
- * Client code should be using {@link SimpleFeatureTypeBuilder}.
- * </p>
- * @author Justin Deoliveira, The Open Planning Project
- *
- */
-public class DefaultFeatureTypeBuilder extends SimpleFeatureTypeBuilder {
-
- public DefaultFeatureTypeBuilder() {
- super( new DefaultFeatureTypeFactory2());
- attributeBuilder = new DefaultAttributeTypeBuilder();
-
- //sets the default namespace to gml
- setNamespaceURI((String)null);
- }
-
- public void setNamespaceURI(String namespaceURI) {
- if ( namespaceURI != null ) {
- super.setNamespaceURI(namespaceURI);
- }
- else {
- super.setNamespaceURI("http://www.opengis.net/gml");
- }
-
- }
-
- public void add(String name, Class binding) {
- if ( Geometry.class.isAssignableFrom(binding)) {
- //TODO: check user data
- add( name, binding, (CoordinateReferenceSystem) null );
- }
- else {
- super.add( name, binding );
- }
- }
-
- /**
- * Additional api for adding an AttributeType directly.
- *
- */
- public void add(AttributeType type) {
- attributes().add(type);
- }
- public void add(AttributeType[] types) {
- if( types == null )
- return;
-
- for ( int i = 0; i < types.length; i++ ) {
- add(types[i]);
- }
- }
-
- public void setDefaultGeometry(AttributeType defaultGeomtetry) {
- setDefaultGeometry(defaultGeomtetry.getLocalName());
- }
-
- /**
- * Override to type narror to DefaultFeautreType.
- */
- public DefaultFeatureType buildFeatureType() {
- return (DefaultFeatureType) super.buildFeatureType();
- }
-}
Deleted: geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/type/FeatureAttributeType.java
===================================================================
--- geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/type/FeatureAttributeType.java 2007-10-01 00:43:34 UTC (rev 27293)
+++ geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/type/FeatureAttributeType.java 2007-10-01 00:46:16 UTC (rev 27294)
@@ -1,226 +0,0 @@
-/*
- * GeoTools - OpenSource mapping toolkit
- * http://geotools.org
- * (C) 2004-2006, GeoTools Project Managment Committee (PMC)
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation;
- * version 2.1 of the License.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- */
-package org.geotools.feature.type;
-
-import org.geotools.feature.AttributeType;
-import org.geotools.feature.DefaultAttributeType;
-import org.geotools.feature.Feature;
-import org.geotools.feature.FeatureType;
-import org.geotools.feature.IllegalAttributeException;
-import org.geotools.feature.Name;
-import org.opengis.filter.Filter;
-
-/**
- * Represents an ordered list of AttributeTypes. For SFS this will be a
- * FeatureType. For GML this is the same as an element whose complexType
- * contains a Sequence of Attributes.
- *
- * @author dzwiers
- * @source $URL$
- */
-public class FeatureAttributeType extends AttributeDescriptorImpl implements AttributeType {
-
- private final FeatureType featureType;
-
-
- /**
- * @param copy
- */
- public FeatureAttributeType(FeatureAttributeType copy) {
- super(copy.getType(),copy.getName(),copy.getMinOccurs(),copy.getMaxOccurs(),copy.isNillable(),copy.getDefaultValue());
-
- featureType = copy.getFeatureType();
- }
-
- // The field for 'Class type' should be added when GT has moved to java 1.5
- public FeatureAttributeType(String name,FeatureType featureType, boolean nillable, int min, int max) {
- super(DefaultAttributeType.createAttributeType(name, Feature.class, Filter.INCLUDE),new Name(name),min,max,nillable,null);
-
- this.featureType = featureType;
- }
-
- public FeatureAttributeType(String name,FeatureType featureType, boolean nillable){
- this(name,featureType, nillable, 1, 1);
- }
- public Filter getRestriction(){
- return DefaultAttributeType.getRestriction(this);
- }
-
- protected FeatureType getFeatureType(){return featureType;}
-
- /**
- * {@inheritDoc}
- */
- public String getLocalName() {
- return DefaultAttributeType.getLocalName(this);
- }
-
- /**
- * {@inheritDoc}
- */
- public Class getBinding() {
- return DefaultAttributeType.getBinding(this);
- }
-
- /* (non-Javadoc)
- * @see org.geotools.feature.AttributeType#isGeometry()
- */
- public boolean isGeometry() {
- return false;
- }
-
- /* (non-Javadoc)
- * @see org.geotools.feature.AttributeType#parse(java.lang.Object)
- */
- public Object parse(Object value) throws IllegalArgumentException {
- if (value instanceof Feature) {
- return value;
- }
- if(value instanceof Object[])
- try {
- return featureType.create((Object[])value);
- } catch (IllegalAttributeException e) {
- IllegalArgumentException ee = new IllegalArgumentException(e.getMessage());
- ee.initCause(e);
- throw ee;
- }
- throw new IllegalArgumentException(getLocalName()+" needs to parse an array of Objects");
- }
-
- /* (non-Javadoc)
- * @see org.geotools.feature.AttributeType#validate(java.lang.Object)
- */
- public void validate(Object obj) throws IllegalArgumentException {
- if(obj instanceof Feature){
- try {
- featureType.duplicate((Feature)obj);
- return;
- } catch (IllegalAttributeException e) {
- IllegalArgumentException ee = new IllegalArgumentException(e.getMessage());
- ee.initCause(e);
- throw ee;
- }
- }
- //users should call parse first - ch.
- /*if(obj instanceof Object[]){
- try {
- featureType.create((Object[])obj);
- return;
- } catch (IllegalAttributeException e) {
- IllegalArgumentException ee = new IllegalArgumentException(e.getMessage());
- ee.initCause(e);
- throw ee;
- }
- }*/
- throw new IllegalArgumentException("Not a Feature");
-
- }
-
- /* (non-Javadoc)
- * @see org.geotools.feature.AttributeType#duplicate(java.lang.Object)
- */
- public Object duplicate(Object src) throws IllegalAttributeException {
- if(src instanceof Feature){
- return featureType.duplicate((Feature)src);
- }
- throw new IllegalArgumentException("Not an Object []");
- }
-
- /* (non-Javadoc)
- * @see org.geotools.feature.AttributeType#createDefaultValue()
- */
- public Object createDefaultValue() {
- Object[] t = new Object[featureType.getAttributeCount()];
- for(int i=0;i<t.length;i++)
- t[i] = null;
- try {
- return featureType.create(t);
- } catch (IllegalAttributeException e) {
- // do nothing
- return null;
- }
- }
-
- /**
- * This is only used twice in the whole geotools code base, and one of
- * those is for a test, so we're removing it from the interface. If
- * getAttributeType does not have the AttributeType it will just return
- * null. Gets the number of occurrences of this attribute.
- *
- * @param xPath XPath pointer to attribute type.
- *
- * @return Number of occurrences.
- */
- public boolean hasAttributeType(String xPath) {
- return getAttributeType(xPath) != null;
- }
-
- /**
- * Returns the number of attributes at the first 'level' of the schema.
- *
- * @return equivalent value to getAttributeTypes().length
- */
- public int getAttributeCount(){
- return featureType.getAttributeCount();
- }
-
-
- /**
- * Gets the attributeType at this xPath, if the specified attributeType
- * does not exist then null is returned.
- *
- * @param xPath XPath pointer to attribute type.
- *
- * @return True if attribute exists.
- */
- public AttributeType getAttributeType(String xPath) {
- return featureType.getAttributeType(xPath);
- }
-
- /**
- * Find the position of a given AttributeType.
- *
- * @param type The type to search for.
- *
- * @return -1 if not found, a zero-based index if found.
- */
- public int find(AttributeType type) {return featureType.find(type);
- }
-
- /**
- * Find the position of an AttributeType which matches the given String.
- * @param attName the name to look for
- * @return -1 if not found, zero-based index otherwise
- */
- public int find(String attName) {
- return featureType.find(attName);
- }
-
- /**
- * Gets the attributeType at the specified index.
- *
- * @param position the position of the attribute to check.
- *
- * @return The attribute type at the specified position.
- */
- public AttributeType getAttributeType(int position) {
- return featureType.getAttributeType(position);
- }
-
- public AttributeType[] getAttributeTypes() {
- return featureType.getAttributeTypes();
- }
-}
Deleted: geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/type/GeometricAttributeType.java
===================================================================
--- geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/type/GeometricAttributeType.java 2007-10-01 00:43:34 UTC (rev 27293)
+++ geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/type/GeometricAttributeType.java 2007-10-01 00:46:16 UTC (rev 27294)
@@ -1,188 +0,0 @@
-/*
- * GeoTools - OpenSource mapping toolkit
- * http://geotools.org
- * (C) 2004-2006, GeoTools Project Managment Committee (PMC)
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation;
- * version 2.1 of the License.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- */
-package org.geotools.feature.type;
-
-import java.util.Collections;
-
-import org.geotools.feature.DefaultAttributeType;
-import org.geotools.feature.GeometryAttributeType;
-import org.geotools.feature.IllegalAttributeException;
-import org.geotools.geometry.jts.JTS;
-import org.opengis.feature.type.AttributeType;
-import org.opengis.feature.type.GeometryType;
-import org.opengis.feature.type.Name;
-import org.opengis.filter.Filter;
-import org.geotools.referencing.crs.DefaultGeocentricCRS;
-import org.opengis.referencing.crs.CoordinateReferenceSystem;
-
-import com.vividsolutions.jts.geom.Coordinate;
-import com.vividsolutions.jts.geom.Envelope;
-import com.vividsolutions.jts.geom.Geometry;
-import com.vividsolutions.jts.geom.GeometryCollection;
-import com.vividsolutions.jts.geom.GeometryFactory;
-import com.vividsolutions.jts.geom.LinearRing;
-import com.vividsolutions.jts.geom.PrecisionModel;
-import com.vividsolutions.jts.io.WKTReader;
-
-/**
- * Provides ...TODO summary sentence
- * <p>
- * TODO Description
- * </p><p>
- * </p><p>
- * Example Use:<pre><code>
- * GeometryAttributeType x = new GeometryAttributeType( ... );
- * TODO code example
- * </code></pre>
- * </p>
- * @author Leprosy
- * @since 0.3
- * TODO: test wkt geometry parse.
- * @source $URL$
- *
- * @deprecated use {@link GeometryTypeImpl}.
- *
- */
-public class GeometricAttributeType extends DefaultAttributeType implements org.geotools.feature.GeometryAttributeType{
- /** CoordianteSystem used by this GeometryAttributeType */
- //protected CoordinateReferenceSystem crs;
- protected GeometryFactory geometryFactory;
-
-
- public GeometricAttributeType(String name, Class type, boolean nillable, int min, int max,
- Object defaultValue, CoordinateReferenceSystem crs, Filter filter) {
- super(createAttributeType(name, type, crs,filter), name, nillable,min,max,defaultValue);
-
- geometryFactory = getCoordinateSystem() == null ?
- CSGeometryFactory.DEFAULT : new CSGeometryFactory(getCoordinateSystem());
-
- /*
- coordinateSystem = (cs != null) ? cs : LocalCoordinateSystem.CARTESIAN;
- geometryFactory = (cs == LocalCoordinateSystem.CARTESIAN)
- ? CSGeometryFactory.DEFAULT : new CSGeometryFactory(cs);
- */
- }
-
- public GeometricAttributeType(String name, Class type, boolean nillable,
- Object defaultValue, CoordinateReferenceSystem cs,Filter filter) {
- this(name, type, nillable,1,1, defaultValue, cs,filter);
- }
-
- public GeometricAttributeType(GeometricAttributeType copy, CoordinateReferenceSystem override) {
- this( copy.getLocalName(), copy.getBinding(), copy.isNillable(), copy.getMinOccurs(),copy.getMaxOccurs(), null, crs(override), copy.getRestriction() );
-
-
- geometryFactory = (getCoordinateSystem() == DefaultGeocentricCRS.CARTESIAN)
- ? CSGeometryFactory.DEFAULT : new CSGeometryFactory(getCoordinateSystem());
- }
-
-
- protected GeometricAttributeType(GeometryType type, Name name, int min, int max, boolean isNillable,Object defaultValue) {
- super(type, name, min, max, isNillable,defaultValue);
- }
-
- public GeometryType getType() {
- return (GeometryType) super.getType();
- }
-
- public CoordinateReferenceSystem getCoordinateSystem() {
- return ((GeometryType)getType()).getCRS();
- }
-
- public GeometryFactory getGeometryFactory() {
- return geometryFactory;
- }
-
-
- public Object duplicate(Object o) throws IllegalAttributeException {
- if (o == null)
- return o;
- if (o instanceof Geometry) {
- return ((Geometry)o).clone();
- }
- throw new IllegalAttributeException("Cannot duplicate " + o.getClass().getName());
- }
-
- public static CoordinateReferenceSystem crs( CoordinateReferenceSystem override ) {
- CoordinateReferenceSystem crs = override;
-
- if (override != null) {
- crs = override;
- }
-
- if (crs == null) {
- crs = DefaultGeocentricCRS.CARTESIAN;
- }
-
- return crs;
- }
-
- public static GeometryType createAttributeType(String name,Class binding,CoordinateReferenceSystem crs,Filter restriction) {
- return new GeometryTypeImpl(
- new org.geotools.feature.Name(name),binding,crs,false,false,
- restriction != null ? Collections.singletonList(restriction) : Collections.EMPTY_LIST,
- null,null);
- }
-}
-/**
- * Helper class used to force CS information on JTS Geometry
- */
-class CSGeometryFactory extends GeometryFactory {
-
- static public GeometryFactory DEFAULT = new GeometryFactory();
- static public PrecisionModel DEFAULT_PRECISON_MODEL = new PrecisionModel();
-
- public CSGeometryFactory(CoordinateReferenceSystem cs) {
- super(toPrecisionModel(cs), toSRID(cs));
- }
-
- public GeometryCollection createGeometryCollection(Geometry[] geometries) {
- GeometryCollection gc = super.createGeometryCollection(geometries);
-
- // JTS14
- //gc.setUserData( cs );
- return gc;
- }
-
- public LinearRing createLinearRing(Coordinate[] coordinates) {
- LinearRing lr = super.createLinearRing(coordinates);
-
- // JTS14
- //gc.setUserData( cs );
- return lr;
- }
-
- //
- // And so on
- // Utility Functions
- private static int toSRID(CoordinateReferenceSystem cs) {
- if ((cs == null) || (cs == DefaultGeocentricCRS.CARTESIAN)) {
- return 0;
- }
-
- // not sure how to tell SRID from CoordinateSystem?
- return 0;
- }
-
- private static PrecisionModel toPrecisionModel(CoordinateReferenceSystem cs) {
- if ((cs == null) || (cs == DefaultGeocentricCRS.CARTESIAN)) {
- return DEFAULT_PRECISON_MODEL;
- }
-
- return DEFAULT_PRECISON_MODEL;
- }
-}
-
Deleted: geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/type/ListAttributeType.java
===================================================================
--- geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/type/ListAttributeType.java 2007-10-01 00:43:34 UTC (rev 27293)
+++ geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/type/ListAttributeType.java 2007-10-01 00:46:16 UTC (rev 27294)
@@ -1,235 +0,0 @@
-/*
- * GeoTools - OpenSource mapping toolkit
- * http://geotools.org
- * (C) 2004-2006, GeoTools Project Managment Committee (PMC)
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation;
- * version 2.1 of the License.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- */
-package org.geotools.feature.type;
-
-import java.util.LinkedList;
-import java.util.List;
-
-import org.geotools.feature.AttributeType;
-import org.geotools.feature.DefaultAttributeType;
-import org.geotools.feature.IllegalAttributeException;
-import org.geotools.feature.Name;
-import org.opengis.filter.Filter;
-
-/**
- * Represents an ordered list of AttributeTypes. For SFS this will be a
- * FeatureType. For GML this is the same as an element whose complexType
- * contains a Sequence of Attributes.
- *
- * @author dzwiers
- * @source $URL$
- *
- * @deprecated Will be removed in geootols 2.6.
- */
-public class ListAttributeType extends AttributeDescriptorImpl implements AttributeType {
-
- private final AttributeType[] children;
-
- /**
- * @param copy
- */
- public ListAttributeType(ListAttributeType copy) {
- super(copy.getType(),copy.getName(),copy.getMinOccurs(),copy.getMaxOccurs(),copy.isNillable(),copy.getDefaultValue());
- children = copy.getAttributeTypes();
- }
-
- // The field for 'Class type' should be added when GT has moved to java 1.5
- public ListAttributeType(String name, boolean nillable, int min, int max,
- AttributeType[] children, Filter restriction) {
- super(DefaultAttributeType.createAttributeType(name, List.class, restriction),
- new Name(name),min,max,nillable,null);
- this.children = children;
- }
-
- public ListAttributeType(String name, boolean nillable,
- AttributeType[] children) {
- this(name, nillable, 1, 1, children,Filter.EXCLUDE);
- }
- public Filter getRestriction(){
- return DefaultAttributeType.getRestriction(this);
- }
-
- /**
- * {@inheritDoc}
- */
- public String getLocalName() {
- return DefaultAttributeType.getLocalName(this);
- }
-
- /**
- * {@inheritDoc}
- */
- public Class getBinding() {
- return DefaultAttributeType.getBinding(this);
- }
-
- /* (non-Javadoc)
- * @see org.geotools.feature.AttributeType#isGeometry()
- */
- public boolean isGeometry() {
- return false;
- }
-
- /* (non-Javadoc)
- * @see org.geotools.feature.AttributeType#parse(java.lang.Object)
- */
- public Object parse(Object value) throws IllegalArgumentException {
- if(value instanceof Object[]){
- Object[] in, out;
- in = (Object[])value;
- out = new Object[in.length];
- if(in.length == children.length){
- for(int i=0;i<children.length;i++){
- out[i] = children[i].parse(in[i]);
- }
- return out;
- }
- throw new IllegalArgumentException("Expected "+children.length+" Objects, got "+in.length+" Objects");
- }
- throw new IllegalArgumentException("Not an Object []");
- }
-
- /* (non-Javadoc)
- * @see org.geotools.feature.AttributeType#validate(java.lang.Object)
- */
- public void validate(Object obj) throws IllegalArgumentException {
- if(obj instanceof List){
- List in;
- in = (List)obj;
- if(in.size() == children.length){
- for(int i=0;i<children.length;i++){
- children[i].validate(in.get(i));
- }
- return;
- }
- throw new IllegalArgumentException("Expected "+children.length+" Objects, got "+in.size()+" Objects");
- }
- throw new IllegalArgumentException("Not an Object []");
-
- }
-
- /* (non-Javadoc)
- * @see org.geotools.feature.AttributeType#duplicate(java.lang.Object)
- */
- public Object duplicate(Object src) throws IllegalAttributeException {
- if(src instanceof List){
- List in,out;
- in = (List)src;
- out = new LinkedList();
- if(in.size() == children.length){
- for(int i=0;i<children.length;i++){
- out.add(i, children[i].duplicate(in.get(i)));
- }
- return out;
- }
- throw new IllegalArgumentException("Expected "+children.length+" Objects, got "+in.size()+" Objects");
- }
- throw new IllegalArgumentException("Not an Object []");
- }
-
- /* (non-Javadoc)
- * @see org.geotools.feature.AttributeType#createDefaultValue()
- */
- public Object createDefaultValue() {
- List out;
- out = new LinkedList();
- for(int i=0;i<children.length;i++){
- out.add(i, children[i].createDefaultValue());
- }
- return out;
- }
-
- /**
- * This is only used twice in the whole geotools code base, and one of
- * those is for a test, so we're removing it from the interface. If
- * getAttributeType does not have the AttributeType it will just return
- * null. Gets the number of occurrences of this attribute.
- *
- * @param xPath XPath pointer to attribute type.
- *
- * @return Number of occurrences.
- */
- public boolean hasAttributeType(String xPath) {
- return getAttributeType(xPath) != null;
- }
-
- /**
- * Returns the number of attributes at the first 'level' of the schema.
- *
- * @return equivalent value to getAttributeTypes().length
- */
- public int getAttributeCount(){
- return children.length;
- }
-
-
- /**
- * Gets the attributeType at this xPath, if the specified attributeType
- * does not exist then null is returned.
- *
- * @param xPath XPath pointer to attribute type.
- *
- * @return True if attribute exists.
- */
- public AttributeType getAttributeType(String xPath) {
- AttributeType attType = null;
- int idx = find(xPath);
- if (idx >= 0)
- attType = children[idx];
- return attType;
- }
-
- /**
- * Find the position of a given AttributeType.
- *
- * @param type The type to search for.
- *
- * @return -1 if not found, a zero-based index if found.
- */
- public int find(AttributeType type) {
- if (type == null) return -1;
- int idx = find(type.getLocalName());
- if (idx < 0 || !children[idx].equals(type))
- idx = -1;
- return idx;
- }
-
- /**
- * Find the position of an AttributeType which matches the given String.
- * @param attName the name to look for
- * @return -1 if not found, zero-based index otherwise
- */
- public int find(String attName) {
- int i=0;
- while(i<children.length && !attName.equals(children[i].getLocalName()))i++;
- return i == children.length?-1:i;
- }
-
- /**
- * Gets the attributeType at the specified index.
- *
- * @param position the position of the attribute to check.
- *
- * @return The attribute type at the specified position.
- */
- public AttributeType getAttributeType(int position) {
- return children[position];
- }
-
- public AttributeType[] getAttributeTypes() {
- return (AttributeType[]) children.clone();
- }
-}
Deleted: geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/type/NestedAttributeType.java
===================================================================
--- geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/type/NestedAttributeType.java 2007-10-01 00:43:34 UTC (rev 27293)
+++ geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/type/NestedAttributeType.java 2007-10-01 00:46:16 UTC (rev 27294)
@@ -1,76 +0,0 @@
-/*
- * GeoTools - OpenSource mapping toolkit
- * http://geotools.org
- * (C) 2004-2006, GeoTools Project Managment Committee (PMC)
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation;
- * version 2.1 of the License.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- */
-package org.geotools.feature.type;
-
-import org.geotools.feature.AttributeType;
-import org.opengis.filter.Filter;
-
-/**
- * This level of inheritance is intended for documentation purposes ...
- * so read carefully :).
- *
- * A nested Attribute is equivalent to a weak feature, or a feature without a Fid.
- * This distinction is important because there is very little difference between
- * a Java Bean and a nested Attribute, except the existance of this class.
- * This class is a simplified version of the XML schema which would be used to
- * represent this object as XML.
- *
- * The other subtle divergence between a Nested Attribute, and a Feature is the
- * idea that a Feature can be translated into and out of GML, while a Nested
- * Attribute is really just a typed Object. Much of what is represented within
- * the Nested Attribute and NestedAttributeType can, and is duplicated in many
- * bean2xml and xml2bean libraries (they use introspection ... we declare it in
- * a human readable form).
- *
- * @author dzwiers
- *
- * @source $URL$
- *
- * @deprecated Will be removed in geotools 2.6.
- */
-public class NestedAttributeType extends ListAttributeType {
-
- /**
- * super(copy)
- * @param copy
- */
- public NestedAttributeType(NestedAttributeType copy) {
- super(copy);
- }
-
- /**
- * @param name
- * @param nillable
- * @param min
- * @param max
- * @param children
- */
- public NestedAttributeType(String name, boolean nillable, int min, int max,
- AttributeType[] children, Filter restriction) {
- super(name, nillable, min, max, children, restriction);
- }
-
- /**
- * @param name
- * @param nillable
- * @param children
- */
- public NestedAttributeType(String name, boolean nillable,
- AttributeType[] children) {
- super(name, nillable, children);
- }
-
-}
Deleted: geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/type/NumericAttributeType.java
===================================================================
--- geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/type/NumericAttributeType.java 2007-10-01 00:43:34 UTC (rev 27293)
+++ geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/type/NumericAttributeType.java 2007-10-01 00:46:16 UTC (rev 27294)
@@ -1,95 +0,0 @@
-/*
- * GeoTools - OpenSource mapping toolkit
- * http://geotools.org
- * (C) 2004-2006, GeoTools Project Managment Committee (PMC)
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation;
- * version 2.1 of the License.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- */
-package org.geotools.feature.type;
-
-import java.math.BigDecimal;
-import java.math.BigInteger;
-import org.geotools.feature.DefaultAttributeType;
-import org.geotools.feature.PrimativeAttributeType;
-import org.opengis.filter.Filter;
-
-/**
- * Class that represents a Numeric.
- *
- * @author Ian Schneider
- * @author Chris Holmes, TOPP
- * @source $URL$
- */
-public class NumericAttributeType extends DefaultAttributeType implements PrimativeAttributeType {
- /**
- * Constructor with name, type and nillable. Type should always be a
- * Number class.
- *
- * @param name Name of this attribute.
- * @param type Class type of this attribute.
- * @param nillable If nulls are allowed for the attribute of this type.
- * @param min
- * @param max
- * @param defaultValue default value when none is suppled
- * @param filter
- *
- * @throws IllegalArgumentException is type is not a Number.
- *
- * @task REVISIT: protected?
- */
- public NumericAttributeType(String name,
- Class type,
- boolean nillable,
- int min,
- int max,
- Object defaultValue,
- Filter filter)
- throws IllegalArgumentException {
- super(name, type, nillable, min, max, defaultValue);
- this.filter = filter;
- if (!Number.class.isAssignableFrom(type)) {
- throw new IllegalArgumentException(
- "Numeric requires Number class, " + "not " + type);
- }
- }
- private Filter filter;
- public NumericAttributeType(String name, Class type, boolean nillable,
- Object defaultValue,Filter filter)
- throws IllegalArgumentException {
- super(name, type, nillable, defaultValue);
- this.filter = filter;
- if (!Number.class.isAssignableFrom(type)) {
- throw new IllegalArgumentException(
- "Numeric requires Number class, " + "not " + type);
- }
- }
-
- /**
- * Duplicate the given Object. In this case, since Number classes are
- * immutable, lets return the Object.
- *
- * @param o DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public Object duplicate(Object o) {
- return o;
- }
-
- /* (non-Javadoc)
- * @see org.geotools.feature.PrimativeAttributeType#getRestriction()
- */
- public Filter getRestriction() {
- return filter;
- }
-
-
-}
Deleted: geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/type/SetAttributeType.java
===================================================================
--- geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/type/SetAttributeType.java 2007-10-01 00:43:34 UTC (rev 27293)
+++ geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/type/SetAttributeType.java 2007-10-01 00:46:16 UTC (rev 27294)
@@ -1,271 +0,0 @@
-/*
- * GeoTools - OpenSource mapping toolkit
- * http://geotools.org
- * (C) 2004-2006, GeoTools Project Managment Committee (PMC)
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation;
- * version 2.1 of the License.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- */
-package org.geotools.feature.type;
-
-import java.util.HashSet;
-import java.util.Set;
-
-import org.geotools.feature.AttributeType;
-import org.geotools.feature.DefaultAttributeType;
-import org.geotools.feature.IllegalAttributeException;
-import org.geotools.feature.Name;
-import org.opengis.filter.Filter;
-
-/**
- * Represents an un-ordered Set of AttributeTypes. For SFS this should not be used.
- * For GML this is the same as an element whose complexType contains a
- * All of Attributes.
- *
- * NOTE: Some of the methods in this class has nasty order-dependant assumptions, please fix.
- *
- * @author dzwiers
- * @source $URL$
- *
- * @deprecated Will be removed from Geotools 2.6.
- */
-public class SetAttributeType extends AttributeDescriptorImpl
- implements AttributeType {
-
- private final AttributeType[] children;
-
-
- /**
- * @param copy
- */
- public SetAttributeType(SetAttributeType copy) {
- super(copy.getType(),copy.getName(),copy.getMinOccurs(),copy.getMaxOccurs(),copy.isNillable(),copy.getDefaultValue());
- children = copy.getAttributeTypes();
- }
-
- // The field for 'Class type' should be added when GT has moved to java 1.5
- public SetAttributeType(String name, boolean nillable, int min, int max,
- AttributeType[] children, Filter restriction) {
- super(DefaultAttributeType.createAttributeType(name, Set.class, restriction),
- new Name(name),min,max,nillable,null);
- this.children = children;
- }
-
- public SetAttributeType(String name, boolean nillable,
- AttributeType[] children) {
- this(name, nillable, 1, 1, children,Filter.EXCLUDE);
- }
- public Filter getRestriction(){
- return DefaultAttributeType.getRestriction(this);
- }
-
- /**
- * {@inheritDoc}
- */
- public String getLocalName() {
- return DefaultAttributeType.getLocalName(this);
- }
-
- /**
- * {@inheritDoc}
- */
- public Class getBinding() {
- return DefaultAttributeType.getBinding(this);
- }
-
- /* (non-Javadoc)
- * @see org.geotools.feature.AttributeType#isGeometry()
- */
- public boolean isGeometry() {
- return false;
- }
-
- /**
- * This method is unstable ... and does not yet check validity well.
- * TODO make this method robust
- *
- * This method assumes the Objects are in the order of the attributes.
- * In the future, this should be implemented with a bubble sort type
- * algorithm for testing each object vs each child. Bubble sort is
- * recommended as the sample size is typically less than 25 elements,
- * and the operation takes O(n*n) time.
- */
- public Object parse(Object value) throws IllegalArgumentException {
- if(value instanceof Set){
- Object[] in;
- in = ((Set)value).toArray();
- Set out = new HashSet(in.length);
- if(in.length == children.length){
- for(int i=0;i<children.length;i++){
- out.add(children[i].parse(in[i]));
- }
- return out;
- }
- throw new IllegalArgumentException("Expected "+children.length+" Objects, got "+in.length+" Objects");
- }
- throw new IllegalArgumentException("Not an Object []");
- }
-
- /**
- * This method is unstable ... and does not yet check validity well.
- * TODO make this method robust
- *
- * This method assumes the Objects are in the order of the attributes.
- * In the future, this should be implemented with a bubble sort type
- * algorithm for testing each object vs each child. Bubble sort is
- * recommended as the sample size is typically less than 25 elements,
- * and the operation takes O(n*n) time.
- *
- * Note that on the Attribute side of the fence ... this is acutally
- * an unordered List (a Set of elements, where each element has multiplicity ...)
- */
- public void validate(Object obj) throws IllegalArgumentException {
- if(obj instanceof Set){
- Object[] in;
- in = ((Set)obj).toArray();
- if(in.length == children.length){
- for(int i=0;i<children.length;i++){
- children[i].validate(in[i]);
- }
- return;
- }
- throw new IllegalArgumentException("Expected "+children.length+" Objects, got "+in.length+" Objects");
- }
- throw new IllegalArgumentException("Not an Object []");
-
- }
-
- /**
- * This method is unstable ... and does not yet check validity well.
- * TODO make this method robust
- *
- * This method assumes the Objects are in the order of the attributes.
- * In the future, this should be implemented with a bubble sort type
- * algorithm for testing each object vs each child. Bubble sort is
- * recommended as the sample size is typically less than 25 elements,
- * and the operation takes O(n*n) time.
- */
- public Object duplicate(Object src) throws IllegalAttributeException {
- if(src instanceof Set){
- Object[] in;
- in = ((Set)src).toArray();
- Set out = new HashSet(in.length);
- if(in.length == children.length){
- for(int i=0;i<children.length;i++){
- out.add( children[i].duplicate(in[i]));
- }
- return out;
- }
- throw new IllegalArgumentException("Expected "+children.length+" Objects, got "+in.length+" Objects");
- }
- throw new IllegalArgumentException("Not an Object []");
- }
-
-
- /**
- * This method is unstable ... and does not yet check validity well.
- * TODO make this method robust
- *
- * This method assumes the Objects are in the order of the attributes.
- * In the future, this should be implemented with a bubble sort type
- * algorithm for testing each object vs each child. Bubble sort is
- * recommended as the sample size is typically less than 25 elements,
- * and the operation takes O(n*n) time.
- */
- public Object createDefaultValue() {
- Set out = new HashSet(children.length);
- for(int i=0;i<children.length;i++){
- out.add( children[i].createDefaultValue());
- }
- return out;
- }
-
-
- /**
- * This is only used twice in the whole geotools code base, and one of
- * those is for a test, so we're removing it from the interface. If
- * getAttributeType does not have the AttributeType it will just return
- * null. Gets the number of occurrences of this attribute.
- *
- * @param xPath XPath pointer to attribute type.
- *
- * @return Number of occurrences.
- */
- public boolean hasAttributeType(String xPath) {
- return getAttributeType(xPath) != null;
- }
-
- /**
- * Returns the number of attributes at the first 'level' of the schema.
- *
- * @return equivalent value to getAttributeTypes().length
- */
- public int getAttributeCount(){
- return children.length;
- }
-
-
- /**
- * Gets the attributeType at this xPath, if the specified attributeType
- * does not exist then null is returned.
- *
- * @param xPath XPath pointer to attribute type.
- *
- * @return True if attribute exists.
- */
- public AttributeType getAttributeType(String xPath) {
- AttributeType attType = null;
- int idx = find(xPath);
- if (idx >= 0)
- attType = children[idx];
- return attType;
- }
-
- /**
- * Find the position of a given AttributeType.
- *
- * @param type The type to search for.
- *
- * @return -1 if not found, a zero-based index if found.
- */
- public int find(AttributeType type) {
- if (type == null) return -1;
- int idx = find(type.getLocalName());
- if (idx < 0 || !children[idx].equals(type))
- idx = -1;
- return idx;
- }
-
- /**
- * Find the position of an AttributeType which matches the given String.
- * @param attName the name to look for
- * @return -1 if not found, zero-based index otherwise
- */
- public int find(String attName) {
- int i=0;
- while(i<children.length && !attName.equals(children[i].getLocalName()))i++;
- return i == children.length?-1:i;
- }
-
- /**
- * Gets the attributeType at the specified index.
- *
- * @param position the position of the attribute to check.
- *
- * @return The attribute type at the specified position.
- */
- public AttributeType getAttributeType(int position) {
- return children[position];
- }
-
- public AttributeType[] getAttributeTypes() {
- return (AttributeType[]) children.clone();
- }
-}
Deleted: geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/type/TemporalAttributeType.java
===================================================================
--- geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/type/TemporalAttributeType.java 2007-10-01 00:43:34 UTC (rev 27293)
+++ geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/type/TemporalAttributeType.java 2007-10-01 00:46:16 UTC (rev 27294)
@@ -1,68 +0,0 @@
-/*
- * GeoTools - OpenSource mapping toolkit
- * http://geotools.org
- * (C) 2004-2006, GeoTools Project Managment Committee (PMC)
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation;
- * version 2.1 of the License.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- */
-package org.geotools.feature.type;
-
-import org.geotools.feature.DefaultAttributeType;
-import org.geotools.feature.IllegalAttributeException;
-import org.geotools.feature.PrimativeAttributeType;
-import org.geotools.util.Converters;
-import org.opengis.filter.Filter;
-
-import java.util.Date;
-
-/**
- * A Default class that represents a Temporal attribute.
- * @source $URL$
- */
-public class TemporalAttributeType extends DefaultAttributeType implements PrimativeAttributeType {
- // this might be right, maybe not, but anyway, its a default formatting
- static java.text.DateFormat format = java.text.DateFormat.getInstance();
-
- public TemporalAttributeType(String name, boolean nillable, int min,
- int max, Object defaultValue, Filter filter) {
- super(name, java.util.Date.class, nillable, min, max, defaultValue);
- this.filter = filter;
- }
- public TemporalAttributeType(String name, Class type, boolean nillable, int min, int max,
- Object defaultValue, Filter filter ) {
- super(name, type, nillable, min, max, defaultValue);
- this.filter = filter;
- }
-
- private Filter filter;
-
- public Object duplicate(Object o) throws IllegalAttributeException {
- if (o == null) {
- return null;
- }
-
- if (o instanceof Date) {
- Date d = (Date) o;
-
- return new Date(d.getTime());
- }
-
- throw new IllegalAttributeException("Cannot duplicate "
- + o.getClass().getName());
- }
-
- /* (non-Javadoc)
- * @see org.geotools.feature.PrimativeAttributeType#getRestriction()
- */
- public Filter getRestriction() {
- return filter;
- }
-}
Deleted: geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/type/TextualAttributeType.java
===================================================================
--- geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/type/TextualAttributeType.java 2007-10-01 00:43:34 UTC (rev 27293)
+++ geotools/trunk/gt/modules/library/main/src/main/java/org/geotools/feature/type/TextualAttributeType.java 2007-10-01 00:46:16 UTC (rev 27294)
@@ -1,56 +0,0 @@
-/*
- * GeoTools - OpenSource mapping toolkit
- * http://geotools.org
- * (C) 2004-2006, GeoTools Project Managment Committee (PMC)
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation;
- * version 2.1 of the License.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- */
-package org.geotools.feature.type;
-
-import org.geotools.feature.DefaultAttributeType;
-import org.geotools.feature.PrimativeAttributeType;
-import org.opengis.filter.Filter;
-
-
-/**
- *
- * @source $URL$
- */
-public class TextualAttributeType extends DefaultAttributeType implements PrimativeAttributeType {
- public TextualAttributeType(String name, boolean nillable, int min,
- int max, Object defaultValue, Filter filter) {
- super(name, String.class, nillable, min, max, defaultValue);
- this.filter = filter;
- }
- private Filter filter;
-
- /**
- * Duplicate as a String
- *
- * @param o DOCUMENT ME!
- *
- * @return a String obtained by calling toString or null.
- */
- public Object duplicate(Object o) {
- if (o == null) {
- return null;
- }
-
- return o.toString();
- }
-
- /* (non-Javadoc)
- * @see org.geotools.feature.PrimativeAttributeType#getRestriction()
- */
- public Filter getRestriction() {
- return filter;
- }
-}
Deleted: geotools/trunk/gt/modules/library/main/src/test/java/org/geotools/data/DummyFeatureType.java
===================================================================
--- geotools/trunk/gt/modules/library/main/src/test/java/org/geotools/data/DummyFeatureType.java 2007-10-01 00:43:34 UTC (rev 27293)
+++ geotools/trunk/gt/modules/library/main/src/test/java/org/geotools/data/DummyFeatureType.java 2007-10-01 00:46:16 UTC (rev 27294)
@@ -1,115 +0,0 @@
-/*
- * GeoTools - OpenSource mapping toolkit
- * http://geotools.org
- * (C) 2002-2006, Geotools Project Managment Committee (PMC)
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * Created on 20 novembre 2003, 21.31
- */
-package org.geotools.data;
-
-import java.net.URI;
-import java.util.Collections;
-
-import org.geotools.feature.FeatureType;
-import org.geotools.feature.GeometryAttributeType;
-import org.geotools.feature.Name;
-import org.geotools.feature.simple.SimpleFeatureTypeImpl;
-import org.opengis.feature.type.AttributeDescriptor;
-import org.opengis.feature.type.GeometryDescriptor;
-
-/**
- * An empty FeatureType implementation used in the AbstractDataSourceTest
- * @author wolf
- * @source $URL$
- */
-public class DummyFeatureType extends SimpleFeatureTypeImpl implements FeatureType {
- private String typeName;
-
- /** Creates a new instance of DummyFeatureType */
- public DummyFeatureType(String typeName) {
- super(new Name(typeName),Collections.EMPTY_LIST, (GeometryDescriptor) null, false, Collections.EMPTY_LIST, null, null);
- }
-
- public org.geotools.feature.Feature create(Object[] attributes) throws org.geotools.feature.IllegalAttributeException {
- return null;
- }
-
- public org.geotools.feature.Feature create(Object[] attributes, String featureID) throws org.geotools.feature.IllegalAttributeException {
- return null;
- }
-
- public org.geotools.feature.Feature duplicate(org.geotools.feature.Feature feature) throws org.geotools.feature.IllegalAttributeException {
- return null;
- }
-
- public int find(org.geotools.feature.AttributeType type) {
- return 0;
- }
-
- public FeatureType[] getAncestors() {
- return new FeatureType[] {};
- }
-
- public int getAttributeCount() {
- return 0;
- }
-
- public org.geotools.feature.AttributeType getAttributeType(String xPath) {
- return null;
- }
-
- public org.geotools.feature.AttributeType getAttributeType(int position) {
- return null;
- }
-
- public org.geotools.feature.AttributeType[] getAttributeTypes() {
- return new org.geotools.feature.AttributeType[] {};
- }
-
- public GeometryAttributeType getDefaultGeometry() {
- return null;
- }
-
- public URI getNamespace() {
- return null;
- }
-
- public String getTypeName() {
- return typeName;
- }
-
- public boolean hasAttributeType(String xPath) {
- return false;
- }
-
- public boolean isAbstract() {
- return true;
- }
-
- public boolean isDescendedFrom(FeatureType type) {
- return false;
- }
-
- public boolean isDescendedFrom(URI nsURI, String typeName) {
- return false;
- }
-
- /* (non-Javadoc)
- * @see org.geotools.feature.FeatureType#find(java.lang.String)
- */
- public int find(String attName) {
- // TODO Auto-generated method stub
- return 0;
- }
-
-}
Deleted: geotools/trunk/gt/modules/library/main/src/test/java/org/geotools/feature/AttributeTypeTest.java
===================================================================
--- geotools/trunk/gt/modules/library/main/src/test/java/org/geotools/feature/AttributeTypeTest.java 2007-10-01 00:43:34 UTC (rev 27293)
+++ geotools/trunk/gt/modules/library/main/src/test/java/org/geotools/feature/AttributeTypeTest.java 2007-10-01 00:46:16 UTC (rev 27294)
@@ -1,335 +0,0 @@
-/*
- * GeoTools - OpenSource mapping toolkit
- * http://geotools.org
- * (C) 2003-2006, Geotools Project Managment Committee (PMC)
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * Created on July 18, 2003, 12:56 PM
- */
-package org.geotools.feature;
-
-import java.math.BigDecimal;
-import java.math.BigInteger;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
-import com.vividsolutions.jts.geom.Geometry;
-import com.vividsolutions.jts.geom.Point;
-
-/**
- *
- * @author jamesm
- * @source $URL$
- */
-public class AttributeTypeTest extends TestCase {
-
- public AttributeTypeTest(java.lang.String testName) {
- super(testName);
- }
-
- public static void main(String[] args) {
- junit.textui.TestRunner.run(suite());
- }
-
- public static Test suite() {
- TestSuite suite = new TestSuite(AttributeTypeTest.class);
- return suite;
- }
-
- public void testAttributeTypeFactory(){
- AttributeType type = AttributeTypeFactory.newAttributeType("testAttribute", Double.class);
- assertNotNull(type);
- type = AttributeTypeFactory.newAttributeType("testAttribute", Double.class, true);
- assertNotNull(type);
- type = AttributeTypeFactory.newAttributeType("testAttribute", Double.class, false);
- assertNotNull(type);
- }
-
- public void testGetName(){
- AttributeType type = AttributeTypeFactory.newAttributeType("testAttribute", Double.class);
- assertEquals("testAttribute", type.getLocalName());
- }
-
- public void testGetType(){
- AttributeType type = AttributeTypeFactory.newAttributeType("testAttribute", Double.class);
- assertEquals(Double.class, type.getBinding());
- }
-
-
- public void testEquals(){
- AttributeType typeA = AttributeTypeFactory.newAttributeType("testAttribute", Double.class);
- AttributeType typeB = AttributeTypeFactory.newAttributeType("testAttribute", Double.class);
- AttributeType typeC = AttributeTypeFactory.newAttributeType("differnetName", Double.class);
- AttributeType typeD = AttributeTypeFactory.newAttributeType("testAttribute", Integer.class);
- AttributeType typeE = AttributeTypeFactory.newAttributeType(null, Integer.class);
- AttributeType typeF = AttributeTypeFactory.newAttributeType(null, Integer.class);
- assertTrue(typeA.equals(typeA));
- assertTrue(typeA.equals(typeB));
- assertTrue(typeE.equals(typeF));
- assertTrue(!typeA.equals(typeC));
- assertTrue(!typeA.equals(typeD));
- assertTrue(!typeA.equals(null));
- assertTrue(!typeA.equals(typeE));
- }
-
- public void testIsNillable(){
- AttributeType type = AttributeTypeFactory.newAttributeType("testAttribute", Double.class);
- assertEquals(true, type.isNillable());
- type = AttributeTypeFactory.newAttributeType("testAttribute", Double.class, true);
- assertEquals(true, type.isNillable());
- type = AttributeTypeFactory.newAttributeType("testAttribute", Double.class, false);
- assertEquals(false, type.isNillable());
- }
-
- public void testIsGeometry(){
- AttributeType type = AttributeTypeFactory.newAttributeType("testAttribute", Double.class);
- assertEquals(false, type instanceof GeometryAttributeType);
- type = AttributeTypeFactory.newAttributeType("testAttribute", Point.class);
- assertEquals(true, type instanceof GeometryAttributeType);
- type = AttributeTypeFactory.newAttributeType("testAttribute", Geometry.class);
- assertEquals(true, type instanceof GeometryAttributeType);
- }
-
- public void testValidate(){
- AttributeType type = AttributeTypeFactory.newAttributeType("testAttribute", Double.class, true);
- try{
- type.validate(new Double(3));
- }
- catch(IllegalArgumentException iae){
- fail();
- }
- try{
- type.validate(new Integer(3));
- fail("Integer should not be validated by a Double type");
- }
- catch(IllegalArgumentException iae){
-
- }
- try{
- type.validate(null);
- }
- catch(IllegalArgumentException iae){
- fail("null should have been allowed as type is Nillable");
- }
- type = AttributeTypeFactory.newAttributeType("testAttribute", Double.class, false);
- try{
- type.validate(null);
- type.validate((Double)null);
- fail("null should not have been allowed as type is not Nillable");
- }
- catch(IllegalArgumentException iae){
-
- }
-
-
- type = AttributeTypeFactory.newAttributeType("testAttribute", List.class, true);
- try{
- type.validate(new ArrayList());
- }
- catch(IllegalArgumentException iae){
- fail("decended types should be allowed");
- }
-
-
- }
-
- public void testFeatureConstruction() throws Exception {
- FeatureType a = FeatureTypeFactory.newFeatureType(new AttributeType[]{},"noAttribs");
- FeatureType b = FeatureTypeFactory.newFeatureType(new AttributeType[]{AttributeTypeFactory.newAttributeType("testAttribute", Double.class)},"oneAttribs");
- //Direct construction should never be used like this, however it is the only way to test
- //the code fully
- AttributeType feat = AttributeTypeFactory.newAttributeType( "good",a, false);
- }
-
- public void testFeatureValidate() throws SchemaException {
- try{
- //FeatureType b = FeatureTypeFactory.newFeatureType(new AttributeType[]{AttributeTypeFactory.newAttributeType("testAttribute", Double.class)},"oneAttribs");
-
- FeatureType type = FeatureTypeFactory.newFeatureType(new AttributeType[]{},"noAttribs");
- AttributeType feat = AttributeTypeFactory.newAttributeType("foo", type);
- Feature good = type.create(new Object[]{});
- feat.validate(good);
- }
- catch(IllegalAttributeException iae){
- fail();
- }
- Feature bad = null;
- FeatureType b = FeatureTypeFactory.newFeatureType(new AttributeType[]{AttributeTypeFactory.newAttributeType("testAttribute", Double.class)},"oneAttribs");
-
- try{
- bad = b.create(new Object[]{new Double(4)});
- }
- catch(IllegalAttributeException iae){
- fail();
- }
-
- try{
- FeatureType type = FeatureTypeFactory.newFeatureType(new AttributeType[]{},"noAttribs");
- AttributeType feat = AttributeTypeFactory.newAttributeType("foo", type);
- feat.validate(bad);
- fail();
- }
- catch(IllegalArgumentException iae){
-
- }
-
-
-
- }
-
-
- public void testNumericConstruction(){
- //Direct construction should never be used like this, however it is the only way to test
- //the code fully
- AttributeType num = AttributeTypeFactory.newAttributeType("good", Double.class, false, 0,new Double(0));
-
- try{
- num = AttributeTypeFactory.newAttributeType("bad", String.class, false,0,new Double(0));
- fail("Numeric type should not be constructable with type String");
- }
- catch(IllegalArgumentException iae){
- }
- }
-
-
- public void testIsNested(){
- AttributeType type = AttributeTypeFactory.newAttributeType("testAttribute", Double.class, true);
-// assertEquals(false, type.isNested());
- }
-
-
- public void testParse(){
- AttributeType type = AttributeTypeFactory.newAttributeType("testAttribute", Double.class, true);
- assertEquals(null, type.parse(null));
- assertEquals(new Double(1.1),(Double)type.parse(new Double(1.1)));
-
- type = AttributeTypeFactory.newAttributeType("testAttribute", Integer.class, true);
- assertEquals(new Integer(10),(Integer)type.parse(new Integer(10)));
-
- type = AttributeTypeFactory.newAttributeType("testAttribute", String.class, true);
- assertEquals("foo",type.parse("foo"));
-
- type = AttributeTypeFactory.newAttributeType("testAttribute", Number.class, true);
- assertEquals(3d,((Number)type.parse(new Long(3))).doubleValue(),0);
- assertEquals(4.4d,((Number)type.parse("4.4")).doubleValue(),0);
- type = AttributeTypeFactory.newAttributeType("testAttribute", Number.class, true);
-
-
- }
-
- public void testParseNumberSubclass() throws Exception {
-
- AttributeType type = AttributeTypeFactory.newAttributeType("testbigdecimal", BigDecimal.class,true);
-
- Object value = type.parse(new BigDecimal(111.111));
-
- // I modified this test to pass using BigDecimal. -IanS
-// assertEquals(new Double(111.111),value);
-// assertEquals(Double.class,value.getClass());
-
- assertEquals(new BigDecimal(111.111),value);
- assertEquals(BigDecimal.class,value.getClass());
- }
-
- public void testBigNumberSupport() throws Exception {
- AttributeType decimal = AttributeTypeFactory.newAttributeType("decimal", BigDecimal.class,true);
- AttributeType integer = AttributeTypeFactory.newAttributeType("integer", BigInteger.class,true);
-
- BigDecimal decimalValue = new BigDecimal("200");
- BigInteger integerValue = new BigInteger("200");
- Object[] vals = new Object[] {
- "200",
- new Integer(200),
- new Double(200),
- new Long(200),
- decimalValue
- };
-
-
- // BigDecimal tests
- for (int i = 0, ii = vals.length; i < ii; i++) {
- checkNumericAttributeSetting(decimal, vals[i], decimalValue);
- }
-
-
- // BigInteger tests
- for (int i = 0, ii = vals.length; i < ii; i++) {
- checkNumericAttributeSetting(decimal, vals[i], integerValue);
- }
-
- checkNull(decimal);
- checkNull(integer);
- }
-
- private void checkNull(AttributeType type) {
- if (type.isNillable()) {
- assertNull(type.parse(null));
- type.validate(null);
- }
- }
-
- private void checkNumericAttributeSetting(AttributeType type,Object value,Number expected) {
- Number parsed = (Number) type.parse(value);
- type.validate(parsed);
- assertEquals(parsed.intValue(),expected.intValue());
- }
-
- public void testTextualSupport() throws Exception {
- AttributeType textual = AttributeTypeFactory.newAttributeType("textual",String.class,true);
-
- Object[] vals = new Object[] {
- "stringValue",
- new StringBuffer("stringValue"),
- new Date(System.currentTimeMillis()),
- new Long(1000000)
- };
- for (int i = 0, ii = vals.length; i < ii; i++) {
- Object p = textual.parse(vals[i]);
- textual.validate(p);
- assertEquals(p.getClass(),String.class);
- }
-
- checkNull(textual);
- }
-
- public void textTemporalSupport() throws Exception {
- AttributeType temporal = AttributeTypeFactory.newAttributeType("temporal",Date.class,true);
-
- Date d = new Date();
-
- Object[] vals = new Object[] {
- new String(d.toString()),
- new Date(),
- new Long(d.getTime())
- };
-
- for (int i = 0, ii = vals.length; i < ii; i++) {
- checkTemporalAttributeSetting(temporal, vals[i], d);
- }
-
- checkNull(temporal);
- }
-
- private void checkTemporalAttributeSetting(AttributeType type,Object value,Date expected) {
- Object p = type.parse(value);
- type.validate(p);
- assertEquals(expected,p);
- }
-
-
-
-}
Deleted: geotools/trunk/gt/modules/library/main/src/test/java/org/geotools/feature/ChoiceAttrTypeTest.java
===================================================================
--- geotools/trunk/gt/modules/library/main/src/test/java/org/geotools/feature/ChoiceAttrTypeTest.java 2007-10-01 00:43:34 UTC (rev 27293)
+++ geotools/trunk/gt/modules/library/main/src/test/java/org/geotools/feature/ChoiceAttrTypeTest.java 2007-10-01 00:46:16 UTC (rev 27294)
@@ -1,348 +0,0 @@
-/*
- * GeoTools - OpenSource mapping toolkit
- * http://geotools.org
- * (C) 2003-2006, Geotools Project Managment Committee (PMC)
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- */
-package org.geotools.feature;
-
-import com.vividsolutions.jts.geom.Geometry;
-import com.vividsolutions.jts.geom.Point;
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-import org.geotools.feature.type.FeatureAttributeType;
-import java.math.BigDecimal;
-import java.math.BigInteger;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-import java.util.logging.Logger;
-
-
-/**
- * Tests for the Choice attribute.
- *
- * @author Chris Holmes, TOPP
- * @source $URL$
- */
-public class ChoiceAttrTypeTest extends TestCase {
- /** The logger for the default core module. */
- private static final Logger LOGGER = Logger.getLogger(
- "org.geotools.feature");
-
- public ChoiceAttrTypeTest(java.lang.String testName) {
- super(testName);
- }
-
- public static void main(String[] args) {
- junit.textui.TestRunner.run(suite());
- }
-
- public static Test suite() {
- TestSuite suite = new TestSuite(ChoiceAttrTypeTest.class);
-
- return suite;
- }
-
- public void testAttributeTypeFactory() {
- //TODO: we have no ChoiceAttributeTypeFactory.
- }
-
- public void testGetName() {
- AttributeType type = SampleFeatureFixtures.getChoiceAttrType1();
- assertEquals("choiceTest1", type.getLocalName());
- }
-
- public void testGetType() {
- AttributeType type = SampleFeatureFixtures.getChoiceAttrType1();
- assertEquals(Object.class, type.getBinding());
- }
-
- public void testEquals() {
- AttributeType typeA = SampleFeatureFixtures.getChoiceAttrType1();
- LOGGER.finer("created: " + typeA);
-
- AttributeType typeB = SampleFeatureFixtures.getChoiceAttrType1();
- AttributeType typeC = SampleFeatureFixtures.getChoiceAttrType2();
- AttributeType typeD = SampleFeatureFixtures.getChoiceGeomType();
- AttributeType[] choices = SampleFeatureFixtures.createType1Choices();
- String nil = (String) null;
- AttributeType typeE = SampleFeatureFixtures.createChoiceAttrType(nil,
- choices);
- choices = SampleFeatureFixtures.createType1Choices();
- AttributeType typeF = SampleFeatureFixtures.createChoiceAttrType(nil,
- choices);
- assertTrue(typeA.equals(typeA));
- assertTrue(typeA.equals(typeB));
- assertTrue(typeE.equals(typeF));
- assertTrue(!typeA.equals(typeC));
- assertTrue(!typeA.equals(typeD));
- assertTrue(!typeA.equals(null));
- assertTrue(!typeA.equals(typeE));
- }
-
- public void testIsNillable() {
- AttributeType[] choices = SampleFeatureFixtures.createType1Choices();
-
-
- AttributeType type, type2;
- type = SampleFeatureFixtures.createChoiceAttrType("testAtt", choices);
- assertEquals(true, type.isNillable());
-
- choices[0] = AttributeTypeFactory.newAttributeType("testString", String.class, false);
- type2 = SampleFeatureFixtures.createChoiceAttrType("testAtt2", choices);
- //if one choice is nillable then the overall choice should be.
- assertEquals(true, type.isNillable());
- LOGGER.finer("type is: " + type + "\ntype2 is: " + type2);
- //a choice between two non nillable choices should not be nillable
- type = SampleFeatureFixtures.createChoiceAttrType("choiceTest2", choices);
- type = choices[1] = AttributeTypeFactory.newAttributeType("tester", String.class, false);
- assertEquals(false, type.isNillable());
- }
-
- public void testIsGeometry() {
- AttributeType type = SampleFeatureFixtures.getChoiceAttrType2();
- assertEquals(false, type instanceof GeometryAttributeType);
- type = SampleFeatureFixtures.getChoiceGeomType();
- assertEquals(true, type instanceof GeometryAttributeType);
- }
-
-
- public void testValidate(){
- AttributeType type = SampleFeatureFixtures.getChoiceAttrType1();
- try{
- type.validate(new Double(3));
- type.validate(new Byte((byte)3));
- type.validate("blorg");
- }
- catch(IllegalArgumentException iae){
- fail();
- }
- try{
- type.validate(new Integer(3));
- fail("Integer should not be validated by a Double type");
- }
- catch(IllegalArgumentException iae){
-
- }
- try{
- type.validate(null);
- }
- catch(IllegalArgumentException iae){
- fail("null should have been allowed as type is Nillable");
- }
- type = SampleFeatureFixtures.getChoiceAttrType2();
- try{
- type.validate(null);
- type.validate((String)null);
- fail("null should not have been allowed as type is not Nillable");
- }
- catch(IllegalArgumentException iae){
-
- }
-
-
- type = AttributeTypeFactory.newAttributeType("testAttribute", List.class, true);
- try{
- type.validate(new ArrayList());
- }
- catch(IllegalArgumentException iae){
- fail("decended types should be allowed");
- }
-
-
- }
-
-
- public void testFeatureConstruction() throws Exception {
- FeatureType a = SampleFeatureFixtures.createChoiceFeatureType();
-
- //FeatureType a = FeatureTypeFactory.newFeatureType(new AttributeType[]{},"noAttribs");
- //FeatureType b = FeatureTypeFactory.newFeatureType(new AttributeType[]{AttributeTypeFactory.newAttributeType("testAttribute", Double.class)},"oneAttribs");
- //Direct construction should never be used like this, however it is the only way to test `
- //the code fully
- //AttributeType feat = AttributeTypeFactory.newAttributeType( "good",a, false);
- }
-
- /* public void testFeatureValidate() throws SchemaException {
- try{
- //FeatureType b = FeatureTypeFactory.newFeatureType(new AttributeType[]{AttributeTypeFactory.newAttributeType("testAttribute", Double.class)},"oneAttribs");
-
- FeatureType type = FeatureTypeFactory.newFeatureType(new AttributeType[]{},"noAttribs");
- AttributeType feat = AttributeTypeFactory.newAttributeType("foo", type);
- Feature good = type.create(new Object[]{});
- feat.validate(good);
- }
- catch(IllegalAttributeException iae){
- fail();
- }
- Feature bad = null;
- FeatureType b = FeatureTypeFactory.newFeatureType(new AttributeType[]{AttributeTypeFactory.newAttributeType("testAttribute", Double.class)},"oneAttribs");
-
- try{
- bad = b.create(new Object[]{new Double(4)});
- }
- catch(IllegalAttributeException iae){
- fail();
- }
-
- try{
- FeatureType type = FeatureTypeFactory.newFeatureType(new AttributeType[]{},"noAttribs");
- AttributeType feat = AttributeTypeFactory.newAttributeType("foo", type);
- feat.validate(bad);
- fail();
- }
- catch(IllegalArgumentException iae){
-
- }
-
-
-
- }
-
-
- public void testNumericConstruction(){
- //Direct construction should never be used like this, however it is the only way to test
- //the code fully
- AttributeType num = AttributeTypeFactory.newAttributeType("good", Double.class, false, 0,new Double(0));
-
- try{
- num = AttributeTypeFactory.newAttributeType("bad", String.class, false,0,new Double(0));
- fail("Numeric type should not be constructable with type String");
- }
- catch(IllegalArgumentException iae){
- }
- }
-
-
- public void testIsNested(){
- AttributeType type = AttributeTypeFactory.newAttributeType("testAttribute", Double.class, true);
- // assertEquals(false, type.isNested());
- }
-
-
- public void testParse(){
- AttributeType type = AttributeTypeFactory.newAttributeType("testAttribute", Double.class, true);
- assertEquals(null, type.parse(null));
- assertEquals(new Double(1.1),(Double)type.parse(new Double(1.1)));
-
- type = AttributeTypeFactory.newAttributeType("testAttribute", Integer.class, true);
- assertEquals(new Integer(10),(Integer)type.parse(new Integer(10)));
-
- type = AttributeTypeFactory.newAttributeType("testAttribute", String.class, true);
- assertEquals("foo",type.parse("foo"));
-
- type = AttributeTypeFactory.newAttributeType("testAttribute", Number.class, true);
- assertEquals(3d,((Number)type.parse(new Long(3))).doubleValue(),0);
- assertEquals(4.4d,((Number)type.parse("4.4")).doubleValue(),0);
- type = AttributeTypeFactory.newAttributeType("testAttribute", Number.class, true);
-
-
- }
- public void testParseNumberSubclass() throws Exception {
-
- AttributeType type = AttributeTypeFactory.newAttributeType("testbigdecimal", BigDecimal.class,true);
- Object value = type.parse(new BigDecimal(111.111));
-
- // I modified this test to pass using BigDecimal. -IanS
- // assertEquals(new Double(111.111),value);
- // assertEquals(Double.class,value.getClass());
-
- assertEquals(new BigDecimal(111.111),value);
- assertEquals(BigDecimal.class,value.getClass());
- }
-
- public void testBigNumberSupport() throws Exception {
- AttributeType decimal = AttributeTypeFactory.newAttributeType("decimal", BigDecimal.class,true);
- AttributeType integer = AttributeTypeFactory.newAttributeType("integer", BigInteger.class,true);
- BigDecimal decimalValue = new BigDecimal(200);
- BigInteger integerValue = new BigInteger("200");
- Object[] vals = new Object[] {
- "200",
- new Integer(200),
- new Double(200),
- new Long(200),
- decimalValue
- };
-
-
- // BigDecimal tests
- for (int i = 0, ii = vals.length; i < ii; i++) {
- checkNumericAttributeSetting(decimal, vals[i], decimalValue);
- }
-
-
- // BigInteger tests
- for (int i = 0, ii = vals.length; i < ii; i++) {
- checkNumericAttributeSetting(decimal, vals[i], integerValue);
- }
-
- checkNull(decimal);
- checkNull(integer);
- }
-
- private void checkNull(AttributeType type) {
- if (type.isNillable()) {
- assertNull(type.parse(null));
- type.validate(null);
- }
- }
-
- private void checkNumericAttributeSetting(AttributeType type,Object value,Number expected) {
- Number parsed = (Number) type.parse(value);
- type.validate(parsed);
- assertEquals(parsed.intValue(),expected.intValue());
- }
-
- public void testTextualSupport() throws Exception {
- AttributeType textual = AttributeTypeFactory.newAttributeType("textual",String.class,true);
-
- Object[] vals = new Object[] {
- "stringValue",
- new StringBuffer("stringValue"),
- new Date(System.currentTimeMillis()),
- new Long(1000000)
- };
- for (int i = 0, ii = vals.length; i < ii; i++) {
- Object p = textual.parse(vals[i]);
- textual.validate(p);
- assertEquals(p.getClass(),String.class);
- }
-
- checkNull(textual);
- }
-
- public void textTemporalSupport() throws Exception {
- AttributeType temporal = AttributeTypeFactory.newAttributeType("temporal",Date.class,true);
-
- Date d = new Date();
-
- Object[] vals = new Object[] {
- new String(d.toString()),
- new Date(),
- new Long(d.getTime())
- };
-
- for (int i = 0, ii = vals.length; i < ii; i++) {
- checkTemporalAttributeSetting(temporal, vals[i], d);
- }
-
- checkNull(temporal);
- }
-
- private void checkTemporalAttributeSetting(AttributeType type,Object value,Date expected) {
- Object p = type.parse(value);
- type.validate(p);
- assertEquals(expected,p);
- }*/
-}
Modified: geotools/trunk/gt/modules/library/main/src/test/java/org/geotools/feature/FeatureCollectionTest.java
===================================================================
--- geotools/trunk/gt/modules/library/main/src/test/java/org/geotools/feature/FeatureCollectionTest.java 2007-10-01 00:43:34 UTC (rev 27293)
+++ geotools/trunk/gt/modules/library/main/src/test/java/org/geotools/feature/FeatureCollectionTest.java 2007-10-01 00:46:16 UTC (rev 27294)
@@ -108,7 +108,7 @@
SimpleFeatureBuilder b = new SimpleFeatureBuilder(t);
for (int i = 0; i < g.length; i++) {
- b.add( new Geometry[] {g[i]});
+ b.add( g[i]);
fc.add( b.buildFeature(null) );
}
assertEquals(gc.getEnvelopeInternal(),fc.getBounds());
Modified: geotools/trunk/gt/modules/library/main/src/test/java/org/geotools/feature/FeatureFlatTest.java
===================================================================
--- geotools/trunk/gt/modules/library/main/src/test/java/org/geotools/feature/FeatureFlatTest.java 2007-10-01 00:43:34 UTC (rev 27293)
+++ geotools/trunk/gt/modules/library/main/src/test/java/org/geotools/feature/FeatureFlatTest.java 2007-10-01 00:46:16 UTC (rev 27294)
@@ -105,16 +105,16 @@
tb.nillable(false).add( "jimmy", String.class );
SimpleFeatureType test = tb.buildFeatureType();
- try {
- SimpleFeatureBuilder.build(test, (Object[])null, null);
- fail("no error");
- } catch (IllegalAttributeException iae) {
- }
+// try {
+// SimpleFeatureBuilder.build(test, (Object[])null, null);
+// fail("no error");
+// } catch (IllegalAttributeException iae) {
+// }
try {
SimpleFeatureBuilder.build(test, new Object[32],null);
fail("no error");
- } catch (IllegalAttributeException iae) {
+ } catch (IllegalArgumentException iae) {
}
}
Deleted: geotools/trunk/gt/modules/library/main/src/test/java/org/geotools/feature/FeatureTypeFactoryTest.java
===================================================================
--- geotools/trunk/gt/modules/library/main/src/test/java/org/geotools/feature/FeatureTypeFactoryTest.java 2007-10-01 00:43:34 UTC (rev 27293)
+++ geotools/trunk/gt/modules/library/main/src/test/java/org/geotools/feature/FeatureTypeFactoryTest.java 2007-10-01 00:46:16 UTC (rev 27294)
@@ -1,149 +0,0 @@
-/*
- * GeoTools - OpenSource mapping toolkit
- * http://geotools.org
- * (C) 2003-2006, Geotools Project Managment Committee (PMC)
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * Created on July 14, 2003, 5:03 PM
- */
-package org.geotools.feature;
-
-import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.Method;
-import java.lang.reflect.Proxy;
-
-import junit.framework.TestCase;
-
-/**
- * This simply tests and demonstrates how to make a new feature factory.
- *
- * @author Ian Schneider
- * @source $URL$
- */
-public class FeatureTypeFactoryTest extends TestCase {
-
- public static void main(String[] args) {
- junit.textui.TestRunner.run(FeatureTypeFactoryTest.class);
- }
-
- public void testEmpty() {
- //an empty test so tests will pass
- //TODO: fix tests
- }
-
- public void disabledtestFeatureFactoryImpl() throws Exception {
- // set the system property...
- System.setProperty(FeatureTypeFactory.class.getName(), FactoryImpl.class.getName());
- // create a new instance
- FeatureTypeFactory factory = FeatureTypeFactory.newInstance("test");
- FeatureType type = factory.getFeatureType();
- Feature feature = type.create(null);
-
- // lets make sure the implentation is correct
- assertEquals(FactoryImpl.class , factory.getClass());
- // lets make sure the FeatureType produced is correct
- assertEquals(
- Proxy.getInvocationHandler(type).getClass(),
- ImplHandler.class
- );
- // lets make sure the FeatureType produces the correct Feature
- assertEquals(
- Proxy.getInvocationHandler(feature).getClass(),
- ImplHandler.class
- );
- }
-
- // Normally, you would just want to subclass DefaultFeatureTypeFactory and
- // override the method "createFeatureType" - thats it. You would return a
- // subclass of DefaultFeatureType, which, instead of creating an instance of
- // DefaultFeature, would create an instance of your special feature. This is
- // done by overriding DefaultFeatureType.create
- public static class FactoryImpl extends FeatureTypeFactory {
- private java.util.ArrayList attributeTypes = new java.util.ArrayList();
-
- protected void add(AttributeType type) throws IllegalArgumentException {
- attributeTypes.add(type);
- }
-
- protected void add(int idx, AttributeType type) throws ArrayIndexOutOfBoundsException, IllegalArgumentException {
- attributeTypes.add(idx,type);
- }
-
- protected FeatureType createFeatureType() {
- return featureTypeImpl();
- }
-
- protected FeatureType createAbstractType() {
- return featureTypeImpl();
- }
-
-
- public AttributeType get(int idx) throws ArrayIndexOutOfBoundsException {
- return (AttributeType) attributeTypes.get(idx);
- }
-
- public int getAttributeCount() {
- return attributeTypes.size();
- }
-
- protected AttributeType remove(int idx) throws ArrayIndexOutOfBoundsException {
- return (AttributeType) attributeTypes.remove(idx);
- }
-
- protected AttributeType remove(AttributeType type) {
- if (attributeTypes.remove(type))
- return type;
- return null;
- }
-
- protected AttributeType set(int idx, AttributeType type) throws ArrayIndexOutOfBoundsException, IllegalArgumentException {
- AttributeType former = get(idx);
- attributeTypes.set(idx,type);
- return former;
- }
- }
-
-
- // the following is tricky...but doesn't really matter much
-
- static FeatureType featureTypeImpl() {
- return (FeatureType) Proxy.newProxyInstance(
- // use this classloader!!!
- FeatureTypeFactory.class.getClassLoader(),
- new Class[] {FeatureType.class},
- new ImplHandler()
- );
- }
-
- static Feature featureImpl() {
- return (Feature) Proxy.newProxyInstance(
- // use this classloader!!!
- FeatureTypeFactory.class.getClassLoader(),
- new Class[] {Feature.class},
- new ImplHandler()
- );
- }
-
- // this is the "overriding" of the method 'create'.
- // all other method calls can just return null.
- static class ImplHandler implements InvocationHandler {
-
- public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
- if (method.getName().equals("create")) {
- return featureImpl();
- }
- return null;
- }
-
- }
-
-}
Deleted: geotools/trunk/gt/modules/library/main/src/test/java/org/geotools/feature/FeatureWrappedComplexTest.java
===================================================================
--- geotools/trunk/gt/modules/library/main/src/test/java/org/geotools/feature/FeatureWrappedComplexTest.java 2007-10-01 00:43:34 UTC (rev 27293)
+++ geotools/trunk/gt/modules/library/main/src/test/java/org/geotools/feature/FeatureWrappedComplexTest.java 2007-10-01 00:46:16 UTC (rev 27294)
@@ -1,168 +0,0 @@
-/*
- * GeoTools - OpenSource mapping toolkit
- * http://geotools.org
- * (C) 2002-2006, Geotools Project Managment Committee (PMC)
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- */
-package org.geotools.feature;
-
-import com.vividsolutions.jts.geom.Coordinate;
-import com.vividsolutions.jts.geom.Geometry;
-import com.vividsolutions.jts.geom.GeometryCollection;
-import com.vividsolutions.jts.geom.GeometryFactory;
-import com.vividsolutions.jts.geom.Point;
-import com.vividsolutions.jts.geom.PrecisionModel;
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
-import org.opengis.feature.simple.SimpleFeature;
-import org.opengis.util.Cloneable;
-import java.util.Collections;
-import java.util.List;
-import java.util.logging.Logger;
-
-/**
- * Provides testing for a special type of Feature a Simple Feature wrapped in
- * Complex clothing. Specifically DefaultFeature.WrappedComplex. It should return
- * Lists for all of its get Attributes, since that's what a complex feature does.
- *
- * @author Chris Holmes, TOPP
- * @source $URL:
- * http://svn.geotools.org/geotools/trunk/gt/modules/library/main/src/test/java/org/geotools/feature/FeatureWrappedComplexTest.java $
- */
-public class FeatureWrappedComplexTest extends TestCase {
- /** The logger for the default core module. */
- private static final Logger LOGGER = Logger.getLogger("org.geotools.feature");
-
- /** Feature on which to preform tests */
- private SimpleFeature testFeature = null;
- TestSuite suite = null;
-
- public FeatureWrappedComplexTest( String testName ) {
- super(testName);
- }
-
- public static void main( String[] args ) {
- org.geotools.util.Logging.GEOTOOLS.forceMonolineConsoleOutput();
- junit.textui.TestRunner.run(suite());
- }
-
- public static Test suite() {
- TestSuite suite = new TestSuite(FeatureWrappedComplexTest.class);
-
- return suite;
- }
-
- public void setUp() {
- SimpleFeature feature = (SimpleFeature) SampleFeatureFixtures.createFeature();
- // testFeature = feature.toComplex(); //this isn't in the api...yet.
-
- try {
- testFeature = new DefaultFeature.ComplexWrapper(feature);
- } catch (IllegalAttributeException iae) {
- throw new RuntimeException("programming error with wrapper");
- }
- }
-
- public void testAttributeAccess() throws Exception {
- // this ones kinda silly
- SimpleFeature f = testFeature;
-
- try {
- f.setAttribute(1244, Collections.singletonList("x"));
- fail("not out of bounds");
- } catch (ArrayIndexOutOfBoundsException aioobe) {
- } catch (IndexOutOfBoundsException aioobe) {
- }
-
- try {
- f.setAttribute("1244", "x");
- fail("allowed bogus attribute setting");
- } catch (IllegalAttributeException iae) {
- }
-
- try {
- f.setAttribute("testGeometry", "x");
- fail("allowed bogus attribute setting");
- } catch (IllegalAttributeException iae) {
- }
- }
-
- public void testWrappedAccessIndex() {
- int attrIndex = 5;
- SimpleFeature simple = SampleFeatureFixtures.createFeature();
- SimpleFeature wrapped = testFeature;
- Object intAtt = wrapped.getAttribute(attrIndex);
- LOGGER.info("simple is: " + simple + ", and wrapped is: " + wrapped);
- LOGGER.info("intAtt is: " + intAtt);
- assertTrue(intAtt instanceof List);
-
- List intAttList = (List) intAtt;
- assertTrue(intAttList.get(0).equals(simple.getAttribute(attrIndex)));
- }
-
- public void testWrappedAccessName() {
- String attName = "testCharacter";
- SimpleFeature simple = SampleFeatureFixtures.createFeature();
- SimpleFeature wrapped = testFeature;
- Object intAtt = wrapped.getAttribute(attName);
- assertTrue(intAtt instanceof List);
-
- List intAttList = (List) intAtt;
- assertTrue(intAttList.get(0).equals(simple.getAttribute(attName)));
- }
-
- public void testWrappedAccessAll() {
- SimpleFeature simple = SampleFeatureFixtures.createFeature();
- SimpleFeature wrapped = testFeature;
- List simpleAtts = simple.getAttributes();
- List complexAtts = wrapped.getAttributes();
- List curAttList = null;
-
- // we're starting at 1 because of the annoying equals with geometries,
- // and I don't want to figure out where the util method is...
- for( int i = 1; i < complexAtts.size(); i++ ) {
- assertTrue(complexAtts.get(i) instanceof List);
- curAttList = (List) complexAtts.get(i);
- assertEquals(1, curAttList.size());
- assertEquals(curAttList.get(0), (simpleAtts.get(i)));
- }
- }
-
- public void testModify() throws IllegalAttributeException {
- String newData = "new string";
-
- try {
- testFeature.setAttribute("testString", newData);
- fail("All objects should be wrapped in Lists for Complex Features");
- } catch (Exception iae) {
- assertTrue(iae instanceof IllegalAttributeException);
- }
-
- List singleNewData = Collections.singletonList(newData);
- testFeature.setAttribute("testString", singleNewData);
- assertEquals(testFeature.getAttribute("testString"), singleNewData);
-
- try {
- testFeature.setAttribute("testGeometry", singleNewData);
- fail("a wrapped string should not be able to set a geometry");
- } catch (Exception e) {
- // e.printStackTrace();
- assertTrue(e instanceof IllegalAttributeException);
- }
- }
-
- public void testEquals() throws Exception {
- // todo
- }
-}
Deleted: geotools/trunk/gt/modules/library/main/src/test/java/org/geotools/feature/FlatFeatureFactorySpiTest.java
===================================================================
--- geotools/trunk/gt/modules/library/main/src/test/java/org/geotools/feature/FlatFeatureFactorySpiTest.java 2007-10-01 00:43:34 UTC (rev 27293)
+++ geotools/trunk/gt/modules/library/main/src/test/java/org/geotools/feature/FlatFeatureFactorySpiTest.java 2007-10-01 00:46:16 UTC (rev 27294)
@@ -1,71 +0,0 @@
-/*
- * GeoTools - OpenSource mapping toolkit
- * http://geotools.org
- * (C) 2003-2006, Geotools Project Managment Committee (PMC)
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * Created on May 20, 2003, 11:26 AM
- */
-package org.geotools.feature;
-
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
-/**
- *
- * @author jamesm
- * @source $URL$
- */
-public class FlatFeatureFactorySpiTest extends TestCase {
-
- public FlatFeatureFactorySpiTest(java.lang.String testName) {
- super(testName);
- }
-
- public static Test suite() {
- TestSuite suite = new TestSuite(FlatFeatureFactorySpiTest.class);
- return suite;
- }
-
- public void testObtainFactory(){
- FeatureTypeFactory factory = FeatureTypeFactory.newInstance("test");
- assertNotNull(factory);
- }
-
- public void testDefaultFactory() {
- FeatureTypeFactory factory = FeatureTypeFactory.newInstance("test");
- AttributeType a1 = AttributeTypeFactory.newAttributeType("X",Integer.class);
- AttributeType a2 = AttributeTypeFactory.newAttributeType("Y",Double.class);
- factory.addType(0,a1);
- assertEquals(a1, factory.get(factory.getAttributeCount() - 1));
- factory.addType(1,a2);
- assertEquals(a2, factory.get(factory.getAttributeCount() - 1));
- factory.removeType(1);
- factory.removeType(0);
- assertEquals(factory.getAttributeCount(),0);
- factory.addType(a1);
- factory.addType(a2);
- factory.swap(0,1);
- assertEquals(a1, factory.get(1));
- assertEquals(a2, factory.get(0));
- factory.removeType(a1);
- factory.removeType(a2);
- assertEquals(factory.getAttributeCount(),0);
- }
-
- public static void main(String[] args) {
- junit.textui.TestRunner.run(suite());
- }
-
-
-}
Modified: geotools/trunk/gt/modules/library/pom.xml
===================================================================
--- geotools/trunk/gt/modules/library/pom.xml 2007-10-01 00:43:34 UTC (rev 27293)
+++ geotools/trunk/gt/modules/library/pom.xml 2007-10-01 00:46:16 UTC (rev 27294)
@@ -58,6 +58,7 @@
<module>referencing</module>
<module>coverage</module>
<module>api</module>
+ <module>legacy</module>
<module>main</module>
<module>data</module>
<module>sample-data</module>
Modified: geotools/trunk/gt/modules/library/xml/src/main/java/org/geotools/xml/gml/ChoiceAttributeTypeImpl.java
===================================================================
--- geotools/trunk/gt/modules/library/xml/src/main/java/org/geotools/xml/gml/ChoiceAttributeTypeImpl.java 2007-10-01 00:43:34 UTC (rev 27293)
+++ geotools/trunk/gt/modules/library/xml/src/main/java/org/geotools/xml/gml/ChoiceAttributeTypeImpl.java 2007-10-01 00:46:16 UTC (rev 27294)
@@ -1,29 +1,17 @@
package org.geotools.xml.gml;
+import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.geotools.data.DataUtilities;
-import org.geotools.feature.DefaultAttributeType;
-import org.geotools.feature.type.AttributeDescriptorImpl;
import org.geotools.feature.type.AttributeTypeImpl;
-import org.geotools.feature.type.GeometricAttributeType;
import org.geotools.util.SimpleInternationalString;
import org.opengis.feature.type.AttributeType;
import org.opengis.feature.type.Name;
import org.opengis.filter.Filter;
-import org.opengis.referencing.crs.CoordinateReferenceSystem;
import org.opengis.util.InternationalString;
-import com.vividsolutions.jts.geom.GeometryCollection;
-import com.vividsolutions.jts.geom.GeometryFactory;
-import com.vividsolutions.jts.geom.LineString;
-import com.vividsolutions.jts.geom.MultiLineString;
-import com.vividsolutions.jts.geom.MultiPoint;
-import com.vividsolutions.jts.geom.MultiPolygon;
-import com.vividsolutions.jts.geom.Point;
-import com.vividsolutions.jts.geom.Polygon;
-
/**
* Created for GML generated FeatureTypes. Represents a Choice type.
*
@@ -33,7 +21,7 @@
* @author Jesse
*/
class ChoiceAttributeTypeImpl extends AttributeTypeImpl implements ChoiceAttributeType {
-
+ private static final Class[] EMPTY = new Class[0];
protected Class[] types;
private boolean isNillable;
private int maxOccurs;
@@ -51,7 +39,7 @@
}
public Class[] getChoices() {
- return types;
+ return EMPTY;
}
public Object convert(Object obj) {
return obj;
Modified: geotools/trunk/gt/modules/library/xml/src/main/java/org/geotools/xml/gml/ChoiceGeometryTypeImpl.java
===================================================================
--- geotools/trunk/gt/modules/library/xml/src/main/java/org/geotools/xml/gml/ChoiceGeometryTypeImpl.java 2007-10-01 00:43:34 UTC (rev 27293)
+++ geotools/trunk/gt/modules/library/xml/src/main/java/org/geotools/xml/gml/ChoiceGeometryTypeImpl.java 2007-10-01 00:46:16 UTC (rev 27294)
@@ -1,10 +1,5 @@
package org.geotools.xml.gml;
-import org.geotools.feature.DefaultAttributeType;
-import org.geotools.feature.type.AttributeDescriptorImpl;
-import org.geotools.feature.type.GeometricAttributeType;
-import org.geotools.feature.type.GeometryDescriptorImpl;
-import org.opengis.feature.type.AttributeType;
import org.opengis.feature.type.GeometryType;
import org.opengis.feature.type.Name;
import org.opengis.filter.Filter;
|