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  
* 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 Details

  • Constructor Details

  • Method Details

    • 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:
    • 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().
      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.
      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, 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:

      • List - structured properties maintained in order
      • Set - order of structured properties insignificant
      • etc...
      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 <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
      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<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(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

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