org.geotools.feature
Class FeatureTypeBuilder

java.lang.Object
  extended byorg.geotools.feature.FeatureTypes
      extended byorg.geotools.feature.FeatureTypeBuilder
All Implemented Interfaces:
Factory
Direct Known Subclasses:
FeatureTypeFactory

public abstract class FeatureTypeBuilder
extends FeatureTypes
implements Factory

A schema builder, because FeatureTypes are meant to be immutable, this object is mutable.

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
getFeatureType()

Repeated calls to getFeatureType will return the same FeatureType given that no calls which modify the state of the factory are made.

Here's an example of how to use this:

 
 FeatureTypeBuilder build = FeatureTypeFactory.newInstance();  
 build.addType(...);
 build.setName(...);  
 build.setNamespace(...);  
 FeatureType type = build.getFeatureType(); 
 
There are also a set of convenience methods for creation of FeatureTypes. These are the various newFeatureType methods.

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

Field Summary
 
Fields inherited from class org.geotools.feature.FeatureTypes
ANY_LENGTH
 
Constructor Summary
FeatureTypeBuilder()
          An empty public constructor.
FeatureTypeBuilder(java.util.Map hints)
          An empty public constructor.
 
Method Summary
protected abstract  void add(AttributeType type)
          DOCUMENT ME!
protected abstract  void add(int idx, AttributeType type)
          DOCUMENT ME!
protected  void addBaseTypes(java.util.Set types)
           
 void addType(AttributeType type)
          A the given AttributeType to this factory.
 void addType(int idx, AttributeType type)
          Insert the given type at the index specified.
 void addTypes(AttributeType[] types)
          Add an array of AttributeTypes to this factory.
protected  void check(AttributeType type)
          Checks to see if this factory already contains the type.
 boolean contains(AttributeType type)
          Check to see if this factory contains the given AttributeType.
protected abstract  FeatureType createFeatureType()
          DOCUMENT ME!
abstract  AttributeType get(int idx)
          DOCUMENT ME!
abstract  int getAttributeCount()
          DOCUMENT ME!
protected  java.util.Set getBuiltinTypes()
           
 GeometryAttributeType getDefaultGeometry()
          Return the AttributeType currently used as the defaultGeometry property for the FeatureType this factory will create.
 FeatureType getFeatureType()
          Get a FeatureType which reflects the state of this factory.
 java.util.Map getImplementationHints()
          Returns the implementation hints.
 java.lang.String getName()
          Get the current configuration of the name of this factory.
 java.net.URI getNamespace()
          Get the current configuration of the namespace of this factory.
 java.util.Collection getSuperTypes()
          Obtain the super types of this factory.
 void importType(FeatureType type)
          A convienence method for importing AttributeTypes, simply calls
importType(type,false)
 void importType(FeatureType type, boolean strict)
          Import all of the AttributeTypes from the given FeatureType into this factory.
 boolean isAbstract()
          Is this factory configured to be abstract?
static FeatureTypeFactory newInstance(java.lang.String name)
          Create a new FeatureTypeFactory with the given typeName.
protected abstract  AttributeType remove(AttributeType type)
          DOCUMENT ME!
protected abstract  AttributeType remove(int idx)
          DOCUMENT ME!
 void removeAll()
          Remove all the AttributeTypes in this factory.
 void removeType(AttributeType type)
          Remove the given type from this factory.
 void removeType(int idx)
          Remove the AttributeType at the given index.
protected abstract  AttributeType set(int idx, AttributeType type)
          DOCUMENT ME!
 void setAbstract(boolean a)
          Configure this factory to produce an abstract type.
 void setDefaultGeometry(GeometryAttributeType defaultGeometry)
          Sets the defaultGeometry of this factory.
 void setName(java.lang.String name)
          Set the name of the FeatureType this factory will produce.
 void setNamespace(java.net.URI namespace)
          Set the namespace of the FeatureType this factory will produce.
 void setSuperTypes(java.util.Collection types)
          Set the super types of this factory.
 void setType(int idx, AttributeType type)
          Set the AttributeType at the given index.
 void swap(int idx1, int idx2)
          Swap the AttributeTypes at the given locations.
 java.lang.String toString()
          Returns a string representation of this factory.
 
Methods inherited from class org.geotools.feature.FeatureTypes
ancestors, equals, equals, equals, equalsAncestors, equalsId, getFieldLength, isDecendedFrom, isDecendedFrom, newFeatureType, newFeatureType, newFeatureType, newFeatureType, newFeatureType, newFeatureType, transform, transform
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

FeatureTypeBuilder

public FeatureTypeBuilder()
An empty public constructor. Subclasses should not provide a constructor.


FeatureTypeBuilder

public FeatureTypeBuilder(java.util.Map hints)
An empty public constructor. Subclasses should not provide a constructor.

Method Detail

getImplementationHints

public java.util.Map getImplementationHints()
Returns the implementation hints. The default implementation returns en empty map.

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.

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

Specified by:
getImplementationHints in interface Factory
Returns:
The map of hints, or an empty map if none.

newInstance

public static FeatureTypeFactory newInstance(java.lang.String name)
                                      throws FactoryConfigurationError
Create a new FeatureTypeFactory with the given typeName.

Parameters:
name - The typeName of the feature to create.
Returns:
A new FeatureTypeFactory instance.
Throws:
FactoryConfigurationError - If there exists a configuration error.

importType

public void importType(FeatureType type,
                       boolean strict)
                throws java.lang.IllegalArgumentException
Import all of the AttributeTypes from the given FeatureType into this factory.

If strict is true, non-uniquely named AttributeTypes will throw an exception.

If strict is false, these will be silently ignored, but not added.

No other information is imported.

Parameters:
type - The FeatureType to import from.
strict - Enforce namespace restrictions.
Throws:
java.lang.IllegalArgumentException - If strict is true and there are naming problems.

setSuperTypes

public final void setSuperTypes(java.util.Collection types)
Set the super types of this factory. The types will be copied into a Set.

Parameters:
types - A Collection of types.

getSuperTypes

public final java.util.Collection getSuperTypes()
Obtain the super types of this factory. Any user types will be appended to the built in types of this factory.

Returns:
A Collection representing the super types of the FeatureType this factory will create.

importType

public void importType(FeatureType type)
A convienence method for importing AttributeTypes, simply calls
importType(type,false)

Parameters:
type - The type to import.

setName

public void setName(java.lang.String name)
Set the name of the FeatureType this factory will produce.

Parameters:
name - The new name. May be null.

getName

public final java.lang.String getName()
Get the current configuration of the name of this factory.

Returns:
The current name. May be null.

setNamespace

public void setNamespace(java.net.URI namespace)
Set the namespace of the FeatureType this factory will produce.

Parameters:
namespace - The new namespace. May be null.

getNamespace

public final java.net.URI getNamespace()
Get the current configuration of the namespace of this factory.

Returns:
The current namespace. May be null.

isAbstract

public final boolean isAbstract()
Is this factory configured to be abstract?

Returns:
True if it is, false if it aint.

setAbstract

public final void setAbstract(boolean a)
Configure this factory to produce an abstract type.

Parameters:
a - True or false.

removeAll

public final void removeAll()
Remove all the AttributeTypes in this factory.


addTypes

public final void addTypes(AttributeType[] types)
                    throws java.lang.NullPointerException,
                           java.lang.IllegalArgumentException
Add an array of AttributeTypes to this factory.

Parameters:
types - The types or a null array.
Throws:
java.lang.NullPointerException - If any of the types are null.
java.lang.IllegalArgumentException - If there are naming problems.

addType

public final void addType(AttributeType type)
                   throws java.lang.NullPointerException,
                          java.lang.IllegalArgumentException
A the given AttributeType to this factory.

Parameters:
type - The type to add.
Throws:
java.lang.NullPointerException - If the type is null.
java.lang.IllegalArgumentException - If another type exists with the same name.

removeType

public final void removeType(AttributeType type)
                      throws java.lang.NullPointerException
Remove the given type from this factory.

Parameters:
type - The type to remove.
Throws:
java.lang.NullPointerException - If the type is null.

addType

public final void addType(int idx,
                          AttributeType type)
                   throws java.lang.NullPointerException,
                          java.lang.IllegalArgumentException,
                          java.lang.ArrayIndexOutOfBoundsException
Insert the given type at the index specified.

Parameters:
idx - The index to insert at.
type - The AttributeType to insert.
Throws:
java.lang.NullPointerException - If the type is null.
java.lang.IllegalArgumentException - If the AttributeType is not allowed.
java.lang.ArrayIndexOutOfBoundsException - If the index is out of range.

removeType

public final void removeType(int idx)
                      throws java.lang.ArrayIndexOutOfBoundsException
Remove the AttributeType at the given index.

Parameters:
idx - The index to remove at.
Throws:
java.lang.ArrayIndexOutOfBoundsException - If the index is out of bounds.

setType

public final void setType(int idx,
                          AttributeType type)
                   throws java.lang.IllegalArgumentException,
                          java.lang.NullPointerException,
                          java.lang.ArrayIndexOutOfBoundsException
Set the AttributeType at the given index. Overwrites the existing type.

Parameters:
idx - The index to use.
type - The type to use.
Throws:
java.lang.IllegalArgumentException - If the type is not good.
java.lang.NullPointerException - if they type passed in is null
java.lang.ArrayIndexOutOfBoundsException - if the index is out of bounds.

swap

public final void swap(int idx1,
                       int idx2)
                throws java.lang.ArrayIndexOutOfBoundsException
Swap the AttributeTypes at the given locations.

Parameters:
idx1 - The index of the first.
idx2 - The index of the second.
Throws:
java.lang.ArrayIndexOutOfBoundsException - if either index is not in the array bounds.

getDefaultGeometry

public final GeometryAttributeType getDefaultGeometry()
Return the AttributeType currently used as the defaultGeometry property for the FeatureType this factory will create.

Returns:
The AttributeType representing the defaultGeometry or null.

setDefaultGeometry

public final void setDefaultGeometry(GeometryAttributeType defaultGeometry)
                              throws java.lang.IllegalArgumentException
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.

Parameters:
defaultGeometry - The AttributeType to use as the defaultGeometry. May be null.
Throws:
java.lang.IllegalArgumentException - if the type is not a geometry.

getFeatureType

public final FeatureType getFeatureType()
                                 throws SchemaException
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.

Returns:
The featureType reflecting the current factory state.
Throws:
SchemaException - if name is null or blank

toString

public java.lang.String toString()
Returns a string representation of this factory.

Returns:
The string representing this factory.

contains

public final boolean contains(AttributeType type)
Check to see if this factory contains the given AttributeType. The comparison is done by name.

Parameters:
type - The AttributeType to search for by name.
Returns:
true if a like-named AttributeType exists, false otherwise.

check

protected void check(AttributeType type)
Checks to see if this factory already contains the type.

Parameters:
type -
Throws:
java.lang.IllegalArgumentException - DOCUMENT ME!

getBuiltinTypes

protected final java.util.Set getBuiltinTypes()

addBaseTypes

protected void addBaseTypes(java.util.Set types)

createFeatureType

protected abstract FeatureType createFeatureType()
                                          throws SchemaException
DOCUMENT ME!

Returns:
Throws:
SchemaException

add

protected abstract void add(AttributeType type)
                     throws java.lang.IllegalArgumentException
DOCUMENT ME!

Parameters:
type -
Throws:
java.lang.IllegalArgumentException

remove

protected abstract AttributeType remove(AttributeType type)
DOCUMENT ME!

Parameters:
type -
Returns:

add

protected abstract void add(int idx,
                            AttributeType type)
                     throws java.lang.ArrayIndexOutOfBoundsException,
                            java.lang.IllegalArgumentException
DOCUMENT ME!

Parameters:
idx -
type -
Throws:
java.lang.ArrayIndexOutOfBoundsException
java.lang.IllegalArgumentException

remove

protected abstract AttributeType remove(int idx)
                                 throws java.lang.ArrayIndexOutOfBoundsException
DOCUMENT ME!

Parameters:
idx -
Returns:
Throws:
java.lang.ArrayIndexOutOfBoundsException

get

public abstract AttributeType get(int idx)
                           throws java.lang.ArrayIndexOutOfBoundsException
DOCUMENT ME!

Parameters:
idx -
Returns:
Throws:
java.lang.ArrayIndexOutOfBoundsException

set

protected abstract AttributeType set(int idx,
                                     AttributeType type)
                              throws java.lang.ArrayIndexOutOfBoundsException,
                                     java.lang.IllegalArgumentException
DOCUMENT ME!

Parameters:
idx -
type -
Returns:
Throws:
java.lang.ArrayIndexOutOfBoundsException
java.lang.IllegalArgumentException

getAttributeCount

public abstract int getAttributeCount()
DOCUMENT ME!

Returns:


Copyright © GeoTools. All Rights Reserved.