|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
ObjectSimpleFeatureTypeBuilder
public class SimpleFeatureTypeBuilder
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" );
modules/library/main (gt-main.jar)
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 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: 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,
CoordinateReferenceSystem crs)
Create a SimpleFeatureType with the same content; just updating the geometry attribute to match the provided coordinate reference system. |
static SimpleFeatureType |
retype(SimpleFeatureType original,
String[] types)
Create a SimpleFeatureType containing just the descriptors indicated. |
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 |
---|
protected FeatureTypeFactory factory
protected Map bindings
protected String local
protected String uri
protected InternationalString description
protected List<AttributeDescriptor> attributes
protected List<Filter> restrictions
protected String defaultGeometry
protected CoordinateReferenceSystem crs
protected boolean isAbstract
protected SimpleFeatureType superType
protected AttributeTypeBuilder attributeBuilder
Constructor Detail |
---|
public SimpleFeatureTypeBuilder()
public SimpleFeatureTypeBuilder(FeatureTypeFactory factory)
Method Detail |
---|
public void setFeatureTypeFactory(FeatureTypeFactory factory)
public FeatureTypeFactory getFeatureTypeFactory()
public void init(SimpleFeatureType type)
protected void init()
protected void reset()
public void setNamespaceURI(String namespaceURI)
public void setNamespaceURI(URI namespaceURI)
public String getNamespaceURI()
public void setName(String name)
public String getName()
public void setName(Name name)
public void setDescription(InternationalString description)
public InternationalString getDescription()
public void setDefaultGeometry(String defaultGeometryName)
public String getDefaultGeometry()
public void setCRS(CoordinateReferenceSystem crs)
public CoordinateReferenceSystem getCRS()
public void setSRS(String srs)
IllegalArgumentException
- When the srs specified can be decored
into a crs.public void setAbstract(boolean isAbstract)
public boolean isAbstract()
public void setSuperType(SimpleFeatureType superType)
public SimpleFeatureType getSuperType()
public void addBinding(AttributeType type)
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.
type
- The attribute type.public void addBindings(Schema schema)
schema
- The schema containing the attribute types.#addBinding(AttributeType)}.
public void setBindings(Schema schema)
schema
- The schema contianing attribute types.#addBinding(AttributeType)}.
public AttributeType getBinding(Class<?> binding)
binding
- The class.
public SimpleFeatureTypeBuilder minOccurs(int minOccurs)
This value is reset after a call to add(String, Class)
public SimpleFeatureTypeBuilder maxOccurs(int maxOccurs)
This value is reset after a call to add(String, Class)
public SimpleFeatureTypeBuilder nillable(boolean isNillable)
This value is reset after a call to add(String, Class)
public SimpleFeatureTypeBuilder length(int length)
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)
public SimpleFeatureTypeBuilder restriction(Filter filter)
This value is reset after a call to add(String, Class)
public SimpleFeatureTypeBuilder restrictions(List<Filter> filters)
This value is reset after a call to add(String, Class)
public SimpleFeatureTypeBuilder description(String description)
This value is reset after a call to add(String, Class)
public SimpleFeatureTypeBuilder defaultValue(Object defaultValue)
This value is reset after a call to add(String, Class)
public SimpleFeatureTypeBuilder crs(CoordinateReferenceSystem crs)
This only applies if the attribute added is geometric.
This value is reset after a call to add(String, Class)
public SimpleFeatureTypeBuilder srs(String srs)
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)
srs
- The spatial reference system.public SimpleFeatureTypeBuilder srid(Integer srid)
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)
srid
- The id of a spatial reference system.public SimpleFeatureTypeBuilder userData(Object key, Object value)
This value is reset after a call to add(String, Class)
key
- The key of the user data.value
- The value of the user data.public SimpleFeatureTypeBuilder descriptor(AttributeDescriptor descriptor)
This method is convenience for:
builder.minOccurs( descriptor.getMinOccurs() ).maxOccurs( descriptor.getMaxOccurs() )
.nillable( descriptor.isNillable() )...
public void add(String name, Class binding)
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.
name
- The name of the attribute.bind
- The class the attribute is bound to.public void add(AttributeDescriptor descriptor)
Use of this method is discouraged. Consider using add(String, Class)
.
public AttributeDescriptor remove(String attributeName)
attributeName
- the name of the AttributeDescriptor to remove
IllegalArgumentException
- if there is no AttributeDescriptor with the name attributeNamepublic void add(int index, AttributeDescriptor descriptor)
Use of this method is discouraged. Consider using add(String, Class)
.
public void addAll(List<AttributeDescriptor> descriptors)
Use of this method is discouraged. Consider using add(String, Class)
.
public void addAll(AttributeDescriptor[] descriptors)
Use of this method is discouraged. Consider using add(String, Class)
.
public void add(String name, Class binding, CoordinateReferenceSystem crs)
The crs parameter may be null
.
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
.public void add(String name, Class binding, String srs)
The srs parameter may be null
.
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
.public void add(String name, Class binding, Integer srid)
The srid parameter may be null
.
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
.public void setAttributes(List<AttributeDescriptor> attributes)
attributes
- the new list of attributes, or null to reset the listpublic void setAttributes(AttributeDescriptor[] attributes)
attributes
- the new list of attributes, or null to reset the listpublic SimpleFeatureType buildFeatureType()
After the type is built the running list of attributes is cleared.
protected Set newSet()
HashSet
.
protected List newList()
ArrayList
.
protected Map newMap()
HashMap
protected List newList(List origional)
If the new copy can not be created reflectively.. newList()
is
returned.
protected Name name()
typeName
has been set, its value is returned.
name
has been set, it + namespaceURI
are returned.
protected List<AttributeDescriptor> attributes()
protected List<Filter> restrictions()
protected Map bindings()
protected CoordinateReferenceSystem decode(String srs)
public static SimpleFeatureType retype(SimpleFeatureType original, String[] types)
original
- SimpleFeatureTypetypes
- name of types to include in result
public static SimpleFeatureType retype(SimpleFeatureType original, CoordinateReferenceSystem crs)
original
- SimpleFeatureTypecrs
- CoordianteReferenceSystem of result
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |