Class SimpleFeatureTypeBuilder
- Object
-
- SimpleFeatureTypeBuilder
-
public class SimpleFeatureTypeBuilder extends Object
A builder for simple feature types.Simple Usage:
//create the builder SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder(); //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();
set<property>()
. Methods which set per attribute state are named<property>()
. Furthermore calls to per attributeGlobal state is reset after a call to
buildFeatureType()
. Per attribute state is reset after a call toadd(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", Polygon.class ); builder.setDefaultGeometry( "lineProperty" );
- Author:
- Justin Deolivera, Jody Garnett
-
-
Field Summary
Fields Modifier and Type Field Description protected AttributeTypeBuilder
attributeBuilder
attribute builderprotected List<AttributeDescriptor>
attributes
List of attributes.protected Map<Class<?>,AttributeType>
bindings
Map of java class bound to properties types.protected CoordinateReferenceSystem
defaultCrs
default coordinate reference system of the typeprotected boolean
defaultCrsSet
protected String
defaultGeometry
Name of the default geometry to useprotected InternationalString
description
Description of type.protected FeatureTypeFactory
factory
factoriesprotected boolean
isAbstract
flag controlling if the type is abstract.protected String
local
Naming: local nameprotected List<Filter>
restrictions
Additional restrictions on the type.protected SimpleFeatureType
superType
the parent type.protected String
uri
Naming: uri indicating scope
-
Constructor Summary
Constructors Constructor Description SimpleFeatureTypeBuilder()
Constructs the builder.SimpleFeatureTypeBuilder(FeatureTypeFactory factory)
Constructs the builder specifying the factory for creating feature and feature collection types.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description 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, Integer srid)
Adds a new geometric attribute w/ provided name, class, and spatial reference system identifiervoid
add(String name, Class<?> binding, String srs)
Adds a new geometric attribute w/ provided name, class, and spatial reference system identifiervoid
add(String name, Class<?> binding, CoordinateReferenceSystem crs)
Adds a new geometric attribute w/ provided name, class, and coordinate reference system.void
add(AttributeDescriptor descriptor)
Adds a descriptor directly to the builder.void
addAll(List<AttributeDescriptor> descriptors)
Adds a list of descriptors directly to the builder.void
addAll(AttributeDescriptor... descriptors)
Adds an array 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 (will create attributes list if needed)protected Map<Class<?>,AttributeType>
bindings()
Accessor for bindings (will create binding map if needed).SimpleFeatureType
buildFeatureType()
Builds a feature type from compiled state.static SimpleFeatureType
copy(SimpleFeatureType original)
Copies a feature type.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.AttributeDescriptor
get(int index)
Gets an AttributeBuilder configured using the descriptor at the provided index.AttributeDescriptor
get(String attributeName)
AttributeType
getBinding(Class<?> binding)
Looks up an attribute type which has been bound to a class.CoordinateReferenceSystem
getCRS()
The fallback coordinate reference system that will be applied to any geometric attributes added to the type without their own coordinate reference system specified.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: IftypeName
has been set, its value is returned.protected List
newList()
Creates a new list instance, this default impelementation returnsArrayList
.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 returnsHashMap
protected Set
newSet()
Creates a new set instance, this default implementation returnsHashSet
.SimpleFeatureTypeBuilder
nillable(boolean isNillable)
Sets the nullability of the next attribute added to the feature type.SimpleFeatureTypeBuilder
options(Object... options)
Sets a restriction on the possible field values of the next attribute added to the feature type.SimpleFeatureTypeBuilder
options(List<?> options)
Sets a restriction on the possible field values of the next attribute added to the feature type.AttributeDescriptor
remove(String attributeName)
Removes an attribute from the builderprotected 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 (will create restrictions list if needed).SimpleFeatureTypeBuilder
restrictions(List<Filter> filters)
Adds a collection of restrictions to the next attribute added to thestatic SimpleFeatureType
retype(SimpleFeatureType original, String... attributes)
Create a SimpleFeatureType containing just the attribute descriptors indicated.static SimpleFeatureType
retype(SimpleFeatureType original, List<String> attributes)
Create a SimpleFeatureType containing just the attribute descriptors indicated.static SimpleFeatureType
retype(SimpleFeatureType original, Query query)
Create a SimpleFeatureType with the parameters and coordinate reference system of the query.static SimpleFeatureType
retype(SimpleFeatureType original, CoordinateReferenceSystem crs)
Create a SimpleFeatureType with the same content; just updating the geometry attribute to match the provided coordinate reference system.void
set(int index, AttributeDescriptor descriptor)
Replace the descriptor at the provided index.void
set(String attributeName, AttributeDescriptor descriptor)
Replace the descriptor at the provided index.void
set(String attributeName, AttributeTypeBuilder attributeBuilder)
Replace the descriptor at the provided index.void
set(AttributeDescriptor descriptor)
Replace the descriptor at the provided index.void
setAbstract(boolean isAbstract)
Sets the flag controlling if the resulting type is abstract.void
setAttributes(List<AttributeDescriptor> attributes)
Directly sets the list of attributes.void
setAttributes(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 next attribute being added.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(String name)
Sets the name of the built type.void
setName(Name name)
Sets the local name and namespace uri 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 next attribute being added 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.
-
-
-
Field Detail
-
factory
protected FeatureTypeFactory factory
factories
-
bindings
protected Map<Class<?>,AttributeType> 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.
-
defaultGeometry
protected String defaultGeometry
Name of the default geometry to use
-
defaultCrsSet
protected boolean defaultCrsSet
-
defaultCrs
protected CoordinateReferenceSystem defaultCrs
default 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 next attribute being added.The supplied coordinate reference is a "default" only used if geometric attributes are later added to the type without specifying their coordinate reference system.
You must call this method prior to calling add for it to function.
Example:
builder.setCRS( DefaultGeographicCRS.EGS84 ); builder.add( "geom", Polygon.class );
-
getCRS
public CoordinateReferenceSystem getCRS()
The fallback coordinate reference system that will be applied to any geometric attributes added to the type without their own coordinate reference system specified.
-
setSRS
public void setSRS(String srs)
Sets the coordinate reference system of the next attribute being added 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 theadd(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.
-
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.
-
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)
-
options
public SimpleFeatureTypeBuilder options(Object... options)
Sets a restriction on the possible field values of the next attribute added to the feature type.This method is the same as adding a restriction based on value in (option1, option2, ...}. This restriction is reset after a call to
add(String, Class)
-
options
public SimpleFeatureTypeBuilder options(List<?> options)
Sets a restriction on the possible field values of the next attribute added to the feature type.This method is the same as adding a restriction based on value in (option1, option2, ...}. This restriction is reset after a call to
add(String, Class)
-
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 theThis 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. Example:
builder.crs( DefaultGeographicCRS.WGS84 ).add( "geom", Polygon.class )
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)
, orsetBindings(Schema)
.If not such binding exists then an attribute type is created on the fly.
- Parameters:
name
- The name of the attribute.binding
- 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 benull
.
-
add
public void add(String name, Class<?> binding, String srs)
Adds a new geometric attribute w/ provided name, class, and spatial reference system identifierThe 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 benull
.
-
add
public void add(String name, Class<?> binding, Integer srid)
Adds a new geometric attribute w/ provided name, class, and spatial reference system identifierThe 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 benull
.
-
get
public AttributeDescriptor get(int index)
Gets an AttributeBuilder configured using the descriptor at the provided index.- Parameters:
index
- attribute index- Returns:
- attribute builder configured with descriptor
-
get
public AttributeDescriptor get(String attributeName)
-
set
public void set(int index, AttributeDescriptor descriptor)
Replace the descriptor at the provided index.
-
set
public void set(AttributeDescriptor descriptor)
Replace the descriptor at the provided index.
-
set
public void set(String attributeName, AttributeDescriptor descriptor)
Replace the descriptor at the provided index.
-
set
public void set(String attributeName, AttributeTypeBuilder attributeBuilder)
Replace the descriptor at the provided index.
-
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 returnsHashSet
.
-
newList
protected List newList()
Creates a new list instance, this default impelementation returnsArrayList
.
-
newMap
protected Map newMap()
Creates a new map instance, this default implementation returnsHashMap
-
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:- If
typeName
has been set, its value is returned. - If
name
has been set, it +namespaceURI
are returned.
- If
-
attributes
protected List<AttributeDescriptor> attributes()
Accessor for attributes (will create attributes list if needed)
-
restrictions
protected List<Filter> restrictions()
Accessor for restrictions (will create restrictions list if needed).
-
bindings
protected Map<Class<?>,AttributeType> bindings()
Accessor for bindings (will create binding map if needed).
-
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... attributes)
Create a SimpleFeatureType containing just the attribute descriptors indicated.- Parameters:
original
- SimpleFeatureTypeattributes
- name of attributes to include in result- Returns:
- SimpleFeatureType containing just the types indicated by name
-
retype
public static SimpleFeatureType retype(SimpleFeatureType original, List<String> attributes)
Create a SimpleFeatureType containing just the attribute descriptors indicated.- Parameters:
original
- SimpleFeatureTypeattributes
- name of attributes to include in result- Returns:
- SimpleFeatureType containing just the types indicated by name
-
retype
public static SimpleFeatureType retype(SimpleFeatureType original, CoordinateReferenceSystem crs)
Create a SimpleFeatureType with the same content; just updating the geometry attribute to match the provided coordinate reference system.- Parameters:
original
- SimpleFeatureTypecrs
- CoordinateReferenceSystem of result- Returns:
- SimpleFeatureType updated with the provided CoordinateReferenceSystem
-
retype
public static SimpleFeatureType retype(SimpleFeatureType original, Query query)
Create a SimpleFeatureType with the parameters and coordinate reference system of the query.- Parameters:
original
- SimpleFeatureTypequery
- Query defining attributes and coordinate reference system- Returns:
- SimpleFeatureType updated with the provided CoordinateReferenceSystem
-
copy
public static SimpleFeatureType copy(SimpleFeatureType original)
Copies a feature type.This method does a deep copy in that all individual attributes are copied as well.
-
-