public final class Names extends Static
DefaultNameFactory
,
but makes some tasks easier by avoiding the need to find a factory, and by creating name and
their namespace in a single step.
QName
class and in the Java Content Repository (JCR) specification,
a name is an ordered pair of (namespace
, localPart
) strings. A JCR name can take two lexical forms:
expanded form and qualified form. Those names are mapped to generic names as below:
Equivalence between JCR name and GenericName
JCR name GeoAPI equivalence ExpandedName ::= '{' Namespace '}' LocalPart
GenericName.scope().name().toString()
= JCR Namespace
GenericName.toString()
= JCR LocalPart
QualifiedName ::= [Prefix ':'] LocalPart
ScopedName.scope()
= global namespace ScopedName.head().toString()
= JCR Prefix
ScopedName.tail().toString()
= JCR LocalPart
DefaultNameFactory
,
DefaultNameSpace
,
DefaultScopedName
,
DefaultLocalName
,
DefaultTypeName
,
DefaultMemberName
Defined in the sis-utility
module
Modifier and Type | Method and Description |
---|---|
static LocalName |
createLocalName(CharSequence namespace,
String separator,
CharSequence localPart)
Creates a name which is local in the given namespace.
|
static MemberName |
createMemberName(CharSequence namespace,
String separator,
CharSequence localPart,
Class<?> valueClass)
Creates a member name for values of the given class.
|
static TypeName |
createTypeName(CharSequence namespace,
String separator,
CharSequence localPart)
Creates a type name which is local in the given namespace.
|
static GenericName |
parseGenericName(CharSequence namespace,
String separator,
CharSequence scopedName)
Creates a local or scoped name in the given namespace.
|
static Class<?> |
toClass(TypeName type)
Returns the Java class associated to the given type name.
|
static String |
toExpandedString(GenericName name)
Formats the given name in expanded form close to the Java Content Repository (JCR) definition.
|
public static GenericName parseGenericName(CharSequence namespace, String separator, CharSequence scopedName)
String
or InternationalString
instances.
The namespace
character sequences is taken verbatim, while scopedName
is parsed
as described in name factory.namespace
- The namespace, or null
for the global namespace.separator
- The separator between the namespace and the scoped name.scopedName
- The name to parse.public static LocalName createLocalName(CharSequence namespace, String separator, CharSequence localPart)
String
or InternationalString
instances.
Those character sequences are taken verbatim; they are not parsed into their components.
namespace
and localPart
strings into smaller name components (e.g. namespaces contained in other namespaces). If such finer
grain control is desired, one can use DefaultNameFactory
instead of this Names
class.
Mapping from arguments to name components Argument Mapped to namespace
name.scope().name().toString()
localPart
name.toString()
createLocalName("http://www.opengis.net/gml/srs/epsg.xml", "#", "4326")
:
• name.toString()
returns the "4326"
string.• name.scope()
returns the "http://www.opengis.net/gml/srs/epsg.xml"
namespace.• name.toFullyQualifiedName()
returns the "http://www.opengis.net/gml/srs/epsg.xml#4326"
name.• toExpandedString(name)
returns the "{http://www.opengis.net/gml/srs/epsg.xml}4326"
string.
DefaultNameFactory.createLocalName(NameSpace, CharSequence)
is more efficient since it allows to create the NameSpace
object only once.namespace
- The namespace, or null
for the global namespace.separator
- The separator between the namespace and the local part.localPart
- The name which is locale in the given namespace.public static TypeName createTypeName(CharSequence namespace, String separator, CharSequence localPart)
String
or InternationalString
instances.
Those character sequences are taken verbatim; they are not parsed into their components.
createTypeName("gco", ":", "Integer")
returns a name
which can be used for representing the type of <gco:Integer>
elements in XML files.DefaultNameFactory.createTypeName(NameSpace, CharSequence)
is more efficient since it allows to create the NameSpace
object only once.namespace
- The namespace, or null
for the global namespace.separator
- The separator between the namespace and the local part.localPart
- The name which is locale in the given namespace.public static MemberName createMemberName(CharSequence namespace, String separator, CharSequence localPart, Class<?> valueClass)
TypeName
will be inferred
from the given valueClass
as documented in the DefaultTypeName
javadoc.
DefaultNameFactory.createMemberName(NameSpace, CharSequence, TypeName)
is more efficient since it allows to create the NameSpace
and TypeName
objects only once.namespace
- The namespace, or null
for the global namespace.separator
- The separator between the namespace and the local part.localPart
- The name which is locale in the given namespace.valueClass
- The type of values, used for inferring a TypeName
instance.public static Class<?> toClass(TypeName type) throws UnknownNameException
null
, then this method returns null
.DefaultTypeName
,
then this method delegates to DefaultTypeName.toClass()
."OGC"
, then:
"CharacterString"
, "Integer"
, "Real"
or other recognized names
(see DefaultTypeName
javadoc), then the corresponding class is returned.UnknownNameException
is thrown."class"
, then:
Class.forName(String)
, then that class is returned.UnknownNameException
is thrown."OGC"
scope (see above),
then the corresponding class is returned.null
is returned. No exception is thrown because names in the global namespace
could be anything, so we can not be sure that the given name was wrong.null
is returned, since this method can not check the validity of names in other
namespaces.type
- The type name from which to infer a Java class.TypeName
,
or null
if there is no mapping from the given name to a Java class.UnknownNameException
- if a mapping from the given name to a Java class was expected to exist
(typically because of the scope) but the operation failed.DefaultTypeName.toClass()
,
DefaultNameFactory.toTypeName(Class)
public static String toExpandedString(GenericName name)
ExpandedName ::= '{' NameSpace '}' LocalPart NameSpace ::= name.scope().name().toString() LocalPart ::= name.toString()
name
- The generic name to format in expanded form, or null
.null
if the given name was null.DefaultNameSpace.toString()
Copyright © 2010–2015 The Apache Software Foundation. All rights reserved.