org.geotools.feature
Class TypeBuilder

Object
  extended by 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  
* collection implementation may be specified

There are five state control methods:

For examples of using this class please see the following type creation methods:

Author:
Justin Deoliveira, Jody Garnett

Field Summary
protected  Collection members
          Members of a collection()
 
Constructor Summary
TypeBuilder(FeatureTypeFactory factory)
           
 
Method Summary
 TypeBuilder add(PropertyDescriptor descriptor)
          Add provided descriptor to the type to be created.
 void addAttribute(Name name, AttributeType type)
           
 void addAttribute(Name name, Class binding)
           
 void addAttribute(String name, AttributeType type)
           
 void addAttribute(String name, Class binding)
           
 void addAttribute(String name, String namespaceURI, AttributeType type)
           
 void addAttribute(String uri, String name, Class binding)
           
 void addBinding(Class binding, AttributeType type)
          Used to provide a specific type for provided binding.
 void addMemberType(Name 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(String namespaceURI, String name, AssociationType memberType)
          Creates a association descriptor and adds to collection members.
 void addRestriction(Filter restriction)
           
 AssociationType association()
          Create AssociationType
 TypeBuilder association(Name name, AssociationType type)
           
 TypeBuilder association(String name, AssociationType type)
           
 TypeBuilder association(String namespaceURI, String 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(Name name, AttributeType type)
           
 TypeBuilder attribute(Name name, Class binding)
           
 TypeBuilder attribute(String name, AttributeType type)
           
 TypeBuilder attribute(String name, Class binding)
          Add a descriptor with a provided name, with the binding
 TypeBuilder attribute(String name, String namespaceURI, AttributeType type)
           
 TypeBuilder attribute(String namespaceURI, String name, Class binding)
          Add a descriptor with a provided name, with the binding
 AttributeDescriptor attributeDescriptor()
          Create an AttributeDesctiptor, useful for fine grain control.
 TypeBuilder bind(Class<?> binding)
           
protected  Map 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(CoordinateReferenceSystem crs)
           
 TypeBuilder crs(String SRS)
          Uses CRS utility class with buildres TypeFactory.getCRSFactory to look up a CoordinateReferenceSystem based on the provied srs.
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(AssociationDescriptor memberOf)
           
 TypeBuilder member(Name name, AssociationType type)
          Creates a association descriptor and adds to collection members.
 TypeBuilder member(String name, AssociationType type)
          Creates a association descriptor and adds to collection members.
protected  Collection members()
          Grab member collection as an argument to factory method.
 TypeBuilder name(String name)
           
protected  Collection<PropertyDescriptor> newCollection()
          Template method to enable subclasses to customize the collection implementation used by "default".
protected  Collection newCollection(Collection 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(Name name)
           
 void setDefaultGeometry(String name)
           
 void setDefaultGeometry(String name, String namespaceURI)
           
 void setDescription(InternationalString description)
           
 void setIdentified(boolean isIdentified)
           
 void setMaxOccurs(int maxOccurs)
           
 void setMembers(Collection members)
          Provide collection class used organize collection members
 void 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: If typeName has been set, its value is returned.
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

members

protected Collection 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:

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:


 AttributeType ROUTE = builder.name("Route").bind(LineString.class).crs("EPSG:4326").geometry();
 
Shape Example Java Rectangle2D:

 builder.setName("Quad");
 builder.setBinding(Rectangle2D.class);
 builder.setCRS(crs);
 AttributeType QUAD = builder.geometry();
 
Use of GeoAPI Geometry interfaces is encouraged as implementations are made avaiable.


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().

Parameters:
type -
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)

getRestrictions

public List<Filter> getRestrictions()

setRestrictions

public void setRestrictions(List<Filter> restrictions)

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:
  1. If typeName has been set, its value is returned.
  2. If name has been set, it + namespaceURI are returned.


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.

Parameters:
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.

Parameters:
binding -
type -

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).

Parameters:
schema -

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:
namespaceURI -
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,
                         Class binding)

addAttribute

public void addAttribute(String uri,
                         String name,
                         Class binding)

addAttribute

public void addAttribute(Name name,
                         Class binding)

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:

The collection class used here should be matched by content described by this type. Explicitly a FeatureType with 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 Collection<PropertyDescriptor> 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 Collection newCollection(Collection origional)
Provides an empty copy of the provided origional collection.

This method is used by reset for the following goals:

This allows a user to indicate that properties are stored in a "LinkedList" once.

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 bindings()
Accessor for bindings.


createName

protected Name createName(String ns,
                          String local)
Template method for creating an attribute name.

Returns:
Types.typeName(String, String)

setDefaultGeometry

public void setDefaultGeometry(String name)

setDefaultGeometry

public void setDefaultGeometry(String name,
                               String namespaceURI)

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 supplied defaultGeom 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:

Parameters:
srs -
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 members)
Provide collection class used organize collection members


members

protected Collection 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.

Parameters:
name -
type -

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.

Parameters:
name -
type -

addMemberType

public void addMemberType(Name name,
                          AssociationType memberType)
Creates a association descriptor and adds to collection members.

Calls clear to reset cardinality after use.

Parameters:
name -
type -

member

public TypeBuilder member(String name,
                          AssociationType type)
Creates a association descriptor and adds to collection members.

Calls clear to reset cardinality after use.

Parameters:
name -
type -
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.

Parameters:
name -
type -
Returns:
TypeBuilder for operation chaining

member

public TypeBuilder member(AssociationDescriptor memberOf)


Copyright © 1996-2014 Geotools. All Rights Reserved.