org.geotools.feature.simple
Class SimpleFeatureTypeBuilder

Object
  extended by SimpleFeatureTypeBuilder
Direct Known Subclasses:
DefaultFeatureTypeBuilder

public class SimpleFeatureTypeBuilder
extends Object

A builder for simple feature types.

Simple Usage:

  
  //create the builder
  SimpleTypeBuilder builder = new SimpleTypeBuilder();
  
  //set global state
  builder.setName( "testType" );
  builder.setNamespaceURI( "http://www.geotools.org/" );
  builder.setSRS( "EPSG:4326" );
  
  //add attributes
  builder.add( "intProperty", Integer.class );
  builder.add( "stringProperty", String.class );
  builder.add( "pointProperty", Point.class );
  
  //add attribute setting per attribute state
  builder.minOccurs(0).maxOccurs(2).nillable(false).add("doubleProperty",Double.class);
  
  //build the type
  SimpleFeatureType featureType = builder.buildFeatureType();
  
 

This builder builds type by maintaining state. Two types of state are maintained: Global Type State and Per Attribute State. Methods which set global state are named set<property>(). Methods which set per attribute state are named <property>(). Furthermore calls to per attribute

Global state is reset after a call to buildFeatureType(). Per attribute state is reset after a call to add(java.lang.String, java.lang.Class).

A default geometry for the feature type can be specified explictly via setDefaultGeometry(String). However if one is not set the first geometric attribute (GeometryType) added will be resulting default. So if only specifying a single geometry for the type there is no need to call the method. However if specifying multiple geometries then it is good practice to specify the name of the default geometry type. For instance:

  builder.add( "pointProperty", Point.class );
  builder.add( "lineProperty", LineString.class );
  builder.add( "polygonProperty", "polygonProperty" );
  
  builder.setDefaultGeometry( "lineProperty" );
        

Author:
Justin Deolivera, Jody Garnett

Field Summary
protected  AttributeTypeBuilder attributeBuilder
          attribute builder
protected  List<AttributeDescriptor> attributes
          List of attributes.
protected  Map bindings
          Map of java class bound to properties types.
protected  CoordinateReferenceSystem crs
          coordinate reference system of the type
protected  String defaultGeometry
          Name of the default geometry to use
protected  InternationalString description
          Description of type.
protected  FeatureTypeFactory factory
          factories
protected  boolean isAbstract
          flag controlling if the type is abstract.
protected  String local
          Naming: local name
protected  List<Filter> restrictions
          Additional restrictions on the type.
protected  SimpleFeatureType superType
          the parent type.
protected  String uri
          Naming: uri indicating scope
 
Constructor Summary
SimpleFeatureTypeBuilder()
          Constructs the builder.
SimpleFeatureTypeBuilder(FeatureTypeFactory factory)
          Constructs the builder specifying the factory for creating feature and feature collection types.
 
Method Summary
 void add(AttributeDescriptor descriptor)
          Adds a descriptor directly to the builder.
 void add(int index, AttributeDescriptor descriptor)
          Adds a descriptor to the builder by index.
 void add(String name, Class binding)
          Adds a new attribute w/ provided name and class.
 void add(String name, Class binding, CoordinateReferenceSystem crs)
          Adds a new geometric attribute w/ provided name, class, and coordinate reference system.
 void add(String name, Class binding, Integer srid)
          Adds a new geometric attribute w/ provided name, class, and spatial reference system identifier The srid parameter may be null.
 void add(String name, Class binding, String srs)
          Adds a new geometric attribute w/ provided name, class, and spatial reference system identifier The srs parameter may be null.
 void addAll(AttributeDescriptor[] descriptors)
          Adds an array of descriptors directly to the builder.
 void addAll(List<AttributeDescriptor> descriptors)
          Adds a list of descriptors directly to the builder.
 void addBinding(AttributeType type)
          Specifies an attribute type binding.
 void addBindings(Schema schema)
          Specifies a number of attribute type bindings.
protected  List<AttributeDescriptor> attributes()
          Accessor for attributes.
protected  Map bindings()
          Accessor for bindings.
 SimpleFeatureType buildFeatureType()
          Builds a feature type from compiled state.
 SimpleFeatureTypeBuilder crs(CoordinateReferenceSystem crs)
          Sets the crs of the next attribute added to the feature type.
protected  CoordinateReferenceSystem decode(String srs)
          Decodes a srs, supplying a useful error message if there is a problem.
 SimpleFeatureTypeBuilder defaultValue(Object defaultValue)
          Sets the default value of the next attribute added to the feature type.
 SimpleFeatureTypeBuilder description(String description)
          Sets the description of the next attribute added to the feature type.
 SimpleFeatureTypeBuilder descriptor(AttributeDescriptor descriptor)
          Sets all the attribute specific state from a single descriptor.
 AttributeType getBinding(Class<?> binding)
          Looks up an attribute type which has been bound to a class.
 CoordinateReferenceSystem getCRS()
          The coordinate reference system of the built type.
 String getDefaultGeometry()
          The name of the default geometry attribute of the built type.
 InternationalString getDescription()
          The description of the built type.
 FeatureTypeFactory getFeatureTypeFactory()
          The factory used to create feature and feature collection types.
 String getName()
          The name of the built type.
 String getNamespaceURI()
          The namespace uri of the built type.
 SimpleFeatureType getSuperType()
          The super type of the built type.
protected  void init()
          Clears the running list of attributes.
 void init(SimpleFeatureType type)
          Initializes the builder with state from a pre-existing feature type.
 boolean isAbstract()
          The flag controlling if the resulting type is abstract.
 SimpleFeatureTypeBuilder length(int length)
          Sets a restriction on the field length of the next attribute added to the feature type.
 SimpleFeatureTypeBuilder maxOccurs(int maxOccurs)
          Sets the maxOccurs of the next attribute added to the feature type.
 SimpleFeatureTypeBuilder minOccurs(int minOccurs)
          Sets the minOccurs of the next attribute added to the feature type.
protected  Name name()
          Naming: Accessor which returns type name as follows: If typeName has been set, its value is returned.
protected  List newList()
          Creates a new list instance, this default impelementation returns ArrayList.
protected  List newList(List origional)
          Creates a new list which is the same type as the provided list.
protected  Map newMap()
          Creates a new map instance, this default implementation returns HashMap
protected  Set newSet()
          Creates a new set instance, this default implementation returns HashSet.
 SimpleFeatureTypeBuilder nillable(boolean isNillable)
          Sets the nullability of the next attribute added to the feature type.
 AttributeDescriptor remove(String attributeName)
          Removes an attribute from the builder
protected  void reset()
          Completely resets all builder state.
 SimpleFeatureTypeBuilder restriction(Filter filter)
          Adds a restriction to the next attribute added to the feature type.
protected  List<Filter> restrictions()
          Accessor for restrictions.
 SimpleFeatureTypeBuilder restrictions(List<Filter> filters)
          Adds a collection of restrictions to the next attribute added to the This value is reset after a call to add(String, Class)
static SimpleFeatureType retype(SimpleFeatureType original, String[] types)
          H
 void setAbstract(boolean isAbstract)
          Sets the flag controlling if the resulting type is abstract.
 void setAttributes(AttributeDescriptor[] attributes)
          Directly sets the list of attributes.
 void setAttributes(List<AttributeDescriptor> attributes)
          Directly sets the list of attributes.
 void setBindings(Schema schema)
          Specifies a number of attribute type bindings clearing out all existing bindings.
 void setCRS(CoordinateReferenceSystem crs)
          Sets the coordinate reference system of the built type.
 void setDefaultGeometry(String defaultGeometryName)
          Sets the name of the default geometry attribute of the built type.
 void setDescription(InternationalString description)
          Sets the description of the built type.
 void setFeatureTypeFactory(FeatureTypeFactory factory)
          Sets the factory used to create feature and feature collection types.
 void setName(Name name)
          Sets the local name and namespace uri of the built type.
 void setName(String name)
          Sets the name of the built type.
 void setNamespaceURI(String namespaceURI)
          Set the namespace uri of the built type.
 void setNamespaceURI(URI namespaceURI)
           
 void setSRS(String srs)
          Sets the coordinate reference system of the built type by specifying its srs.
 void setSuperType(SimpleFeatureType superType)
          Sets the super type of the built type.
 SimpleFeatureTypeBuilder srid(Integer srid)
          Sets the srid of the next attribute added to the feature type.
 SimpleFeatureTypeBuilder srs(String srs)
          Sets the srs of the next attribute added to the feature type.
 SimpleFeatureTypeBuilder userData(Object key, Object value)
          Sets user data for the next attribute added to the feature type.
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

factory

protected FeatureTypeFactory factory
factories


bindings

protected Map bindings
Map of java class bound to properties types.


local

protected String local
Naming: local name


uri

protected String uri
Naming: uri indicating scope


description

protected InternationalString description
Description of type.


attributes

protected List<AttributeDescriptor> attributes
List of attributes.


restrictions

protected List<Filter> restrictions
Additional restrictions on the type.


defaultGeometry

protected String defaultGeometry
Name of the default geometry to use


crs

protected CoordinateReferenceSystem crs
coordinate reference system of the type


isAbstract

protected boolean isAbstract
flag controlling if the type is abstract.


superType

protected SimpleFeatureType superType
the parent type.


attributeBuilder

protected AttributeTypeBuilder attributeBuilder
attribute builder

Constructor Detail

SimpleFeatureTypeBuilder

public SimpleFeatureTypeBuilder()
Constructs the builder.


SimpleFeatureTypeBuilder

public SimpleFeatureTypeBuilder(FeatureTypeFactory factory)
Constructs the builder specifying the factory for creating feature and feature collection types.

Method Detail

setFeatureTypeFactory

public void setFeatureTypeFactory(FeatureTypeFactory factory)
Sets the factory used to create feature and feature collection types.


getFeatureTypeFactory

public FeatureTypeFactory getFeatureTypeFactory()
The factory used to create feature and feature collection types.


init

public void init(SimpleFeatureType type)
Initializes the builder with state from a pre-existing feature type.


init

protected void init()
Clears the running list of attributes.


reset

protected void reset()
Completely resets all builder state.


setNamespaceURI

public void setNamespaceURI(String namespaceURI)
Set the namespace uri of the built type.


setNamespaceURI

public void setNamespaceURI(URI namespaceURI)

getNamespaceURI

public String getNamespaceURI()
The namespace uri of the built type.


setName

public void setName(String name)
Sets the name of the built type.


getName

public String getName()
The name of the built type.


setName

public void setName(Name name)
Sets the local name and namespace uri of the built type.


setDescription

public void setDescription(InternationalString description)
Sets the description of the built type.


getDescription

public InternationalString getDescription()
The description of the built type.


setDefaultGeometry

public void setDefaultGeometry(String defaultGeometryName)
Sets the name of the default geometry attribute of the built type.


getDefaultGeometry

public String getDefaultGeometry()
The name of the default geometry attribute of the built type.


setCRS

public void setCRS(CoordinateReferenceSystem crs)
Sets the coordinate reference system of the built type.


getCRS

public CoordinateReferenceSystem getCRS()
The coordinate reference system of the built type.


setSRS

public void setSRS(String srs)
Sets the coordinate reference system of the built type by specifying its srs.

Throws:
IllegalArgumentException - When the srs specified can be decored into a crs.

setAbstract

public void setAbstract(boolean isAbstract)
Sets the flag controlling if the resulting type is abstract.


isAbstract

public boolean isAbstract()
The flag controlling if the resulting type is abstract.


setSuperType

public void setSuperType(SimpleFeatureType superType)
Sets the super type of the built type.


getSuperType

public SimpleFeatureType getSuperType()
The super type of the built type.


addBinding

public void addBinding(AttributeType type)
Specifies an attribute type binding.

This method is used to associate an attribute type with a java class. The class is retreived from type.getBinding(). When the add(String, Class) method is used to add an attribute to the type being built, this binding is used to locate the attribute type.

Parameters:
type - The attribute type.

addBindings

public void addBindings(Schema schema)
Specifies a number of attribute type bindings.

Parameters:
schema - The schema containing the attribute types.
See Also:
#addBinding(AttributeType)}.

setBindings

public void setBindings(Schema schema)
Specifies a number of attribute type bindings clearing out all existing bindings.

Parameters:
schema - The schema contianing attribute types.
See Also:
#addBinding(AttributeType)}.

getBinding

public AttributeType getBinding(Class<?> binding)
Looks up an attribute type which has been bound to a class.

Parameters:
binding - The class.
Returns:
AttributeType The bound attribute type.

minOccurs

public SimpleFeatureTypeBuilder minOccurs(int minOccurs)
Sets the minOccurs of the next attribute added to the feature type.

This value is reset after a call to add(String, Class)


maxOccurs

public SimpleFeatureTypeBuilder maxOccurs(int maxOccurs)
Sets the maxOccurs of the next attribute added to the feature type.

This value is reset after a call to add(String, Class)


nillable

public SimpleFeatureTypeBuilder nillable(boolean isNillable)
Sets the nullability of the next attribute added to the feature type.

This value is reset after a call to add(String, Class)


length

public SimpleFeatureTypeBuilder length(int length)
Sets a restriction on the field length of the next attribute added to the feature type.

This method is the same as adding a restriction based on length( value ) < length This value is reset after a call to add(String, Class)

Returns:
length Used to limit the length of the next attribute created

restriction

public SimpleFeatureTypeBuilder restriction(Filter filter)
Adds a restriction to the next attribute added to the feature type.

This value is reset after a call to add(String, Class)


restrictions

public SimpleFeatureTypeBuilder restrictions(List<Filter> filters)
Adds a collection of restrictions to the next attribute added to the

This value is reset after a call to add(String, Class)


description

public SimpleFeatureTypeBuilder description(String description)
Sets the description of the next attribute added to the feature type.

This value is reset after a call to add(String, Class)


defaultValue

public SimpleFeatureTypeBuilder defaultValue(Object defaultValue)
Sets the default value of the next attribute added to the feature type.

This value is reset after a call to add(String, Class)


crs

public SimpleFeatureTypeBuilder crs(CoordinateReferenceSystem crs)
Sets the crs of the next attribute added to the feature type.

This only applies if the attribute added is geometric.

This value is reset after a call to add(String, Class)


srs

public SimpleFeatureTypeBuilder srs(String srs)
Sets the srs of the next attribute added to the feature type.

The srs parameter is the id of a spatial reference system, for example: "epsg:4326".

This only applies if the attribute added is geometric.

This value is reset after a call to add(String, Class)

Parameters:
srs - The spatial reference system.

srid

public SimpleFeatureTypeBuilder srid(Integer srid)
Sets the srid of the next attribute added to the feature type.

The srid parameter is the epsg code of a spatial reference system, for example: "4326".

This only applies if the attribute added is geometric.

This value is reset after a call to add(String, Class)

Parameters:
srid - The id of a spatial reference system.

userData

public SimpleFeatureTypeBuilder userData(Object key,
                                         Object value)
Sets user data for the next attribute added to the feature type.

This value is reset after a call to add(String, Class)

Parameters:
key - The key of the user data.
value - The value of the user data.

descriptor

public SimpleFeatureTypeBuilder descriptor(AttributeDescriptor descriptor)
Sets all the attribute specific state from a single descriptor.

This method is convenience for: builder.minOccurs( descriptor.getMinOccurs() ).maxOccurs( descriptor.getMaxOccurs() ) .nillable( descriptor.isNillable() )...


add

public void add(String name,
                Class binding)
Adds a new attribute w/ provided name and class.

The provided class is used to locate an attribute type binding previously specified by addBinding(AttributeType),addBindings(Schema), or setBindings(Schema).

If not such binding exists then an attribute type is created on the fly.

Parameters:
name - The name of the attribute.
bind - The class the attribute is bound to.

add

public void add(AttributeDescriptor descriptor)
Adds a descriptor directly to the builder.

Use of this method is discouraged. Consider using add(String, Class).


remove

public AttributeDescriptor remove(String attributeName)
Removes an attribute from the builder

Parameters:
attributeName - the name of the AttributeDescriptor to remove
Returns:
the AttributeDescriptor with the name attributeName
Throws:
IllegalArgumentException - if there is no AttributeDescriptor with the name attributeName

add

public void add(int index,
                AttributeDescriptor descriptor)
Adds a descriptor to the builder by index.

Use of this method is discouraged. Consider using add(String, Class).


addAll

public void addAll(List<AttributeDescriptor> descriptors)
Adds a list of descriptors directly to the builder.

Use of this method is discouraged. Consider using add(String, Class).


addAll

public void addAll(AttributeDescriptor[] descriptors)
Adds an array of descriptors directly to the builder.

Use of this method is discouraged. Consider using add(String, Class).


add

public void add(String name,
                Class binding,
                CoordinateReferenceSystem crs)
Adds a new geometric attribute w/ provided name, class, and coordinate reference system.

The crs parameter may be null.

Parameters:
name - The name of the attribute.
binding - The class that the attribute is bound to.
crs - The crs of of the geometry, may be null.

add

public void add(String name,
                Class binding,
                String srs)
Adds a new geometric attribute w/ provided name, class, and spatial reference system identifier

The srs parameter may be null.

Parameters:
name - The name of the attribute.
binding - The class that the attribute is bound to.
srs - The srs of of the geometry, may be null.

add

public void add(String name,
                Class binding,
                Integer srid)
Adds a new geometric attribute w/ provided name, class, and spatial reference system identifier

The srid parameter may be null.

Parameters:
name - The name of the attribute.
binding - The class that the attribute is bound to.
srid - The srid of of the geometry, may be null.

setAttributes

public void setAttributes(List<AttributeDescriptor> attributes)
Directly sets the list of attributes.

Parameters:
attributes - the new list of attributes, or null to reset the list

setAttributes

public void setAttributes(AttributeDescriptor[] attributes)
Directly sets the list of attributes.

Parameters:
attributes - the new list of attributes, or null to reset the list

buildFeatureType

public SimpleFeatureType buildFeatureType()
Builds a feature type from compiled state.

After the type is built the running list of attributes is cleared.

Returns:
The built feature type.

newSet

protected Set newSet()
Creates a new set instance, this default implementation returns HashSet.


newList

protected List newList()
Creates a new list instance, this default impelementation returns ArrayList.


newMap

protected Map newMap()
Creates a new map instance, this default implementation returns HashMap


newList

protected List newList(List origional)
Creates a new list which is the same type as the provided list.

If the new copy can not be created reflectively.. newList() is returned.


name

protected Name name()
Naming: Accessor which returns type name as follows:
  1. If typeName has been set, its value is returned.
  2. If name has been set, it + namespaceURI are returned.


attributes

protected List<AttributeDescriptor> attributes()
Accessor for attributes.


restrictions

protected List<Filter> restrictions()
Accessor for restrictions.


bindings

protected Map bindings()
Accessor for bindings.


decode

protected CoordinateReferenceSystem decode(String srs)
Decodes a srs, supplying a useful error message if there is a problem.


retype

public static SimpleFeatureType retype(SimpleFeatureType original,
                                       String[] types)
H

Parameters:
original -
types -
Returns:


Copyright © 1996-2009 Geotools. All Rights Reserved.