Class TypeBuilder
- Object
-
- TypeBuilder
-
public class TypeBuilder extends Object
Makes building types easier by maintaining state.For reference the builder captures the following state:
State Property Complex Feature Builder scope state descriptor() attribute() geometry() association() complex() feature() collection() init() reset() clear() naming namespace x x x x x x x x name x x x x x x x x x isIdentified x x x x x x x description x x x x x x x x type isAbstract x x x x x x x superType x x x x x x x restriction* x x x x x x x association referenceType x x descriptor minOccurs x x x maxOccurs x x x isNillable x x x propertyType x x atomic binding x x x complex properties* x x x x x spatial crs x x x x defaultGeom x x x x collection members* x x x There are five state control methods:
init(org.geotools.api.feature.type.PropertyType)
- completly load settings from typeinit(org.geotools.api.feature.type.PropertyDescriptor)
- completly load settings from descriptorinit()
- completly replace settings with builder defaults
For examples of using this class please see the following type creation methods:
attribute()
geometry()
association()
complex()
feature()
collection()
- Author:
- Justin Deoliveira, Jody Garnett
-
-
Field Summary
Fields Modifier and Type Field Description protected Collection<PropertyDescriptor>
members
Members of a collection()
-
Constructor Summary
Constructors Constructor Description TypeBuilder(FeatureTypeFactory factory)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description TypeBuilder
add(PropertyDescriptor descriptor)
Add provided descriptor to the type to be created.void
addAttribute(String name, Class binding)
void
addAttribute(String uri, String name, Class binding)
void
addAttribute(String name, String namespaceURI, AttributeType type)
void
addAttribute(String name, AttributeType type)
void
addAttribute(Name name, Class binding)
void
addAttribute(Name name, AttributeType type)
void
addBinding(Class binding, AttributeType type)
Used to provide a specific type for provided binding.void
addMemberType(String namespaceURI, String name, AssociationType memberType)
Creates a association descriptor and adds to collection members.void
addMemberType(String name, AssociationType memberType)
Creates a association descriptor and adds to collection members.void
addMemberType(Name name, AssociationType memberType)
Creates a association descriptor and adds to collection members.void
addRestriction(Filter restriction)
AssociationType
association()
Create AssociationTypeTypeBuilder
association(String namespaceURI, String name, AssociationType type)
TypeBuilder
association(String name, AssociationType type)
TypeBuilder
association(Name name, AssociationType type)
AssociationDescriptor
associationDescriptor()
Create an AssociationDesctiptor, define relationships between ComplexAttribtues (in particular FeatureCollection to members).AttributeType
attribute()
Creation method for AttributeType.TypeBuilder
attribute(String name, Class binding)
Add a descriptor with a provided name, with the bindingTypeBuilder
attribute(String namespaceURI, String name, Class binding)
Add a descriptor with a provided name, with the bindingTypeBuilder
attribute(String name, String namespaceURI, AttributeType type)
TypeBuilder
attribute(String name, AttributeType type)
TypeBuilder
attribute(Name name, Class binding)
TypeBuilder
attribute(Name name, AttributeType type)
AttributeDescriptor
attributeDescriptor()
Create an AttributeDesctiptor, useful for fine grain control.TypeBuilder
bind(Class<?> binding)
protected Map<Class<?>,AttributeType>
bindings()
Accessor for bindings.TypeBuilder
cardinality(int min, int max)
void
clear()
ComplexType
complex()
Create a complex attribute, made up of other attributes.static boolean
contains(Collection collection, PropertyDescriptor descriptor)
protected Name
createName(String ns, String local)
Template method for creating an attribute name.protected List<Filter>
createRestrictionSet()
Template method to enable subclasses to customize the set implementation used for restrictions.protected Name
createTypeName(String ns, String local)
Template method for creating a type name.TypeBuilder
crs(String SRS)
Uses CRS utility class with buildres TypeFactory.getCRSFactory to look up a CoordinateReferenceSystem based on the provied srs.TypeBuilder
crs(CoordinateReferenceSystem crs)
protected GeometryDescriptor
defaultGeometry()
Convenience method for getting the descriptor of the default geometry type.TypeBuilder
defaultGeometry(String name)
FeatureType
feature()
Create feature.GeometryType
geometry()
Create GeometryType.AssociationType
getAssociationSuper()
Class<?>
getBinding()
AttributeType
getBinding(Class binding)
Used to lookup AttributeType for provided binding.CoordinateReferenceSystem
getCRS()
Name
getDefaultGeometry()
InternationalString
getDescription()
int
getMaxOccurs()
Collection
getMembers()
Access to members used by builder.int
getMinOccurs()
String
getName()
String
getNamespaceURI()
Collection<PropertyDescriptor>
getProperties()
Access to properties used by builder.PropertyType
getPropertyType()
AttributeType
getReferenceType()
List<Filter>
getRestrictions()
AttributeType
getSuper()
FeatureTypeFactory
getTypeFactory()
void
init()
Initialize this builder.void
init(PropertyDescriptor descriptor)
void
init(PropertyType type)
boolean
isAbstract()
boolean
isIdentified()
boolean
isNillable()
void
load(Schema schema)
Load the indicated schema to map Java class to your Type System.TypeBuilder
member(String name, AssociationType type)
Creates a association descriptor and adds to collection members.TypeBuilder
member(AssociationDescriptor memberOf)
TypeBuilder
member(Name name, AssociationType type)
Creates a association descriptor and adds to collection members.protected Collection<PropertyDescriptor>
members()
Grab member collection as an argument to factory method.TypeBuilder
name(String name)
protected <T> Collection<T>
newCollection()
Template method to enable subclasses to customize the collection implementation used by "default".protected <T> Collection<T>
newCollection(Collection<T> origional)
Provides an empty copy of the provided origional collection.TypeBuilder
nillable(boolean isNillable)
protected Collection<PropertyDescriptor>
properties()
Grab property collection as an argument to factory method.TypeBuilder
property(PropertyType type)
Used as a the target for attributeDescriptor or associatioDescriptor().TypeBuilder
referenceType(AttributeType reference)
void
reset()
Reset is called after creation a "new" type.protected List<Filter>
restrictions()
Accessor for restructions which does the null check and creation if necessary.void
setAbstract(boolean isAbstract)
void
setBinding(Class<?> binding)
void
setCRS(CoordinateReferenceSystem crs)
void
setDefaultGeometry(String name)
void
setDefaultGeometry(String name, String namespaceURI)
void
setDefaultGeometry(Name name)
void
setDescription(InternationalString description)
void
setIdentified(boolean isIdentified)
void
setMaxOccurs(int maxOccurs)
void
setMembers(Collection<PropertyDescriptor> members)
Provide collection class used organize collection membersvoid
setMinOccurs(int minOccurs)
void
setName(String name)
void
setNamespaceURI(String namespace)
void
setNillable(boolean isNillable)
void
setProperties(Collection<PropertyDescriptor> properties)
Allow for user supplied collection implementaion used for properties.void
setPropertyType(PropertyType type)
void
setReferenceType(AttributeType reference)
Allows you to indicate the reference type to be used with Association to be created.void
setRestrictions(List<Filter> restrictions)
void
setSuper(PropertyType superType)
void
setTypeFactory(FeatureTypeFactory factory)
protected Name
typeName()
Accessor which returns type banme as follows: IftypeName
has been set, its value is returned.
-
-
-
Field Detail
-
members
protected Collection<PropertyDescriptor> members
Members of a collection()
-
-
Constructor Detail
-
TypeBuilder
public TypeBuilder(FeatureTypeFactory factory)
-
-
Method Detail
-
getTypeFactory
public FeatureTypeFactory getTypeFactory()
-
setTypeFactory
public void setTypeFactory(FeatureTypeFactory factory)
-
reset
public void reset()
Reset is called after creation a "new" type.The following information is reset:
- name
- properties: structural properties (attributes and associations)
- members: collection members
- default geometry
- minOccurs
- maxOccurs
Note: type type of collection class is not reset, a new instanceof the existing collection class is used.
-
clear
public void clear()
-
init
public void init()
Initialize this builder.This method cleans the builder of all contained state.
- See Also:
reset()
-
init
public void init(PropertyDescriptor descriptor)
-
init
public void init(PropertyType type)
-
attribute
public AttributeType attribute()
Creation method for AttributeType.Example:
AttributeType TEXT = builder.name("Text").bind(String.class).attribute();
Example:
builder.setName("Interger"); builder.setBinding(Integer.class); AttributeType INTEGER = builder.attribute();
- Returns:
- AttributeType created
-
association
public AssociationType association()
Create AssociationType
-
geometry
public GeometryType geometry()
Create GeometryType.SFSQL Example JTS LineString.class:
Shape Example Java Rectangle2D:AttributeType ROUTE = builder.name("Route").bind(LineString.class).crs("EPSG:4326").geometry();
Use of GeoAPI Geometry interfaces is encouraged as implementations are made avaiable.builder.setName("Quad"); builder.setBinding(Rectangle2D.class); builder.setCRS(crs); AttributeType QUAD = builder.geometry();
-
complex
public ComplexType complex()
Create a complex attribute, made up of other attributes.Example using Set:
builder.setName("FullName"); builder.setProperties(new HasSet()); builder.addAttribute("first", TEXT); builder.setMinOccurs(0); builder.setMaxOccurs(Integer.MAX_VALUE); builder.addAttribute("middle", TEXT); builder.addAttribute("last", TEXT); ComplexType FULLNAME = builder.complex();
Example using chaining:
ComplexType FULLNAME = builder.name("FullName").attribute("first", TEXT).cardinality(0, Integer.MAX_VALUE).attribute("middle", TEXT).attribute("last", TEXT).complex();
- Returns:
- ComplexType
-
attributeDescriptor
public AttributeDescriptor attributeDescriptor()
Create an AttributeDesctiptor, useful for fine grain control.Example:
AttributeDescriptor name = build.name("name").property(TEXT).cardinality(1, 5) .attributeDescriptor();
- Returns:
- AttributeDescriptor used to define sturcture of ComplexAttribtues
-
associationDescriptor
public AssociationDescriptor associationDescriptor()
Create an AssociationDesctiptor, define relationships between ComplexAttribtues (in particular FeatureCollection to members).Example:
AttributeDescriptor contains = build.name("contains").property(ROAD).nillable(false).cardinality(0, Interger.MAX_VALUE).associationDescriptor();
- Returns:
- AttributeDescriptor used to define sturcture of ComplexAttribtues
-
feature
public FeatureType feature()
Create feature.- Returns:
- FeatureType
-
setNamespaceURI
public void setNamespaceURI(String namespace)
-
getNamespaceURI
public String getNamespaceURI()
-
setName
public void setName(String name)
-
name
public TypeBuilder name(String name)
-
getName
public String getName()
-
setBinding
public void setBinding(Class<?> binding)
-
bind
public TypeBuilder bind(Class<?> binding)
-
getPropertyType
public PropertyType getPropertyType()
-
setPropertyType
public void setPropertyType(PropertyType type)
-
property
public TypeBuilder property(PropertyType type)
Used as a the target for attributeDescriptor or associatioDescriptor().- Returns:
- TypeBuilder (for chaining).
-
getBinding
public Class<?> getBinding()
-
getDescription
public InternationalString getDescription()
-
setDescription
public void setDescription(InternationalString description)
-
setAbstract
public void setAbstract(boolean isAbstract)
-
isAbstract
public boolean isAbstract()
-
nillable
public TypeBuilder nillable(boolean isNillable)
-
setNillable
public void setNillable(boolean isNillable)
-
isNillable
public boolean isNillable()
-
setIdentified
public void setIdentified(boolean isIdentified)
-
isIdentified
public boolean isIdentified()
-
setSuper
public void setSuper(PropertyType superType)
-
getSuper
public AttributeType getSuper()
-
getAssociationSuper
public AssociationType getAssociationSuper()
-
addRestriction
public void addRestriction(Filter restriction)
-
restrictions
protected List<Filter> restrictions()
Accessor for restructions which does the null check and creation if necessary.
-
createRestrictionSet
protected List<Filter> createRestrictionSet()
Template method to enable subclasses to customize the set implementation used for restrictions.- Returns:
- A HashSet.
-
typeName
protected Name typeName()
Accessor which returns type banme as follows:- If
typeName
has been set, its value is returned. - If
name
has been set, it +namespaceURI
are returned.
- If
-
createTypeName
protected Name createTypeName(String ns, String local)
Template method for creating a type name.- Returns:
org.geotools.feature.iso.Types#typeName(String, String)
-
getBinding
public AttributeType getBinding(Class binding)
Used to lookup AttributeType for provided binding.- Returns:
- AttributeType
- Throws:
IllegalArgumentExcception
- if class is not bound to a prototype
-
addBinding
public void addBinding(Class binding, AttributeType type)
Used to provide a specific type for provided binding.You can use this method to map the AttributeType used when addAttribute( String name, Class binding ) is called.
-
load
public void load(Schema schema)
Load the indicated schema to map Java class to your Type System. (please us a profile to prevent binding conflicts).
-
getMinOccurs
public int getMinOccurs()
-
cardinality
public TypeBuilder cardinality(int min, int max)
-
setMinOccurs
public void setMinOccurs(int minOccurs)
-
getMaxOccurs
public int getMaxOccurs()
-
setMaxOccurs
public void setMaxOccurs(int maxOccurs)
-
attribute
public TypeBuilder attribute(String name, Class binding)
Add a descriptor with a provided name, with the binding- Parameters:
name
- Name of descriptor (combined with uri for a Name)binding
- Used to look up a bound AttributeType- Returns:
- this builder for additional chaining
-
attribute
public TypeBuilder attribute(String namespaceURI, String name, Class binding)
Add a descriptor with a provided name, with the binding- Parameters:
name
- Name of descriptor (combined with uri for a Name)binding
- Used to look up a bound AttributeType- Returns:
- this builder for additional chaining
-
attribute
public TypeBuilder attribute(Name name, Class binding)
-
attribute
public TypeBuilder attribute(String name, String namespaceURI, AttributeType type)
-
attribute
public TypeBuilder attribute(String name, AttributeType type)
-
attribute
public TypeBuilder attribute(Name name, AttributeType type)
-
addAttribute
public void addAttribute(String name, AttributeType type)
-
addAttribute
public void addAttribute(String name, String namespaceURI, AttributeType type)
-
addAttribute
public void addAttribute(Name name, AttributeType type)
-
setReferenceType
public void setReferenceType(AttributeType reference)
Allows you to indicate the reference type to be used with Association to be created.
-
referenceType
public TypeBuilder referenceType(AttributeType reference)
-
getReferenceType
public AttributeType getReferenceType()
-
association
public TypeBuilder association(String name, AssociationType type)
-
association
public TypeBuilder association(String namespaceURI, String name, AssociationType type)
-
association
public TypeBuilder association(Name name, AssociationType type)
-
add
public TypeBuilder add(PropertyDescriptor descriptor)
Add provided descriptor to the type to be created.Please note that you may not have two types with the same name, depending on the factory being used the order of the structural content may be signficant - this builder will preserve order although the factory may or may not make use of this fact.
-
contains
public static boolean contains(Collection collection, PropertyDescriptor descriptor)
-
getProperties
public Collection<PropertyDescriptor> getProperties()
Access to properties used by builder.You can use this method to perform collection opperations before construction. This is most useful when initializing the builder with a known type, performing modifications, and then creating a derrived type.
-
setProperties
public void setProperties(Collection<PropertyDescriptor> properties)
Allow for user supplied collection implementaion used for properties.Examples of useful property collections:
- List - structured properties maintained in order
- Set - order of structured properties insignificant
- etc...
getProperties() instanceof Set
indicates that Features of that FeatureType should maintain a Set of properties where order is not significant.- Parameters:
properties
- Collection implementation used to organize properties
-
newCollection
protected <T> Collection<T> newCollection()
Template method to enable subclasses to customize the collection implementation used by "default".Considered moving this to the type interface but it would be in appropriate as the user may need to specifiy different collections for seperate types in the same schema.
- Returns:
- Collection (subclass may override)
-
newCollection
protected <T> Collection<T> newCollection(Collection<T> origional)
Provides an empty copy of the provided origional collection.This method is used by reset for the following goals:
- use the user supplied collection directly by the TypeFactory,
- remember the user supplied collection type for subsequent builder use
- Parameters:
origional
- Origional collection- Returns:
- New instance of the originoal Collection
-
properties
protected Collection<PropertyDescriptor> properties()
Grab property collection as an argument to factory method.This may return a copy as needed, since most calls to a factory method end up with a reset this seems not be needed at present.
-
bindings
protected Map<Class<?>,AttributeType> bindings()
Accessor for bindings.
-
createName
protected Name createName(String ns, String local)
Template method for creating an attribute name.- Returns:
org.geotools.feature.Types#typeName(String, String)
-
setDefaultGeometry
public void setDefaultGeometry(String name)
-
setDefaultGeometry
public void setDefaultGeometry(Name name)
-
defaultGeometry
public TypeBuilder defaultGeometry(String name)
-
getDefaultGeometry
public Name getDefaultGeometry()
-
defaultGeometry
protected GeometryDescriptor defaultGeometry()
Convenience method for getting the descriptor of the default geometry type. This method will first try to look up the supplieddefaultGeom
property, if it cant find, it will try to locate any added geometry.
-
setCRS
public void setCRS(CoordinateReferenceSystem crs)
-
crs
public TypeBuilder crs(CoordinateReferenceSystem crs)
-
crs
public TypeBuilder crs(String SRS)
Uses CRS utility class with buildres TypeFactory.getCRSFactory to look up a CoordinateReferenceSystem based on the provied srs.A SpatialReferenceSystem can be one of the following:
- "AUTHORITY:CODE"
- Well Known Text
- Returns:
- TypeBuilder ready for chaining
- Throws:
IllegalArgumentException
- When SRS not understood
-
getCRS
public CoordinateReferenceSystem getCRS()
-
getMembers
public Collection getMembers()
Access to members used by builder.You can use this method to perform collection opperations before construction. This is most useful when initializing the builder with a known type, performing modifications, and then creating a derrived type.
-
setMembers
public void setMembers(Collection<PropertyDescriptor> members)
Provide collection class used organize collection members
-
members
protected Collection<PropertyDescriptor> members()
Grab member collection as an argument to factory method.This may return a copy as needed, since most calls to a factory method end up with a reset this seems not be needed at present.
-
addMemberType
public void addMemberType(String name, AssociationType memberType)
Creates a association descriptor and adds to collection members.Calls clear to reset cardinality after use.
-
addMemberType
public void addMemberType(String namespaceURI, String name, AssociationType memberType)
Creates a association descriptor and adds to collection members.Calls clear to reset cardinality after use.
-
addMemberType
public void addMemberType(Name name, AssociationType memberType)
Creates a association descriptor and adds to collection members.Calls clear to reset cardinality after use.
-
member
public TypeBuilder member(String name, AssociationType type)
Creates a association descriptor and adds to collection members.Calls clear to reset cardinality after use.
- Returns:
- TypeBuilder for operation chaining
-
member
public TypeBuilder member(Name name, AssociationType type)
Creates a association descriptor and adds to collection members.Calls clear to reset cardinality after use.
- Returns:
- TypeBuilder for operation chaining
-
member
public TypeBuilder member(AssociationDescriptor memberOf)
-
-