Object
TypeBuilder
FeatureTypeBuilder
- All Implemented Interfaces:
Localized
Helper class for the creation of
A call to
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:
- Various
setName(...)
methods for specifying the feature type name (mandatory). - Methods for optionally setting designation, definition or description texts, or the deprecation status.
- Methods for optionally specifying the feature type hierarchy: its super types and whether the feature type is abstract.
- Convenience methods for setting the name space and the default multiplicity of properties to be added to the feature type.
- Methods for adding an attribute, an association or an operation.
- Method for listing the previously added properties.
- A
build()
method for creating theFeatureType
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();
System.out.println(city)
prints the following table:
City ┌────────────┬─────────┬──────────────┬───────────────┐ │ Name │ Type │ Multiplicity │ 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.- Since:
- 0.8
- See Also:
-
Constructor Summary
ConstructorDescriptionCreates 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. -
Method Summary
Modifier and TypeMethodDescriptionaddAssociation
(DefaultAssociationRole template) Creates a newFeatureAssociationRole
builder initialized to the same characteristics than the given template.Creates a newFeatureAssociationRole
builder for features of the given type.addAssociation
(GenericName type) Creates a newFeatureAssociationRole
builder for features of a type of the given name.<V> AttributeTypeBuilder
<V> addAttribute
(Class<V> valueClass) Creates a newAttributeType
builder for values of the given class.<V> AttributeTypeBuilder
<V> addAttribute
(DefaultAttributeType<V> template) Creates a newAttributeType
builder initialized to the same characteristics than the given template.addAttribute
(GeometryType type) Creates a new attribute for geometries of the given type.addProperty
(AbstractIdentifiedType template) Adds the given property in the feature type properties.build()
Builds the feature type from the information and properties specified to this builder.clear()
Clears all setting in this builder.Returns the namespace of the names created bysetName(CharSequence...)
method calls.getProperty
(String name) Returns the builder for the property of the given name.Returns the direct parents of the feature type to create.boolean
Returnstrue
if the feature type to create will act as an abstract super-type.boolean
isNameUsed
(String name) Returnstrue
if a property of the given name is defined or if the given name is ambiguous.Returns a view of all attributes and associations added to theFeatureType
to build.setAbstract
(boolean isAbstract) Sets whether the feature type to create will be abstract.setAll
(DefaultFeatureType template) Sets all properties of this builder to the values of the given feature type.setDefaultMultiplicity
(int minimumOccurs, int maximumOccurs) Sets the default minimum and maximum number of next attributes and associations to add.setDefinition
(CharSequence definition) Sets a concise definition of the element.setDeprecated
(boolean deprecated) Sets whether the type is deprecated.setDescription
(CharSequence description) Sets optional information beyond that required for concise definition of the element.setDesignation
(CharSequence designation) Sets a natural language designator for the element.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.setName
(CharSequence localPart) Sets theFeatureType
name as a simple string.setName
(CharSequence... components) Sets theFeatureType
name as a string in the given scope.setName
(GenericName name) Sets theFeatureType
name as a generic name.Sets the namespace of the next names to be created bysetName(CharSequence...)
method calls.setSuperTypes
(DefaultFeatureType... parents) Sets the parent types (or super-type) from which to inherit properties.Methods inherited from class TypeBuilder
getDefinition, getDescription, getDesignation, getLocale, getName, isDeprecated, toString
-
Constructor Details
-
FeatureTypeBuilder
public FeatureTypeBuilder()Creates a new builder instance using the default name factory. -
FeatureTypeBuilder
Creates a new builder instance using the given feature type as a template. This constructor initializes the list of properties, the super types andisAbstract
flag to values inferred from the given template. The properties list will contain properties declared explicitly in the given template, not including properties inherited from super types.Warning: Thetemplate
argument type will be changed toFeatureType
if and when such interface will be defined in GeoAPI.- Parameters:
template
- an existing feature type to use as a template, ornull
if none.
-
FeatureTypeBuilder
Creates a new builder instance using the given name factory, geometry library and locale for formatting error messages.- Parameters:
factory
- the factory to use for creating names, ornull
for the default factory.library
- the library to use for creating geometric objects, ornull
for the default.locale
- the locale to use for formatting error messages, ornull
for the default locale.
-
-
Method Details
-
clear
Clears all setting in this builder. After invoking this method, thisFeatureTypeBuilder
is in same state that after it has been constructed. This method can be invoked for reusing the same builder for creating otherFeatureType
instances afterbuild()
invocation.- Returns:
this
for allowing method calls chaining.
-
setAll
Sets all properties of this builder to the values of the given feature type. This builder is cleared before the properties of the given type are copied. The copy is performed as documented in the constructor.Warning: Thetemplate
argument type will be changed toFeatureType
if and when such interface will be defined in GeoAPI.- Parameters:
template
- an existing feature type to use as a template, ornull
if none.- Returns:
this
for allowing method calls chaining.
-
isAbstract
public boolean isAbstract()Returnstrue
if the feature type to create will act as an abstract super-type. Abstract types cannot be instantiated.- Returns:
true
if the feature type to create will act as an abstract super-type.- See Also:
-
setAbstract
Sets whether the feature type to create will be abstract. If this method is not invoked, then the default value isfalse
.- Parameters:
isAbstract
- whether the feature type will be abstract.- Returns:
this
for allowing method calls chaining.
-
getSuperTypes
Returns the direct parents of the feature type to create.Warning: The return type will be changed toFeatureType[]
if and when such interface will be defined in GeoAPI.- Returns:
- the parents of the feature type to create, or an empty array if none.
- See Also:
-
setSuperTypes
Sets the parent types (or super-type) from which to inherit properties. If this method is not invoked, then the default value is no parent.Warning: Theparents
argument type will be changed toFeatureType...
if and when such interface will be defined in GeoAPI.- Parameters:
parents
- the parent types from which to inherit properties, or an empty array if none. Null elements are ignored.- Returns:
this
for allowing method calls chaining.
-
getNameSpace
Returns the namespace of the names created bysetName(CharSequence...)
method calls. Anull
value means that the names are in the global namespace.- Returns:
- the namespace to use when
setName(CharSequence)
is invoked, ornull
if none.
-
setNameSpace
Sets the namespace of the next names to be created bysetName(CharSequence...)
method calls. This method applies only to the next calls tosetName(CharSequence)
orsetName(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"
AttributeType
names is the name of the enclosingFeatureType
, but this is not mandatory. Users who want to apply this convention can invokesetNameSpace(featureName)
afterFeatureTypeBuilder.setName(featureName)
but beforeAttributeTypeBuilder.setName(attributeName)
.- Parameters:
ns
- the new namespace, ornull
if none.- Returns:
this
for allowing method calls chaining.
-
setName
Sets theFeatureType
name as a generic name. If another name was defined before this method call, that previous value will be discarded.Note for subclasses
AllsetName(…)
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.- Overrides:
setName
in classTypeBuilder
- Parameters:
name
- the generic name (cannot benull
).- Returns:
this
for allowing method calls chaining.- See Also:
-
setName
Sets theFeatureType
name as a simple string. The namespace will be the value specified by the last call tosetNameSpace(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 givenCharSequence
, then delegates tosetName(GenericName)
.- Overrides:
setName
in classTypeBuilder
- Parameters:
localPart
- the local part of the generic name as aString
orInternationalString
.- Returns:
this
for allowing method calls chaining.- See Also:
-
setName
Sets theFeatureType
name as a string in the given scope. Thecomponents
array must contain at least one element. In addition to the path specified by thecomponents
array, the name may also contain a namespace specified by the last call tosetNameSpace(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
orScopedName
instance depending on whether thenames
array contains exactly 1 element or more than 1 element, then delegates tosetName(GenericName)
.- Overrides:
setName
in classTypeBuilder
- Parameters:
components
- the name components as an array ofString
orInternationalString
instances.- Returns:
this
for allowing method calls chaining.- See Also:
-
setDefaultMultiplicity
Sets the default minimum and maximum number of next attributes and associations to add. Those defaults will applied to newly created attributes or associations, for example in next calls toaddAttribute(Class)
. Attributes and associations added before this method call are not modified.If this method is not invoked, then the default multiplicity is [1 … 1].
- Parameters:
minimumOccurs
- new default minimum number of property values.maximumOccurs
- new default maximum number of property values.- Returns:
this
for allowing method calls chaining.- Since:
- 1.0
- See Also:
-
setIdentifierDelimiters
Sets the prefix, suffix and delimiter to use when formatting a compound identifier made of two or more attributes. The delimiter will be used only if at least two attributes have the identifier component role.If this method is not invoked, then the default values are the
":"
delimiter and no prefix or suffix.- Parameters:
delimiter
- the characters to use as delimiter between each single property value.prefix
- characters to use at the beginning of the concatenated string, ornull
if none.suffix
- characters to use at the end of the concatenated string, ornull
if none.- Returns:
this
for allowing method calls chaining.- See Also:
-
properties
Returns a view of all attributes and associations added to theFeatureType
to build. This list contains only properties declared explicitly 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 theaddAttribute(…)
oraddAssociation(…)
methods. Removal operations never affect the super-types.- Returns:
- a live list over the properties declared to this builder.
- See Also:
-
isNameUsed
Returnstrue
if a property of the given name is defined or if the given name is ambiguous. Invoking this method is equivalent to testing ifgetProperty(name) != null
except that this method does not throw exception if the given name is ambiguous.- Parameters:
name
- the name to test.- Returns:
true
if the given name is used by another property or is ambiguous.- Since:
- 1.0
-
getProperty
Returns the builder for the property of the given name. The given name does not need to contains all elements of aScopedName
; 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.- Parameters:
name
- name of the property to search.- Returns:
- property of the given name, or
null
if none. - Throws:
IllegalArgumentException
- if the given name is ambiguous.
-
addAttribute
Creates a newAttributeType
builder for values of the given class. The default attribute name is the name of the given type, but callers should invoke one of theAttributeTypeBuilder.setName(…)
methods on the returned instance with a better name.Usage example
builder.addAttribute(String.class).setName("City").setDefaultValue("Metropolis");
Feature.class
since features shall be handled as associations instead of attributes.- Type Parameters:
V
- the compile-time value ofvalueClass
argument.- Parameters:
valueClass
- the class of attribute values (cannot beFeature.class
).- Returns:
- a builder for an
AttributeType
. - See Also:
-
addAttribute
Creates a newAttributeType
builder initialized to the same characteristics than the given template. If the new attribute duplicates an existing one (for example if the same template is used many times), caller should use the returned builder for modifying some attributes.Warning: Thetemplate
argument type will be changed toAttributeType
if and when such interface will be defined in GeoAPI.- Type Parameters:
V
- the compile-time type of values in thetemplate
argument.- Parameters:
template
- an existing attribute type to use as a template.- Returns:
- a builder for an
AttributeType
, initialized with the values of the given template. - See Also:
-
addAttribute
Creates a new attribute for geometries of the given type. This method delegates toaddAttribute(Class)
with avalueClass
argument inferred from the combination of theGeometryType
argument given to this method with theGeometryLibrary
argument given at builder creation time. The geometry type can be:GeometryType.POINT
forPoint
orPoint2D
type.GeometryType.LINEAR
forPolyline
orLineString
type.GeometryType.AREAL
forPolygon
type.
Example
The following code creates an attribute named "MyPoint" with values of classPoint2D
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);
Point
class of those libraries will be used instead ofPoint2D
. The fully-qualified class names are given in theGeometryLibrary
javadoc.- Parameters:
type
- kind of geometric object (point, polyline or polygon).- Returns:
- a builder for an
AttributeType
.
-
addAssociation
Creates a newFeatureAssociationRole
builder for features of the given type. The default association name is the name of the given type, but callers should invoke one of theAssociationRoleBuilder.setName(…)
methods on the returned instance with a better name.Warning: Thetype
argument type will be changed toFeatureType
if and when such interface will be defined in GeoAPI.- Parameters:
type
- the type of feature values.- Returns:
- a builder for a
FeatureAssociationRole
. - See Also:
-
addAssociation
Creates a newFeatureAssociationRole
builder for features of a type of the given name. This method can be invoked as an alternative toaddAssociation(FeatureType)
when theFeatureType
instance is not yet available because of cyclic dependency.- Parameters:
type
- the name of the type of feature values.- Returns:
- a builder for a
FeatureAssociationRole
. - See Also:
-
addAssociation
Creates a newFeatureAssociationRole
builder initialized to the same characteristics than the given template. If the new association duplicates an existing one (for example if the same template is used many times), caller should use the returned builder for modifying some associations.Warning: Thetemplate
argument type will be changed toFeatureAssociationRole
if and when such interface will be defined in GeoAPI.- Parameters:
template
- an existing feature association to use as a template.- Returns:
- a builder for an
FeatureAssociationRole
, initialized with the values of the given template. - See Also:
-
addProperty
Adds the given property in the feature type properties. The given property shall be an instance of one of the following types:AttributeType
, in which case this method delegate toaddAttribute(AttributeType)
.FeatureAssociationRole
, in which case this method delegate toaddAssociation(FeatureAssociationRole)
.Operation
, in which case the given operation object will be added verbatim in theFeatureType
; this builder does not create new operations.
Warning: In a future SIS version, the argument type may be changed to theorg.opengis.feature.PropertyType
interface. This change is pending GeoAPI revision.- Parameters:
template
- the property to add to the feature type.- Returns:
- a builder initialized to the given template.
In the
Operation
case, the builder is a read-only accessor on the operation properties. - See Also:
-
setDefinition
Sets a concise definition of the element.- Overrides:
setDefinition
in classTypeBuilder
- Parameters:
definition
- a concise definition of the element, ornull
if none.- Returns:
this
for allowing method calls chaining.- See Also:
-
setDesignation
Sets a natural language designator for the element. This can be used as an alternative to the name in user interfaces.- Overrides:
setDesignation
in classTypeBuilder
- Parameters:
designation
- a natural language designator for the element, ornull
if none.- Returns:
this
for allowing method calls chaining.- See Also:
-
setDescription
Sets optional information beyond that required for concise definition of the element. The description may assist in understanding the feature scope and application. If the type is deprecated, then the description should give indication about the replacement (e.g. "superceded by …").- Overrides:
setDescription
in classTypeBuilder
- Parameters:
description
- information beyond that required for concise definition of the element, ornull
if none.- Returns:
this
for allowing method calls chaining.- See Also:
-
setDeprecated
Sets whether the type is deprecated. If the type is deprecated, then the description should be set to an indication about the replacement (e.g. "superceded by …").- Overrides:
setDeprecated
in classTypeBuilder
- Parameters:
deprecated
- whether this type is deprecated.- Returns:
this
for allowing method calls chaining.- See Also:
-
build
Builds the feature type from the information and properties specified to this builder. One of thesetName(…)
methods must have been invoked before thisbuild()
method (mandatory). All other methods are optional, but some calls to aadd
method are usually needed.Warning: In a future SIS version, the return type may be changed to theorg.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.- Specified by:
build
in classTypeBuilder
- Returns:
- the feature type.
- Throws:
IllegalStateException
- if the builder contains inconsistent information.- See Also:
-