Package org.alfresco.service.namespace
Class QName
java.lang.Object
org.alfresco.service.namespace.QName
- All Implemented Interfaces:
Serializable
,Cloneable
,Comparable<QName>
,QNamePattern
@AlfrescoPublicApi
public final class QName
extends Object
implements QNamePattern, Serializable, Cloneable, Comparable<QName>
QName
represents the qualified name of a Repository item. Each
QName consists of a local name qualified by a namespace.
The QNamePattern
is implemented
to allow instances of this class to be used for direct pattern matching where
required on interfaces.
- Author:
- David Caruana
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
static final int
static final char
static final char
static final char
-
Method Summary
Modifier and TypeMethodDescriptionclone()
int
Uses thenamespace URI
and then thelocalname
to do the comparison i.e.static QName
createQName
(String qname) Create a QName from its internal string representation of the following format:{namespaceURI}localName
static QName
createQName
(String namespaceURI, String localName) Create a QName (With no prefix)static QName
createQName
(String prefix, String localName, NamespacePrefixResolver prefixResolver) Create a QNamestatic QName
createQName
(String qname, NamespacePrefixResolver prefixResolver) Create a QName (from prefix format)prefix:localName
static QName
createQNameWithValidLocalName
(String namespaceURI, String localName) Create a QName, optionally truncating the localname toMAX_LENGTH
.static String
createValidLocalName
(String name) Create a valid local name from the specified nameboolean
Two QNames are equal only when both their name and namespace match.Gets the nameGets the namespacegetPrefixedQName
(NamespacePrefixResolver resolver) Gets a prefix resolved version of this QNameGetter version of toPrefixString()int
hashCode()
Calculate hashCode.boolean
Performs a direct comparison between qnames.static QName
resolveToQName
(NamespacePrefixResolver prefixResolver, String str) Creates a QName representation for the given String.static String
resolveToQNameString
(NamespacePrefixResolver prefixResolver, String str) Creates a string representation of a QName for the given string.static String[]
splitPrefixedQName
(String qname) Create a QNameRender string representation of QName using format:prefix:name
toPrefixString
(NamespacePrefixResolver prefixResolver) Render string representation of QName using format:prefix:name
according to namespace prefix mappings of specified namespace resolver.toString()
Render string representation of QName using format:{namespace}name
-
Field Details
-
EMPTY_URI_SUBSTITUTE
- See Also:
-
NAMESPACE_PREFIX
public static final char NAMESPACE_PREFIX- See Also:
-
NAMESPACE_BEGIN
public static final char NAMESPACE_BEGIN- See Also:
-
NAMESPACE_END
public static final char NAMESPACE_END- See Also:
-
MAX_LENGTH
public static final int MAX_LENGTH- See Also:
-
-
Method Details
-
createQName
Create a QName (With no prefix)- Parameters:
namespaceURI
- the qualifying namespace (maybe null or empty string)localName
- the local name- Returns:
- the QName
- Throws:
InvalidQNameException
-
createQName
public static QName createQName(String prefix, String localName, NamespacePrefixResolver prefixResolver) throws InvalidQNameException, NamespaceException Create a QName- Parameters:
prefix
- namespace prefix (maybe null or empty string)localName
- local nameprefixResolver
- lookup to resolve mappings between prefix and namespace- Returns:
- the QName
- Throws:
InvalidQNameException
NamespaceException
-
createQName
public static QName createQName(String qname, NamespacePrefixResolver prefixResolver) throws InvalidQNameException, NamespaceException Create a QName (from prefix format)prefix:localName
- Parameters:
qname
- qualified name of the following formatprefix:localName
prefixResolver
- lookup to resolve mappings between prefix and namespace- Returns:
- the QName
- Throws:
InvalidQNameException
NamespaceException
-
createQName
Create a QName from its internal string representation of the following format:{namespaceURI}localName
- Parameters:
qname
- the string representation of the QName- Returns:
- the QName
- Throws:
IllegalArgumentException
InvalidQNameException
-
createQNameWithValidLocalName
Create a QName, optionally truncating the localname toMAX_LENGTH
.- Parameters:
namespaceURI
- the qualifying namespace (maybe null or empty string)localName
- the local name, which will be truncated, if necessary- Returns:
- the QName with potentially-truncated localname
-
createValidLocalName
Create a valid local name from the specified name- Parameters:
name
- name to create valid local name from- Returns:
- valid local name
-
splitPrefixedQName
public static String[] splitPrefixedQName(String qname) throws InvalidQNameException, NamespaceException Create a QName- Parameters:
qname
- qualified name of the following formatprefix:localName
- Returns:
- string array where index 0 => prefix and index 1 => local name
- Throws:
InvalidQNameException
NamespaceException
-
clone
- Overrides:
clone
in classObject
- Throws:
CloneNotSupportedException
-
getLocalName
Gets the name- Returns:
- the name
-
getNamespaceURI
Gets the namespace- Returns:
- the namespace (empty string when not specified, but never null)
-
getPrefixedQName
Gets a prefix resolved version of this QName- Parameters:
resolver
- namespace prefix resolver- Returns:
- QName with prefix resolved
-
equals
Two QNames are equal only when both their name and namespace match. Note: The prefix is ignored during the comparison. -
isMatch
Performs a direct comparison between qnames.- Specified by:
isMatch
in interfaceQNamePattern
- Parameters:
qname
- the instance to check- Returns:
- Returns true if the qname matches this pattern
- See Also:
-
hashCode
public int hashCode()Calculate hashCode. Follows pattern used by String where hashCode is cached (QName is immutable). -
toString
Render string representation of QName using format:{namespace}name
-
compareTo
Uses thenamespace URI
and then thelocalname
to do the comparison i.e. the comparison is alphabetical.- Specified by:
compareTo
in interfaceComparable<QName>
-
toPrefixString
Render string representation of QName using format:prefix:name
- Returns:
- the string representation
-
getPrefixString
Getter version of toPrefixString()- Returns:
- the string representation of QName
-
toPrefixString
Render string representation of QName using format:prefix:name
according to namespace prefix mappings of specified namespace resolver.- Parameters:
prefixResolver
- namespace prefix resolver- Returns:
- the string representation
-
resolveToQName
Creates a QName representation for the given String. If the String has no namespace the Alfresco namespace is added. If the String has a prefix an attempt to resolve the prefix to the full URI will be made.- Parameters:
str
- The string to convert- Returns:
- A QName representation of the given string
-
resolveToQNameString
Creates a string representation of a QName for the given string. If the given string already has a namespace, either a URL or a prefix, nothing the given string is returned. If it does not have a namespace the Alfresco namespace is added.- Parameters:
str
- The string to convert- Returns:
- A QName String representation of the given string
-