Class TypeBuilder
- Object
-
- TypeBuilder
-
public class TypeBuilder extends Object
Makes building types easier by maintaining state.For reference the builder captures the following state:
* collection implementation may be specifiedState 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>membersMembers 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 TypeBuilderadd(PropertyDescriptor descriptor)Add provided descriptor to the type to be created.voidaddAttribute(String name, Class binding)voidaddAttribute(String uri, String name, Class binding)voidaddAttribute(String name, String namespaceURI, AttributeType type)voidaddAttribute(String name, AttributeType type)voidaddAttribute(Name name, Class binding)voidaddAttribute(Name name, AttributeType type)voidaddBinding(Class binding, AttributeType type)Used to provide a specific type for provided binding.voidaddMemberType(String namespaceURI, String name, AssociationType memberType)Creates a association descriptor and adds to collection members.voidaddMemberType(String name, AssociationType memberType)Creates a association descriptor and adds to collection members.voidaddMemberType(Name name, AssociationType memberType)Creates a association descriptor and adds to collection members.voidaddRestriction(Filter restriction)AssociationTypeassociation()Create AssociationTypeTypeBuilderassociation(String namespaceURI, String name, AssociationType type)TypeBuilderassociation(String name, AssociationType type)TypeBuilderassociation(Name name, AssociationType type)AssociationDescriptorassociationDescriptor()Create an AssociationDesctiptor, define relationships between ComplexAttribtues (in particular FeatureCollection to members).AttributeTypeattribute()Creation method for AttributeType.TypeBuilderattribute(String name, Class binding)Add a descriptor with a provided name, with the bindingTypeBuilderattribute(String namespaceURI, String name, Class binding)Add a descriptor with a provided name, with the bindingTypeBuilderattribute(String name, String namespaceURI, AttributeType type)TypeBuilderattribute(String name, AttributeType type)TypeBuilderattribute(Name name, Class binding)TypeBuilderattribute(Name name, AttributeType type)AttributeDescriptorattributeDescriptor()Create an AttributeDesctiptor, useful for fine grain control.TypeBuilderbind(Class<?> binding)protected Map<Class<?>,AttributeType>bindings()Accessor for bindings.TypeBuildercardinality(int min, int max)voidclear()ComplexTypecomplex()Create a complex attribute, made up of other attributes.static booleancontains(Collection collection, PropertyDescriptor descriptor)protected NamecreateName(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 NamecreateTypeName(String ns, String local)Template method for creating a type name.TypeBuildercrs(String SRS)Uses CRS utility class with buildres TypeFactory.getCRSFactory to look up a CoordinateReferenceSystem based on the provied srs.TypeBuildercrs(CoordinateReferenceSystem crs)protected GeometryDescriptordefaultGeometry()Convenience method for getting the descriptor of the default geometry type.TypeBuilderdefaultGeometry(String name)FeatureTypefeature()Create feature.GeometryTypegeometry()Create GeometryType.AssociationTypegetAssociationSuper()Class<?>getBinding()AttributeTypegetBinding(Class binding)Used to lookup AttributeType for provided binding.CoordinateReferenceSystemgetCRS()NamegetDefaultGeometry()InternationalStringgetDescription()intgetMaxOccurs()CollectiongetMembers()Access to members used by builder.intgetMinOccurs()StringgetName()StringgetNamespaceURI()Collection<PropertyDescriptor>getProperties()Access to properties used by builder.PropertyTypegetPropertyType()AttributeTypegetReferenceType()List<Filter>getRestrictions()AttributeTypegetSuper()FeatureTypeFactorygetTypeFactory()voidinit()Initialize this builder.voidinit(PropertyDescriptor descriptor)voidinit(PropertyType type)booleanisAbstract()booleanisIdentified()booleanisNillable()voidload(Schema schema)Load the indicated schema to map Java class to your Type System.TypeBuildermember(String name, AssociationType type)Creates a association descriptor and adds to collection members.TypeBuildermember(AssociationDescriptor memberOf)TypeBuildermember(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.TypeBuildername(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.TypeBuildernillable(boolean isNillable)protected Collection<PropertyDescriptor>properties()Grab property collection as an argument to factory method.TypeBuilderproperty(PropertyType type)Used as a the target for attributeDescriptor or associatioDescriptor().TypeBuilderreferenceType(AttributeType reference)voidreset()Reset is called after creation a "new" type.protected List<Filter>restrictions()Accessor for restructions which does the null check and creation if necessary.voidsetAbstract(boolean isAbstract)voidsetBinding(Class<?> binding)voidsetCRS(CoordinateReferenceSystem crs)voidsetDefaultGeometry(String name)voidsetDefaultGeometry(String name, String namespaceURI)voidsetDefaultGeometry(Name name)voidsetDescription(InternationalString description)voidsetIdentified(boolean isIdentified)voidsetMaxOccurs(int maxOccurs)voidsetMembers(Collection<PropertyDescriptor> members)Provide collection class used organize collection membersvoidsetMinOccurs(int minOccurs)voidsetName(String name)voidsetNamespaceURI(String namespace)voidsetNillable(boolean isNillable)voidsetProperties(Collection<PropertyDescriptor> properties)Allow for user supplied collection implementaion used for properties.voidsetPropertyType(PropertyType type)voidsetReferenceType(AttributeType reference)Allows you to indicate the reference type to be used with Association to be created.voidsetRestrictions(List<Filter> restrictions)voidsetSuper(PropertyType superType)voidsetTypeFactory(FeatureTypeFactory factory)protected NametypeName()Accessor which returns type banme as follows: IftypeNamehas 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
typeNamehas been set, its value is returned. - If
namehas been set, it +namespaceURIare 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 Setindicates 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 supplieddefaultGeomproperty, 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)
-
-