Package org.apache.sis.util.iso
Class DefaultNameFactory
java.lang.Object
org.apache.sis.util.iso.AbstractFactory
org.apache.sis.util.iso.DefaultNameFactory
- All Implemented Interfaces:
org.opengis.util.Factory,org.opengis.util.NameFactory
A factory for creating
AbstractName objects.
This factory provides the following methods for creating name instances:
createTypeName(NameSpace, CharSequence)createMemberName(NameSpace, CharSequence, TypeName)createLocalName(NameSpace, CharSequence)createGenericName(NameSpace, CharSequence[])– for local or scoped names
Thread safety
The sameDefaultNameFactory instance can be safely used by many threads without synchronization
on the part of the caller. Subclasses should make sure that any overridden methods remain safe to call
from multiple threads.- Since:
- 0.3
- Version:
- 1.3
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) static final StringThe key or the separator after the first name.private final WeakHashSet<org.opengis.util.GenericName>Weak references to the name created by this factory.(package private) static final StringThe key for name separator.private TypeNamesHelper class for mappingClasstoTypeName, created when first needed. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionorg.opengis.util.GenericNamecreateGenericName(org.opengis.util.NameSpace scope, CharSequence... parsedNames) Creates a local or scoped name from an array of parsed names.org.opengis.util.InternationalStringcreateInternationalString(Map<Locale, String> strings) Creates an international string from a set of strings in different locales.org.opengis.util.LocalNamecreateLocalName(org.opengis.util.NameSpace scope, CharSequence name) Creates a local name from the given character sequence.org.opengis.util.MemberNamecreateMemberName(org.opengis.util.NameSpace scope, CharSequence name, org.opengis.util.TypeName attributeType) Creates a member name from the given character sequence and attribute type.org.opengis.util.NameSpacecreateNameSpace(org.opengis.util.GenericName name, Map<String, ?> properties) Returns a namespace having the given name.org.opengis.util.TypeNamecreateTypeName(org.opengis.util.NameSpace scope, CharSequence name) Creates a type name from the given character sequence and automatically inferred Java type.org.opengis.util.TypeNamecreateTypeName(org.opengis.util.NameSpace scope, CharSequence name, Type javaType) Creates a type name from the given character sequence and explicit Java type.private static StringReturns the value for the given key in the given properties map, ornullif none.org.opengis.util.GenericNameparseGenericName(org.opengis.util.NameSpace scope, CharSequence name) Constructs a generic name from a qualified name.private org.opengis.util.GenericNametoGenericName(Object value) Creates a generic name from the given value.org.opengis.util.GenericName[]toGenericNames(Object value) Converts the given value to an array of generic names.org.opengis.util.TypeNametoTypeName(Class<?> valueClass) Suggests a type name for the given class.Methods inherited from class org.apache.sis.util.iso.AbstractFactory
getVendor
-
Field Details
-
SEPARATOR_KEY
The key for name separator.- See Also:
-
HEAD_SEPARATOR_KEY
The key or the separator after the first name.- See Also:
-
pool
Weak references to the name created by this factory. -
typeNames
Helper class for mappingClasstoTypeName, created when first needed.
-
-
Constructor Details
-
DefaultNameFactory
public DefaultNameFactory()Creates a new factory.
-
-
Method Details
-
createInternationalString
Creates an international string from a set of strings in different locales.- Specified by:
createInternationalStringin interfaceorg.opengis.util.NameFactory- Parameters:
strings- string value for each locale key.- Returns:
- the international string.
- See Also:
-
getString
Returns the value for the given key in the given properties map, ornullif none. -
createNameSpace
public org.opengis.util.NameSpace createNameSpace(org.opengis.util.GenericName name, Map<String, ?> properties) Returns a namespace having the given name. Despite the "create" name, this method tries to return an existing instance when possible. The namespace is characterized by the given name, and optionally by the following properties:Recognized properties Property name Purpose "separator"The separator to insert between parsed names in that namespace. "separator.head"The separator to insert between the namespace and the head.
If omitted, then the default is the same value than"separator".Examples:- For URN namespace,
separator=":"is typically sufficient. - For HTTP namespace,
separator.head="://"andseparator=".".
- Specified by:
createNameSpacein interfaceorg.opengis.util.NameFactory- Parameters:
name- the name of the namespace to be returned. This argument can be created usingcreateGenericName(null, namespace).properties- an optional map of properties to be assigned to the namespace, ornullif none.- Returns:
- a namespace having the given name and separator.
- See Also:
- For URN namespace,
-
createTypeName
public org.opengis.util.TypeName createTypeName(org.opengis.util.NameSpace scope, CharSequence name) throws UnknownNameException Creates a type name from the given character sequence and automatically inferred Java type. The default implementation returns a new or an existingDefaultTypeNameinstance. SeeDefaultTypeNamejavadoc for the list of recognized type names.- Specified by:
createTypeNamein interfaceorg.opengis.util.NameFactory- Parameters:
scope- the scope of the type name create, ornullfor a global namespace.name- the type name as a string or an international string.- Returns:
- the type name for the given scope and character sequence.
- Throws:
UnknownNameException- if a mapping from the name to a Java class was expected to exist (because the specified scope is "OGC" or "class") but the associated Java class cannot be found.- See Also:
-
createTypeName
public org.opengis.util.TypeName createTypeName(org.opengis.util.NameSpace scope, CharSequence name, Type javaType) Creates a type name from the given character sequence and explicit Java type. The default implementation returns a new or an existingDefaultTypeNameinstance.- Parameters:
scope- the scope of the type name to create, ornullfor a global namespace.name- the type name as a string or an international string.javaType- the Java type represented by the name, ornullif none.- Returns:
- the type name for the given scope, character sequence and Java type.
- Since:
- 1.3
- See Also:
-
createMemberName
public org.opengis.util.MemberName createMemberName(org.opengis.util.NameSpace scope, CharSequence name, org.opengis.util.TypeName attributeType) Creates a member name from the given character sequence and attribute type. The default implementation returns a new or an existingDefaultMemberNameinstance.- Parameters:
scope- the scope of the member name to create, ornullfor a global namespace.name- the member name as a string or an international string.attributeType- the type of the data associated with the member.- Returns:
- the member name for the given character sequence.
- See Also:
-
createLocalName
public org.opengis.util.LocalName createLocalName(org.opengis.util.NameSpace scope, CharSequence name) Creates a local name from the given character sequence. The default implementation returns a new or an existingDefaultLocalNameinstance.- Specified by:
createLocalNamein interfaceorg.opengis.util.NameFactory- Parameters:
scope- the scope of the local name to create, ornullfor a global namespace.name- the local name as a string or an international string.- Returns:
- the local name for the given character sequence.
- See Also:
-
createGenericName
public org.opengis.util.GenericName createGenericName(org.opengis.util.NameSpace scope, CharSequence... parsedNames) Creates a local or scoped name from an array of parsed names. The default implementation returns an instance ofDefaultLocalNameif the length of theparsedNamesarray is 1, or an instance ofDefaultScopedNameif the length of the array is 2 or more.- Specified by:
createGenericNamein interfaceorg.opengis.util.NameFactory- Parameters:
scope- the scope of the generic name to create, ornullfor a global namespace.parsedNames- the local names as an array ofStringorInternationalStringinstances. This array shall contain at least one element.- Returns:
- the generic name for the given parsed names.
- See Also:
-
parseGenericName
public org.opengis.util.GenericName parseGenericName(org.opengis.util.NameSpace scope, CharSequence name) Constructs a generic name from a qualified name. This method splits the given name around a separator inferred from the given scope, or the':'separator if the given scope is null.- Specified by:
parseGenericNamein interfaceorg.opengis.util.NameFactory- Parameters:
scope- the scope of the generic name to create, ornullfor a global namespace.name- the qualified name, as a sequence of names separated by a scope-dependent separator.- Returns:
- a name parsed from the given string.
- See Also:
-
toGenericNames
Converts the given value to an array of generic names. If the given value is an instance ofGenericName,Stringor any other type enumerated below, then it is converted and returned in an array of length 1. If the given value is an array or a collection, then an array of same length is returned where each element has been converted.Allowed types or element types are:
GenericName, to be casted and returned as-is.CharSequence(usually aStringor anInternationalString), to be parsed as a generic name using the':'separator.Identifier, its code to be parsed as a generic name using the':'separator.
valueis an array or a collection containingnullelements, then the corresponding element in the returned array will also benull.- Parameters:
value- the object to cast into an array of generic names, ornull.- Returns:
- the generic names, or
nullif the givenvaluewas null. Note that it may be thevaluereference itself casted toGenericName[]. - Throws:
ClassCastException- ifvaluecannot be casted.- Since:
- 0.5
-
toGenericName
Creates a generic name from the given value. The value may be an instance ofGenericName,Identifier,CharSequenceorClass. If the given object is not recognized, then this method returnsnull.- Parameters:
value- the object to convert.- Returns:
- the converted object, or
nullifvalueis not convertible.
-
toTypeName
Suggests a type name for the given class. Apache SIS provides a mapping betweenClassandTypeNameobjects as documented in theDefaultTypeNamejavadoc. The givenvalueClasscan be fetched back byDefaultTypeName.toJavaType().- Parameters:
valueClass- the Java class for which to get a type name, ornull.- Returns:
- a suggested type name, or
nullif the given class was null. - Since:
- 0.5
- See Also:
-