org.geotools.feature
Class DefaultFeatureType

java.lang.Object
  extended byorg.geotools.feature.DefaultFeatureType
All Implemented Interfaces:
FeatureType
Direct Known Subclasses:
SimpleFeatureType

public class DefaultFeatureType
extends java.lang.Object
implements FeatureType

A basic implementation of FeatureType.

Version:
$Id: DefaultFeatureType.java 17701 2006-01-23 00:00:51Z desruisseaux $
Author:
Ian Schneider

Field Summary
static FeatureType EMPTY
          An feature type with no attributes
 
Constructor Summary
DefaultFeatureType(java.lang.String typeName, java.lang.String namespace, java.util.Collection types, java.util.Collection superTypes, GeometryAttributeType defaultGeom)
           
DefaultFeatureType(java.lang.String typeName, java.net.URI namespace, java.util.Collection types, java.util.Collection superTypes, GeometryAttributeType defaultGeom)
          Constructs a new DefaultFeatureType.
 
Method Summary
 Feature create(java.lang.Object[] attributes)
          Creates a new feature, with a generated unique featureID.
 Feature create(java.lang.Object[] attributes, java.lang.String featureID)
          Creates a new feature, with the proper featureID, using this FeatureType.
 Feature duplicate(Feature original)
          Create a duplicate of the provided feature, must delegate to an appropriate FeatureFactory create method.
 boolean equals(FeatureType other)
           
 boolean equals(java.lang.Object other)
          FeatureType check based on namespace, typeName, attributes and ancestors.
 int find(AttributeType type)
          Find the position of a given AttributeType.
 int find(java.lang.String attName)
          Find the position of an AttributeType which matches the given String.
 FeatureType[] getAncestors()
          Obtain an array of this FeatureTypes ancestors.
 int getAttributeCount()
          Returns the number of attributes at the first 'level' of the schema.
 AttributeType getAttributeType(int position)
          Gets the attributeType at the specified index.
 AttributeType getAttributeType(java.lang.String xPath)
          Gets the attributeType at this xPath, if the specified attributeType does not exist then null is returned.
 AttributeType[] getAttributeTypes()
          AttributeTypes for this FeatureType, all attributes defined by this FeatureType and its super types define schema for feature instances.
 GeometryAttributeType getDefaultGeometry()
          Gets the default geometry AttributeType.
 java.net.URI getNamespace()
          Gets the global schema namespace.
 java.lang.String getTypeName()
          Gets the type name for this schema.
 boolean hasAttributeType(java.lang.String xPath)
          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.
 int hashCode()
          Hascode based on namespace, typeName, attributes and ancestors.
 boolean isAbstract()
          Is this FeatureType an abstract type?
 boolean isDescendedFrom(FeatureType type)
          A convenience method for calling
FeatureType f1; FeatureType f2; f1.isDescendedFrom(f2.getNamespace(),f2.getName());
 boolean isDescendedFrom(java.net.URI nsURI, java.lang.String typeName1)
          Test to determine whether this FeatureType is descended from the given FeatureType.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

EMPTY

public static final FeatureType EMPTY
An feature type with no attributes

Constructor Detail

DefaultFeatureType

public DefaultFeatureType(java.lang.String typeName,
                          java.lang.String namespace,
                          java.util.Collection types,
                          java.util.Collection superTypes,
                          GeometryAttributeType defaultGeom)
                   throws SchemaException,
                          java.lang.NullPointerException

DefaultFeatureType

public DefaultFeatureType(java.lang.String typeName,
                          java.net.URI namespace,
                          java.util.Collection types,
                          java.util.Collection superTypes,
                          GeometryAttributeType defaultGeom)
                   throws java.lang.NullPointerException
Constructs a new DefaultFeatureType.

Attributes from the superTypes will be copied to the list of attributes for this feature type.

Parameters:
typeName - The name to give this FeatureType.
namespace - The namespace of the new FeatureType.
types - The attributeTypes to use for validation.
superTypes - The ancestors of this FeatureType.
defaultGeom - The attributeType to set as the defaultGeometry.
Throws:
SchemaException - For problems making the FeatureType.
java.lang.NullPointerException - If typeName is null.
Method Detail

create

public Feature create(java.lang.Object[] attributes)
               throws IllegalAttributeException
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.

Specified by:
create in interface FeatureType
Parameters:
attributes - the array of attribute values
Returns:
The created feature with this as its feature type.
Throws:
IllegalAttributeException - if this FeatureType does not validate the attributes.

create

public Feature create(java.lang.Object[] attributes,
                      java.lang.String featureID)
               throws IllegalAttributeException
Creates a new feature, with the proper featureID, using this FeatureType.

Specified by:
create in interface FeatureType
Parameters:
attributes - the array of attribute values.
featureID - the feature ID.
Returns:
the created feature.
Throws:
IllegalAttributeException - if this FeatureType does not validate the attributes.

duplicate

public Feature duplicate(Feature original)
                  throws IllegalAttributeException
Description copied from interface: FeatureType
Create a duplicate of the provided feature, must delegate to an appropriate FeatureFactory create method.

The implementation is assumed to make use of AttributeType duplicate as required for a deep copy.

//@deprecated This method will be removed in 2.2, please use FeatureFactory obtained from FactoryFinder

Specified by:
duplicate in interface FeatureType
Parameters:
original -
Returns:
a deep copy of feature
Throws:
IllegalAttributeException

getDefaultGeometry

public GeometryAttributeType getDefaultGeometry()
Gets the default 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.

Specified by:
getDefaultGeometry in interface FeatureType
Returns:
The attribute type of the default geometry, which will contain the position.

getAttributeType

public AttributeType getAttributeType(java.lang.String xPath)
Gets the attributeType at this xPath, if the specified attributeType does not exist then null is returned.

Specified by:
getAttributeType in interface FeatureType
Parameters:
xPath - XPath pointer to attribute type.
Returns:
True if attribute exists.

find

public int find(AttributeType type)
Find the position of a given AttributeType.

Specified by:
find in interface FeatureType
Parameters:
type - The type to search for.
Returns:
-1 if not found, a zero-based index if found.

find

public int find(java.lang.String attName)
Find the position of an AttributeType which matches the given String.

Specified by:
find in interface FeatureType
Parameters:
attName - the name to look for
Returns:
-1 if not found, zero-based index otherwise

getAttributeType

public AttributeType getAttributeType(int position)
Gets the attributeType at the specified index.

Specified by:
getAttributeType in interface FeatureType
Parameters:
position - the position of the attribute to check.
Returns:
The attribute type at the specified position.

getAttributeTypes

public AttributeType[] getAttributeTypes()
Description copied from interface: FeatureType
AttributeTypes for this FeatureType, all attributes defined by this FeatureType and its super types define schema for feature instances.

The provided array of AttributeTypes should be considered as adding to (or overriding) the the AttribtueTypes defined by this FeatureTypes ancestors.

Note Well: Client code should not consider the index provided by the find( attName ) method as a valid index into the returned array.

Specified by:
getAttributeTypes in interface FeatureType
Returns:
Array of AttributeType describing this schema, array may be length 0, but should not be null

getNamespace

public java.net.URI getNamespace()
Gets the global schema namespace.

Specified by:
getNamespace in interface FeatureType
Returns:
Namespace of schema.

getTypeName

public java.lang.String getTypeName()
Gets the type name for this schema.

Specified by:
getTypeName in interface FeatureType
Returns:
Namespace of schema.

hasAttributeType

public boolean hasAttributeType(java.lang.String xPath)
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.

Specified by:
hasAttributeType in interface FeatureType
Parameters:
xPath - XPath pointer to attribute type.
Returns:
Number of occurrences.

getAttributeCount

public int getAttributeCount()
Returns the number of attributes at the first 'level' of the schema.

Specified by:
getAttributeCount in interface FeatureType
Returns:
the total number of first level attributes.

equals

public boolean equals(FeatureType other)

hashCode

public int hashCode()
Description copied from interface: FeatureType
Hascode based on namespace, typeName, attributes and ancestors.

Hascode is always a matched set with an equals implementation, please see the javadocs for equals for a detailed discussion.

Specified by:
hashCode in interface FeatureType

toString

public java.lang.String toString()

equals

public boolean equals(java.lang.Object other)
Description copied from interface: FeatureType
FeatureType check based on namespace, typeName, attributes and ancestors.

Conceptually FeatureType equality is supped to indicate an exact match based AttributeType and Ancestors. The geotools models includes additional information of namespace and typename.

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).

Required implementation:


 
A sample implementation is provided in FeatureTypes.equals( FeatureType, FeatureType ).

Questions:
Q: You may wonder why namespace and typeName are not enought?
A: Geotools often returns a "limitied" schema in response to a query where only a subset of the attributes are requested.
Q: Doesn't that still indicate the same schema?
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.

Specified by:
equals in interface FeatureType

getAncestors

public FeatureType[] getAncestors()
Obtain an array of this FeatureTypes ancestors. Implementors should return a non-null array (may be of length 0).

Specified by:
getAncestors in interface FeatureType
Returns:
An array of ancestors.

isAbstract

public boolean isAbstract()
Is this FeatureType an abstract type?

Specified by:
isAbstract in interface FeatureType
Returns:
true if abstract, false otherwise.

isDescendedFrom

public boolean isDescendedFrom(FeatureType type)
A convenience method for calling
FeatureType f1; FeatureType f2; f1.isDescendedFrom(f2.getNamespace(),f2.getName());

Specified by:
isDescendedFrom in interface FeatureType
Parameters:
type - The type to compare to.
Returns:
true if descendant, false otherwise.

isDescendedFrom

public boolean isDescendedFrom(java.net.URI nsURI,
                               java.lang.String typeName1)
Test to determine whether this FeatureType is descended from the given FeatureType. Think of this relationship likes the "extends" relationship in java.

Specified by:
isDescendedFrom in interface FeatureType
Parameters:
nsURI - The namespace URI to use.
typeName1 - The typeName.
Returns:
true if descendant, false otherwise.
Task:
HACK: if nsURI is null only typeName is tested.


Copyright © GeoTools. All Rights Reserved.