public class FeatureTypeBuilder extends TypeBuilder
FeatureType
instances.
This builder can create the arguments to be given to the
feature type constructor
from simpler parameters given to this builder.
The main methods provided in this class are:
setName(...)
methods for specifying the feature type name (mandatory).build()
method for creating the FeatureType
instance from all previous information.FeatureTypeBuilder builder; // Create a feature type for a city, which contains a name and a population. builder = new FeatureTypeBuilder() .setName("City"); builder.addAttribute(String.class) .setName("name").setDefaultValue("Utopia"); builder.addAttribute(Integer.class).setName("population"); FeatureType city = builder.build();A call to
System.out.println(city)
prints the following table:
City ┌────────────┬─────────┬─────────────┬───────────────┐ │ Name │ Type │ Cardinality │ Default value │ ├────────────┼─────────┼─────────────┼───────────────┤ │ name │ String │ [1 … 1] │ Utopia │ │ population │ Integer │ [1 … 1] │ │ └────────────┴─────────┴─────────────┴───────────────┘
FeatureTypeBuilder
instances should be short lived.
After the FeatureType
has been created, the builder should be discarded.
ParameterBuilder
Defined in the sis-feature
module
Constructor and Description |
---|
FeatureTypeBuilder()
Creates a new builder instance using the default name factory.
|
FeatureTypeBuilder(DefaultFeatureType template)
Creates a new builder instance using the given feature type as a template.
|
FeatureTypeBuilder(NameFactory factory,
GeometryLibrary library,
Locale locale)
Creates a new builder instance using the given name factory, geometry library
and locale for formatting error messages.
|
Modifier and Type | Method and Description |
---|---|
AssociationRoleBuilder |
addAssociation(DefaultAssociationRole template)
Creates a new
FeatureAssociationRole builder initialized to the same characteristics
than the given template. |
AssociationRoleBuilder |
addAssociation(DefaultFeatureType type)
Creates a new
FeatureAssociationRole builder for features of the given type. |
AssociationRoleBuilder |
addAssociation(GenericName type)
Creates a new
FeatureAssociationRole builder for features of a type of the given name. |
<V> AttributeTypeBuilder<V> |
addAttribute(Class<V> valueClass)
Creates a new
AttributeType builder for values of the given class. |
<V> AttributeTypeBuilder<V> |
addAttribute(DefaultAttributeType<V> template)
Creates a new
AttributeType builder initialized to the same characteristics than the given template. |
AttributeTypeBuilder<?> |
addAttribute(GeometryType type)
Creates a new attribute for geometries of the given type.
|
PropertyTypeBuilder |
addProperty(AbstractIdentifiedType template)
Adds the given property in the feature type properties.
|
DefaultFeatureType |
build()
Builds the feature type from the information and properties specified to this builder.
|
FeatureTypeBuilder |
clear()
Clears all setting in this builder.
|
CharSequence |
getNameSpace()
Returns the namespace of the names created by
setName(CharSequence...) method calls. |
PropertyTypeBuilder |
getProperty(String name)
Returns the builder for the property of the given name.
|
DefaultFeatureType[] |
getSuperTypes()
Returns the direct parents of the feature type to create.
|
boolean |
isAbstract()
Returns
true if the feature type to create will act as an abstract super-type. |
List<PropertyTypeBuilder> |
properties()
Returns a view of all attributes and associations added to the
FeatureType to build. |
FeatureTypeBuilder |
setAbstract(boolean isAbstract)
Sets whether the feature type to create will be abstract.
|
FeatureTypeBuilder |
setAll(DefaultFeatureType template)
Sets all properties of this builder to the values of the given feature type.
|
FeatureTypeBuilder |
setDefaultCardinality(int minimumOccurs,
int maximumOccurs)
Sets the default minimum and maximum number of next attributes and associations to add.
|
FeatureTypeBuilder |
setDefinition(CharSequence definition)
Sets a concise definition of the element.
|
FeatureTypeBuilder |
setDeprecated(boolean deprecated)
Sets whether the type is deprecated.
|
FeatureTypeBuilder |
setDescription(CharSequence description)
Sets optional information beyond that required for concise definition of the element.
|
FeatureTypeBuilder |
setDesignation(CharSequence designation)
Sets a natural language designator for the element.
|
FeatureTypeBuilder |
setIdentifierDelimiters(String delimiter,
String prefix,
String suffix)
Sets the prefix, suffix and delimiter to use when formatting a compound identifier made of two or more attributes.
|
FeatureTypeBuilder |
setName(CharSequence... components)
Sets the
FeatureType name as a string in the given scope. |
FeatureTypeBuilder |
setName(CharSequence localPart)
Sets the
FeatureType name as a simple string. |
FeatureTypeBuilder |
setName(GenericName name)
Sets the
FeatureType name as a generic name. |
FeatureTypeBuilder |
setNameSpace(CharSequence ns)
Sets the namespace of the next names to be created by
setName(CharSequence...) method calls. |
FeatureTypeBuilder |
setSuperTypes(DefaultFeatureType... parents)
Sets the parent types (or super-type) from which to inherit properties.
|
getDefinition, getDescription, getDesignation, getLocale, getName, isDeprecated, toString
public FeatureTypeBuilder()
public FeatureTypeBuilder(DefaultFeatureType template)
isAbstract
flag
to values inferred from the given template. The properties list will contain properties
declared explicitely in the given template, not including properties inherited from super types.
template
argument type will be changed to FeatureType
if and when such interface
will be defined in GeoAPI.template
- an existing feature type to use as a template, or null
if none.public FeatureTypeBuilder(NameFactory factory, GeometryLibrary library, Locale locale)
factory
- the factory to use for creating names, or null
for the default factory.library
- the library to use for creating geometric objects, or null
for the default.locale
- the locale to use for formatting error messages, or null
for the default locale.public FeatureTypeBuilder clear()
FeatureTypeBuilder
is in same state that after it has been constructed. This method can be invoked for reusing the
same builder for creating other FeatureType
instances after build()
invocation.this
for allowing method calls chaining.public FeatureTypeBuilder setAll(DefaultFeatureType template)
template
argument type will be changed to FeatureType
if and when such interface
will be defined in GeoAPI.template
- an existing feature type to use as a template, or null
if none.this
for allowing method calls chaining.public boolean isAbstract()
true
if the feature type to create will act as an abstract super-type.
Abstract types can not be instantiated.true
if the feature type to create will act as an abstract super-type.DefaultFeatureType.isAbstract()
public FeatureTypeBuilder setAbstract(boolean isAbstract)
false
.isAbstract
- whether the feature type will be abstract.this
for allowing method calls chaining.public DefaultFeatureType[] getSuperTypes()
FeatureType[]
if and when such interface
will be defined in GeoAPI.DefaultFeatureType.getSuperTypes()
public FeatureTypeBuilder setSuperTypes(DefaultFeatureType... parents)
parents
argument type will be changed to FeatureType...
if and when such interface
will be defined in GeoAPI.parents
- the parent types from which to inherit properties, or an empty array if none.
Null elements are ignored.this
for allowing method calls chaining.public CharSequence getNameSpace()
setName(CharSequence...)
method calls.
A null
value means that the names are in the
global namespace.setName(CharSequence)
is invoked, or null
if none.public FeatureTypeBuilder setNameSpace(CharSequence ns)
setName(CharSequence...)
method calls.
This method applies only to the next calls to setName(CharSequence)
or
setName(CharSequence...)
methods; the result of all previous calls stay unmodified.
Example:
FeatureTypeBuilder builder = new FeatureTypeBuilder().setNameSpace("MyNameSpace").setName("City"); FeatureType city = builder.build(); System.out.println(city.getName()); // Prints "City" System.out.println(city.getName().toFullyQualifiedName()); // Prints "MyNameSpace:City"There is different conventions about the use of name spaces. ISO 19109 suggests that the namespace of all
AttributeType
names is the name of the enclosing FeatureType
, but this is not mandatory.
Users who want to apply this convention can invoke setNameSpace(featureName)
after
FeatureTypeBuilder.setName(featureName)
but before
AttributeTypeBuilder.setName(attributeName)
.ns
- the new namespace, or null
if none.this
for allowing method calls chaining.public FeatureTypeBuilder setName(GenericName name)
FeatureType
name as a generic name.
If another name was defined before this method call, that previous value will be discarded.
setName(…)
convenience methods in this builder delegate to this method.
Consequently this method can be used as a central place where to control the creation of all names.setName
in class TypeBuilder
name
- the generic name (can not be null
).this
for allowing method calls chaining.TypeBuilder.getName()
,
TypeBuilder.setName(CharSequence)
,
AbstractIdentifiedType.NAME_KEY
public FeatureTypeBuilder setName(CharSequence localPart)
FeatureType
name as a simple string.
The namespace will be the value specified by the last call to setNameSpace(CharSequence)
,
but that namespace will not be visible in the string representation unless the fully qualified name is requested.
This convenience method creates a LocalName
instance from
the given CharSequence
, then delegates to setName(GenericName)
.
setName
in class TypeBuilder
localPart
- the local part of the generic name as a String
or InternationalString
.this
for allowing method calls chaining.TypeBuilder.getName()
,
TypeBuilder.setName(CharSequence...)
,
getNameSpace()
public FeatureTypeBuilder setName(CharSequence... components)
FeatureType
name as a string in the given scope.
The components
array must contain at least one element.
In addition to the path specified by the components
array, the name may also contain
a namespace specified by the last call to setNameSpace(CharSequence)
.
But contrarily to the specified components, the namespace will not be visible in the name
string representation unless the
fully qualified name is requested.
This convenience method creates a LocalName
or ScopedName
instance depending on whether the names
array contains exactly 1 element or more than 1 element, then
delegates to setName(GenericName)
.
setName
in class TypeBuilder
components
- the name components as an array of String
or InternationalString
instances.this
for allowing method calls chaining.TypeBuilder.getName()
,
TypeBuilder.setName(CharSequence)
,
getNameSpace()
public FeatureTypeBuilder setDefaultCardinality(int minimumOccurs, int maximumOccurs)
addAttribute(Class)
.
Attributes and associations added before this method call are not modified.
If this method is not invoked, then the default cardinality is [1 … 1].
minimumOccurs
- new default minimum number of property values.maximumOccurs
- new default maximum number of property values.this
for allowing method calls chaining.PropertyTypeBuilder.setMinimumOccurs(int)
,
PropertyTypeBuilder.setMaximumOccurs(int)
public FeatureTypeBuilder setIdentifierDelimiters(String delimiter, String prefix, String suffix)
If this method is not invoked, then the default values are the ":"
delimiter and no prefix or suffix.
delimiter
- the characters to use as delimiter between each single property value.prefix
- characters to use at the beginning of the concatenated string, or null
if none.suffix
- characters to use at the end of the concatenated string, or null
if none.this
for allowing method calls chaining.AttributeRole.IDENTIFIER_COMPONENT
public List<PropertyTypeBuilder> properties()
FeatureType
to build.
This list contains only properties declared explicitely to this builder;
it does not include properties inherited from super-types.
The returned list is live: changes in this builder are reflected in that list and conversely.
However the returned list allows only remove operations;
new attributes or associations can be added only by calls to one of the addAttribute(…)
or addAssociation(…)
methods. Removal operations never affect the super-types.getProperty(String)
,
addAttribute(Class)
,
addAttribute(DefaultAttributeType)
,
addAssociation(DefaultFeatureType)
,
addAssociation(GenericName)
,
addAssociation(DefaultAssociationRole)
public PropertyTypeBuilder getProperty(String name)
ScopedName
; it is okay to specify only the tip (for example "myName"
instead of "myScope:myName"
) provided that ignoring the name head does not create ambiguity.name
- name of the property to search.null
if none.IllegalArgumentException
- if the given name is ambiguous.public <V> AttributeTypeBuilder<V> addAttribute(Class<V> valueClass)
AttributeType
builder for values of the given class.
The default attribute name is the name of the given type, but callers should invoke one
of the AttributeTypeBuilder.setName(…)
methods on the returned instance with a better name.
Usage example:
builder.addAttribute(String.class).setName("City").setDefaultValue("Metropolis");The value class can not be
Feature.class
since features shall be handled
as associations instead than attributes.V
- the compile-time value of valueClass
argument.valueClass
- the class of attribute values (can not be Feature.class
).AttributeType
.properties()
public <V> AttributeTypeBuilder<V> addAttribute(DefaultAttributeType<V> template)
AttributeType
builder initialized to the same characteristics than the given template.
template
argument type will be changed to AttributeType
if and when such interface
will be defined in GeoAPI.V
- the compile-time type of values in the template
argument.template
- an existing attribute type to use as a template.AttributeType
, initialized with the values of the given template.properties()
public AttributeTypeBuilder<?> addAttribute(GeometryType type)
addAttribute(Class)
with a valueClass
argument inferred from the combination of the GeometryType
argument given to
this method with the GeometryLibrary
argument given at builder creation time.
The geometry type can be:
GeometryType.POINT
for Point
or Point2D
type.GeometryType.LINEAR
for Polyline
or LineString
type.GeometryType.AREAL
for Polygon
type.Point2D
if the library in use is Java2D.
The Coordinate Reference System (CRS) uses (longitude, latitude) axes on the WGS 84 datum.
Finally that new attribute is declared the feature default geometry:
builder.addAttribute(GeometryType.POINT).setName("MyPoint") .setCRS(CommonCRS.WGS84.normalizedGeographic()) .addRole(AttributeRole.DEFAULT_GEOMETRY);If the library in use is JTS or ESRI instead than Java2D, then the
Point
class of those libraries will be used instead of Point2D
.
The fully-qualified class names are given in the GeometryLibrary
javadoc.type
- kind of geometric object (point, polyline or polygon).AttributeType
.public AssociationRoleBuilder addAssociation(DefaultFeatureType type)
FeatureAssociationRole
builder for features of the given type.
The default association name is the name of the given type, but callers should invoke one
of the AssociationRoleBuilder.setName(…)
methods on the returned instance with a better name.
type
argument type will be changed to FeatureType
if and when such interface
will be defined in GeoAPI.type
- the type of feature values.FeatureAssociationRole
.properties()
public AssociationRoleBuilder addAssociation(GenericName type)
FeatureAssociationRole
builder for features of a type of the given name.
This method can be invoked as an alternative to addAssociation(FeatureType)
when the
FeatureType
instance is not yet available because of cyclic dependency.type
- the name of the type of feature values.FeatureAssociationRole
.properties()
public AssociationRoleBuilder addAssociation(DefaultAssociationRole template)
FeatureAssociationRole
builder initialized to the same characteristics
than the given template.
template
argument type will be changed to FeatureAssociationRole
if and when such interface
will be defined in GeoAPI.template
- an existing feature association to use as a template.FeatureAssociationRole
, initialized with the values of the given template.properties()
public PropertyTypeBuilder addProperty(AbstractIdentifiedType template)
AttributeType
, in which case this method delegate to addAttribute(AttributeType)
.FeatureAssociationRole
, in which case this method delegate to addAssociation(FeatureAssociationRole)
.Operation
, in which case the given operation object will be added verbatim in the FeatureType
;
this builder does not create new operations.org.opengis.feature.PropertyType
interface. This change is pending GeoAPI revision.template
- the property to add to the feature type.Operation
case, the builder is a read-only accessor on the operation properties.properties()
,
getProperty(String)
public FeatureTypeBuilder setDefinition(CharSequence definition)
setDefinition
in class TypeBuilder
definition
- a concise definition of the element, or null
if none.this
for allowing method calls chaining.TypeBuilder.getDefinition()
,
AbstractIdentifiedType.DEFINITION_KEY
public FeatureTypeBuilder setDesignation(CharSequence designation)
setDesignation
in class TypeBuilder
designation
- a natural language designator for the element, or null
if none.this
for allowing method calls chaining.TypeBuilder.getDesignation()
,
AbstractIdentifiedType.DESIGNATION_KEY
public FeatureTypeBuilder setDescription(CharSequence description)
setDescription
in class TypeBuilder
description
- information beyond that required for concise definition of the element, or null
if none.this
for allowing method calls chaining.TypeBuilder.getDescription()
,
AbstractIdentifiedType.DESCRIPTION_KEY
public FeatureTypeBuilder setDeprecated(boolean deprecated)
setDeprecated
in class TypeBuilder
deprecated
- whether this type is deprecated.this
for allowing method calls chaining.TypeBuilder.isDeprecated()
,
AbstractIdentifiedType.DEPRECATED_KEY
public DefaultFeatureType build() throws IllegalStateException
setName(…)
methods must have been invoked before this build()
method (mandatory).
All other methods are optional, but some calls to a add
method are usually needed.
org.opengis.feature.FeatureType
interface. This change is pending GeoAPI revision.If a feature type has already been built and this builder state has not changed since the
feature type creation, then the previously created FeatureType
instance is returned.
build
in class TypeBuilder
IllegalStateException
- if the builder contains inconsistent information.clear()
Copyright © 2010–2017 The Apache Software Foundation. All rights reserved.