Class FeatureTypeBuilder
- All Implemented Interfaces:
- Localized
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 theFeatureTypeinstance 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:
Defined in the sis-feature module
- 
Constructor SummaryConstructorsConstructorDescriptionCreates 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 SummaryModifier and TypeMethodDescriptionaddAssociation(DefaultAssociationRole template) Creates a newFeatureAssociationRolebuilder initialized to the same characteristics than the given template.Creates a newFeatureAssociationRolebuilder for features of the given type.addAssociation(GenericName type) Creates a newFeatureAssociationRolebuilder for features of a type of the given name.<V> AttributeTypeBuilder<V>addAttribute(Class<V> valueClass) Creates a newAttributeTypebuilder for values of the given class.<V> AttributeTypeBuilder<V>addAttribute(DefaultAttributeType<V> template) Creates a newAttributeTypebuilder 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.booleanReturnstrueif the feature type to create will act as an abstract super-type.booleanisNameUsed(String name) Returnstrueif 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 theFeatureTypeto 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 theFeatureTypename as a simple string.setName(CharSequence... components) Sets theFeatureTypename as a string in the given scope.setName(GenericName name) Sets theFeatureTypename 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 TypeBuildergetDefinition, getDescription, getDesignation, getLocale, getName, isDeprecated, toString
- 
Constructor Details- 
FeatureTypeBuilderpublic FeatureTypeBuilder()Creates a new builder instance using the default name factory.
- 
FeatureTypeBuilderCreates a new builder instance using the given feature type as a template. This constructor initializes the list of properties, the super types andisAbstractflag 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: Thetemplateargument type will be changed toFeatureTypeif and when such interface will be defined in GeoAPI.- Parameters:
- template- an existing feature type to use as a template, or- nullif none.
 
- 
FeatureTypeBuilderCreates 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, or- nullfor the default factory.
- library- the library to use for creating geometric objects, or- nullfor the default.
- locale- the locale to use for formatting error messages, or- nullfor the default locale.
 
 
- 
- 
Method Details- 
clearClears all setting in this builder. After invoking this method, thisFeatureTypeBuilderis in same state that after it has been constructed. This method can be invoked for reusing the same builder for creating otherFeatureTypeinstances afterbuild()invocation.- Returns:
- thisfor allowing method calls chaining.
 
- 
setAllSets 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: Thetemplateargument type will be changed toFeatureTypeif and when such interface will be defined in GeoAPI.- Parameters:
- template- an existing feature type to use as a template, or- nullif none.
- Returns:
- thisfor allowing method calls chaining.
 
- 
isAbstractpublic boolean isAbstract()Returnstrueif the feature type to create will act as an abstract super-type. Abstract types cannot be instantiated.- Returns:
- trueif the feature type to create will act as an abstract super-type.
- See Also:
 
- 
setAbstractSets 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:
- thisfor allowing method calls chaining.
 
- 
getSuperTypesReturns 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:
 
- 
setSuperTypesSets 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: Theparentsargument 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:
- thisfor allowing method calls chaining.
 
- 
getNameSpaceReturns the namespace of the names created bysetName(CharSequence...)method calls. Anullvalue means that the names are in the global namespace.- Returns:
- the namespace to use when setName(CharSequence)is invoked, ornullif none.
 
- 
setNameSpaceSets 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:
 There is different conventions about the use of name spaces. ISO 19109 suggests that the namespace of allFeatureTypeBuilder 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"AttributeTypenames 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, or- nullif none.
- Returns:
- thisfor allowing method calls chaining.
 
- 
setNameSets theFeatureTypename 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:
- setNamein class- TypeBuilder
- Parameters:
- name- the generic name (cannot be- null).
- Returns:
- thisfor allowing method calls chaining.
- See Also:
 
- 
setNameSets theFeatureTypename 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 LocalNameinstance from the givenCharSequence, then delegates tosetName(GenericName).- Overrides:
- setNamein class- TypeBuilder
- Parameters:
- localPart- the local part of the generic name as a- Stringor- InternationalString.
- Returns:
- thisfor allowing method calls chaining.
- See Also:
 
- 
setNameSets theFeatureTypename as a string in the given scope. Thecomponentsarray must contain at least one element. In addition to the path specified by thecomponentsarray, 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 LocalNameorScopedNameinstance depending on whether thenamesarray contains exactly 1 element or more than 1 element, then delegates tosetName(GenericName).- Overrides:
- setNamein class- TypeBuilder
- Parameters:
- components- the name components as an array of- Stringor- InternationalStringinstances.
- Returns:
- thisfor allowing method calls chaining.
- See Also:
 
- 
setDefaultMultiplicitySets 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:
- thisfor allowing method calls chaining.
- Since:
- 1.0
- See Also:
 
- 
setIdentifierDelimitersSets 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, or- nullif none.
- suffix- characters to use at the end of the concatenated string, or- nullif none.
- Returns:
- thisfor allowing method calls chaining.
- See Also:
 
- 
propertiesReturns a view of all attributes and associations added to theFeatureTypeto 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:
 
- 
isNameUsedReturnstrueif a property of the given name is defined or if the given name is ambiguous. Invoking this method is equivalent to testing ifgetProperty(name) != nullexcept that this method does not throw exception if the given name is ambiguous.- Parameters:
- name- the name to test.
- Returns:
- trueif the given name is used by another property or is ambiguous.
- Since:
- 1.0
 
- 
getPropertyReturns 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 nullif none.
- Throws:
- IllegalArgumentException- if the given name is ambiguous.
 
- 
addAttributeCreates a newAttributeTypebuilder 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: 
 The value class cannot bebuilder.addAttribute(String.class).setName("City").setDefaultValue("Metropolis");Feature.classsince features shall be handled as associations instead of attributes.- Type Parameters:
- V- the compile-time value of- valueClassargument.
- Parameters:
- valueClass- the class of attribute values (cannot be- Feature.class).
- Returns:
- a builder for an AttributeType.
- See Also:
 
- 
addAttributeCreates a newAttributeTypebuilder 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: Thetemplateargument type will be changed toAttributeTypeif and when such interface will be defined in GeoAPI.- Type Parameters:
- V- the compile-time type of values in the- templateargument.
- 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:
 
- 
addAttributeCreates a new attribute for geometries of the given type. This method delegates toaddAttribute(Class)with avalueClassargument inferred from the combination of theGeometryTypeargument given to this method with theGeometryLibraryargument given at builder creation time. The geometry type can be:- GeometryType.POINTfor- Pointor- Point2Dtype.
- GeometryType.LINEARfor- Polylineor- LineStringtype.
- GeometryType.AREALfor- Polygontype.
 Example: the following code creates an attribute named "MyPoint" with values of classPoint2Dif 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:
 If the library in use is JTS or ESRI instead of Java2D, then thebuilder.addAttribute(GeometryType.POINT).setName("MyPoint") .setCRS(CommonCRS.WGS84.normalizedGeographic()) .addRole(AttributeRole.DEFAULT_GEOMETRY);Pointclass of those libraries will be used instead ofPoint2D. The fully-qualified class names are given in theGeometryLibraryjavadoc.- Parameters:
- type- kind of geometric object (point, polyline or polygon).
- Returns:
- a builder for an AttributeType.
 
- 
addAssociationCreates a newFeatureAssociationRolebuilder 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: Thetypeargument type will be changed toFeatureTypeif and when such interface will be defined in GeoAPI.- Parameters:
- type- the type of feature values.
- Returns:
- a builder for a FeatureAssociationRole.
- See Also:
 
- 
addAssociationCreates a newFeatureAssociationRolebuilder for features of a type of the given name. This method can be invoked as an alternative toaddAssociation(FeatureType)when theFeatureTypeinstance 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:
 
- 
addAssociationCreates a newFeatureAssociationRolebuilder 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: Thetemplateargument type will be changed toFeatureAssociationRoleif 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:
 
- 
addPropertyAdds 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 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.
 Warning: In a future SIS version, the argument type may be changed to theorg.opengis.feature.PropertyTypeinterface. 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 Operationcase, the builder is a read-only accessor on the operation properties.
- See Also:
 
- 
setDefinitionSets a concise definition of the element.- Overrides:
- setDefinitionin class- TypeBuilder
- Parameters:
- definition- a concise definition of the element, or- nullif none.
- Returns:
- thisfor allowing method calls chaining.
- See Also:
 
- 
setDesignationSets a natural language designator for the element. This can be used as an alternative to the name in user interfaces.- Overrides:
- setDesignationin class- TypeBuilder
- Parameters:
- designation- a natural language designator for the element, or- nullif none.
- Returns:
- thisfor allowing method calls chaining.
- See Also:
 
- 
setDescriptionSets 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:
- setDescriptionin class- TypeBuilder
- Parameters:
- description- information beyond that required for concise definition of the element, or- nullif none.
- Returns:
- thisfor allowing method calls chaining.
- See Also:
 
- 
setDeprecatedSets 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:
- setDeprecatedin class- TypeBuilder
- Parameters:
- deprecated- whether this type is deprecated.
- Returns:
- thisfor allowing method calls chaining.
- See Also:
 
- 
buildBuilds 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 aaddmethod are usually needed.Warning: In a future SIS version, the return type may be changed to theorg.opengis.feature.FeatureTypeinterface. 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 FeatureTypeinstance is returned.- Specified by:
- buildin class- TypeBuilder
- Returns:
- the feature type.
- Throws:
- IllegalStateException- if the builder contains inconsistent information.
- See Also:
 
 
-