Package org.apache.sis.feature.builder
Class TypeBuilder
java.lang.Object
org.apache.sis.feature.builder.TypeBuilder
- All Implemented Interfaces:
Localized
- Direct Known Subclasses:
CharacteristicTypeBuilder,FeatureTypeBuilder,PropertyTypeBuilder
Information common to all kind of types (feature, association, characteristics).
Those information are:
- the name — a unique name which can be defined within a scope (or namespace).
- the definition — a concise definition of the element.
- the designation — a natural language designator for the element for user interfaces.
- the description — information beyond that required for concise definition of the element.
LocalName,
ScopedName, String or InternationalString instance.
All other properties are optional.
Default namespace
In many cases, the names of allAttributeTypes and AssociationRoles to create
within a FeatureType share the same namespace.
For making name creations more convenient, the namespace can be
specified once and applied automatically
to all names created by the setName(CharSequence) method.
Note that namespaces will not be visible in the name string representation unless the fully
qualified name is requested.
Example:
- Since:
- 0.8
- Version:
- 0.8
-
Field Summary
FieldsModifier and TypeFieldDescriptionThe feature name, definition, designation and description. -
Constructor Summary
ConstructorsConstructorDescriptionTypeBuilder(Locale locale) Creates a new builder initialized to the given configuration.TypeBuilder(TypeBuilder builder) Creates a new builder initialized to the values of the given builder. -
Method Summary
Modifier and TypeMethodDescription(package private) final StringBuilderappendStringTo(StringBuilder buffer) Partial implementation oftoString().abstract AbstractIdentifiedTypebuild()Builds the feature or property type from the information specified to this builder.(package private) abstract voidIf the object created by the last call tobuild()has been cached, clears that cache.(package private) abstract org.opengis.util.GenericNamecreateGenericName(CharSequence... names) Creates a generic name in the feature namespace.(package private) abstract org.opengis.util.GenericNamecreateLocalName(CharSequence name) Creates a local name in the feature namespace.(package private) final voidensureAlive(TypeBuilder owner) Ensures that this instance is still alive.(package private) final voidensureNonEmpty(String name, CharSequence text) Same asArgumentChecks.ensureNonEmpty(String, CharSequence), but uses the current locale in case of error.(package private) final voidensureNonNull(String name, Object value) Same asArgumentChecks.ensureNonNull(String, Object), but uses the current locale in case of error.(package private) final Errorserrors()Returns the resources for error messages.(package private) final <E extends TypeBuilder>
EReturns the element of the given name in the given list.(package private) StringReturns a default name to use if the user did not specified a name.Returns a concise definition of the element.Returns optional information beyond that required for concise definition of the element.Returns a natural language designator for the element.(package private) final StringReturns the name to use for displaying error messages.Returns the locale used for formatting error messages, ornullif unspecified.org.opengis.util.GenericNamegetName()Returns the name of theIdentifiedTypeto create, ornullif undefined.Returns the map of properties to give to theFeatureTypeorPropertyTypeconstructor.(package private) final voidinitialize(AbstractIdentifiedType template) Initializes this builder to the value of the given type.booleanReturnstrueif the type is deprecated.private voidputIfNonNull(String key, Object value) Puts the given value in theidentificationmap if the value is non-null.(package private) voidremove()Invoked when a type builder has been removed from its parent.(package private) final voidreset()Resets the identification map.(package private) final ResourcesReturns thesis-featurespecific resources for error messages.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.setName(CharSequence localPart) Sets theIdentifiedTypename as a simple string (local name).setName(CharSequence... components) Sets theIdentifiedTypename as a string in the given scope.setName(org.opengis.util.GenericName name) Sets theIdentifiedTypename as a generic name.toString()Returns a string representation of this object.(package private) voidtoStringInternal(StringBuilder buffer) Appends a text inside the value returned bytoString(), before the closing bracket.
-
Field Details
-
identification
The feature name, definition, designation and description. The name is mandatory; all other information are optional.
-
-
Constructor Details
-
TypeBuilder
TypeBuilder(TypeBuilder builder) Creates a new builder initialized to the values of the given builder. This constructor is forAttributeTypeBuilder.setValueClass(Class)andCharacteristicTypeBuilder.setValueClass(Class)implementations.- Parameters:
builder- the builder from which to copy information.
-
TypeBuilder
TypeBuilder(Locale locale) Creates a new builder initialized to the given configuration.
-
-
Method Details
-
reset
final void reset()Resets the identification map. After invoking this method, thisTypeBuilderis in same state that after it has been constructed.- See Also:
-
initialize
Initializes this builder to the value of the given type. The caller is responsible to invokereset()(if needed) before this method. -
putIfNonNull
Puts the given value in theidentificationmap if the value is non-null. This method should be invoked only when theidentificationmap is known to not contain any value for the given key. -
identification
Returns the map of properties to give to theFeatureTypeorPropertyTypeconstructor. If the map does not contains a name, a default name may be generated. -
clearCache
abstract void clearCache()If the object created by the last call tobuild()has been cached, clears that cache.- See Also:
-
createLocalName
Creates a local name in the feature namespace. -
createGenericName
Creates a generic name in the feature namespace. -
getName
public org.opengis.util.GenericName getName()Returns the name of theIdentifiedTypeto create, ornullif undefined. This method returns the value built from the last call to asetName(…)method, or a default name ornullif no name has been explicitly specified.- Returns:
- the name of the
IdentifiedTypeto create (may be a default name ornull). - See Also:
-
getDefaultName
String getDefaultName()Returns a default name to use if the user did not specified a name. The first letter will be changed to lower case (unless the name looks like an acronym) for compliance with Java convention on property names. -
getDisplayName
Returns the name to use for displaying error messages. -
setName
Sets theIdentifiedTypename 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.- Parameters:
name- the generic name (cannot benull).- Returns:
thisfor allowing method calls chaining.- See Also:
-
setName
Sets theIdentifiedTypename as a simple string (local name). The namespace will be the value specified by the last call toFeatureTypeBuilder.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
LocalNameinstance from the givenCharSequence, then delegates tosetName(GenericName).- Parameters:
localPart- the local part of the generic name as aStringorInternationalString.- Returns:
thisfor allowing method calls chaining.- See Also:
-
setName
Sets theIdentifiedTypename as a string in the given scope. Thecomponentsarray must contain at least one element. The last component (the tip) will be sufficient in many cases for calls to theAbstractFeature.getProperty(String)method. The other elements before the last one are optional and can be used for resolving ambiguity. They will be visible as the name path.Example: a call toIn addition to the path specified by thesetName("A", "B", "C")will create a "A:B:C" name. A property built with this name can be obtained from a feature by a call tofeature.getProperty("C")if there is no ambiguity, or otherwise by a call tofeature.getProperty("B:C")(if non-ambiguous) orfeature.getProperty("A:B:C").componentsarray, the name may also contain a namespace specified by the last call toFeatureTypeBuilder.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
LocalNameorScopedNameinstance depending on whether thenamesarray contains exactly 1 element or more than 1 element, then delegates tosetName(GenericName).- Parameters:
components- the name components as an array ofStringorInternationalStringinstances.- Returns:
thisfor allowing method calls chaining.- See Also:
-
getDefinition
Returns a concise definition of the element.- Returns:
- concise definition of the element, or
nullif none. - See Also:
-
setDefinition
Sets a concise definition of the element.- Parameters:
definition- a concise definition of the element, ornullif none.- Returns:
thisfor allowing method calls chaining.- See Also:
-
getDesignation
Returns a natural language designator for the element. This can be used as an alternative to the name in user interfaces.- Returns:
- natural language designator for the element, or
nullif none. - See Also:
-
setDesignation
Sets a natural language designator for the element. This can be used as an alternative to the name in user interfaces.- Parameters:
designation- a natural language designator for the element, ornullif none.- Returns:
thisfor allowing method calls chaining.- See Also:
-
getDescription
Returns optional information beyond that required for concise definition of the element. The description may assist in understanding the element scope and application.- Returns:
- information beyond that required for concise definition of the element, or
nullif none. - 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 …").- Parameters:
description- information beyond that required for concise definition of the element, ornullif none.- Returns:
thisfor allowing method calls chaining.- See Also:
-
isDeprecated
public boolean isDeprecated()Returnstrueif the type is deprecated. If this method returnstrue, then the description should give indication about the replacement (e.g. "superceded by …").- Returns:
- whether this type is deprecated.
- 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 …").- Parameters:
deprecated- whether this type is deprecated.- Returns:
thisfor allowing method calls chaining.- See Also:
-
forName
Returns the element of the given name in the given list. The given name does not need to contains all elements of aScopedName; it can be only the tip (for example"myName"instead of"myScope:myName") provided that ignoring the name head does not create ambiguity.- Parameters:
types- the collection where to search for an element of the given name.name- name of the element to search.nonAmbiguous- whether to throw an exception if the given name is ambiguous.- Returns:
- element of the given name, or
nullif none were found. - Throws:
IllegalArgumentException- if the given name is ambiguous.
-
getLocale
Returns the locale used for formatting error messages, ornullif unspecified. If unspecified, the system default locale will be used. -
errors
Returns the resources for error messages. -
resources
Returns thesis-featurespecific resources for error messages. -
ensureNonNull
Same asArgumentChecks.ensureNonNull(String, Object), but uses the current locale in case of error.- Parameters:
name- the name of the argument to be checked. Used only if an exception is thrown.value- the user argument to check against null value.- Throws:
NullArgumentException- ifobjectis null.
-
ensureAlive
Ensures that this instance is still alive.- Parameters:
owner- the owner of this instance. A value of null means that this instance should not be used any more.
-
ensureNonEmpty
Same asArgumentChecks.ensureNonEmpty(String, CharSequence), but uses the current locale in case of error.- Parameters:
name- the name of the argument to be checked. Used only if an exception is thrown.text- the user argument to check against null value and empty sequences.- Throws:
NullArgumentException- iftextis null.IllegalArgumentException- iftextis empty.
-
toString
Returns a string representation of this object. The returned string is for debugging purpose only and may change in any future SIS version. -
appendStringTo
Partial implementation oftoString(). This method assumes that the class name has already be written in the buffer. -
toStringInternal
Appends a text inside the value returned bytoString(), before the closing bracket. -
remove
void remove()Invoked when a type builder has been removed from its parent. Subclasses should override this method in a way that flag the builder as not usable anymore. -
build
Builds the feature or property type from the information specified to this builder. If a type has already been built and this builder state has not changed since the type creation, then the previously createdIdentifiedTypeinstance is returned.Warning: In a future SIS version, the return type may be changed to theorg.opengis.feature.IdentifiedTypeinterface. This change is pending GeoAPI revision.- Returns:
- the feature or property type.
- Throws:
IllegalStateException- if the builder contains inconsistent information.
-