org.alfresco.service.namespace
Class QName

java.lang.Object
  extended by org.alfresco.service.namespace.QName
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.lang.Comparable, QNamePattern

public final class QName
extends java.lang.Object
implements QNamePattern, java.io.Serializable, java.lang.Cloneable, java.lang.Comparable

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.

See Also:
Serialized Form

Field Summary
static java.lang.String EMPTY_URI_SUBSTITUTE
           
static int MAX_LENGTH
           
static char NAMESPACE_BEGIN
           
static char NAMESPACE_END
           
static char NAMESPACE_PREFIX
           
 
Method Summary
 java.lang.Object clone()
           
 int compareTo(QName qname)
          Uses the namespace URI and then the localname to do the comparison i.e.
static QName createQName(java.lang.String qname)
          Create a QName from its internal string representation of the following format: {namespaceURI}localName
static QName createQName(java.lang.String qname, NamespacePrefixResolver prefixResolver)
          Create a QName (from prefix format) prefix:localName
static QName createQName(java.lang.String namespaceURI, java.lang.String localName)
          Create a QName (With no prefix)
static QName createQName(java.lang.String prefix, java.lang.String localName, NamespacePrefixResolver prefixResolver)
          Create a QName
static QName createQNameWithValidLocalName(java.lang.String namespaceURI, java.lang.String localName)
          Create a QName, optionally truncating the localname to QName.MAX_LENGTH.
static java.lang.String createValidLocalName(java.lang.String name)
          Create a valid local name from the specified name
 boolean equals(java.lang.Object object)
          Two QNames are equal only when both their name and namespace match.
 java.lang.String getLocalName()
          Gets the name
 java.lang.String getNamespaceURI()
          Gets the namespace
 QName getPrefixedQName(NamespacePrefixResolver resolver)
          Gets a prefix resolved version of this QName
 java.lang.String getPrefixString()
          Getter version of toPrefixString()
 int hashCode()
          Calculate hashCode.
 boolean isMatch(QName qname)
          Performs a direct comparison between qnames.
static QName resolveToQName(NamespacePrefixResolver prefixResolver, java.lang.String str)
          Creates a QName representation for the given String.
static java.lang.String resolveToQNameString(NamespacePrefixResolver prefixResolver, java.lang.String str)
          Creates a string representation of a QName for the given string.
static java.lang.String[] splitPrefixedQName(java.lang.String qname)
          Create a QName
 java.lang.String toPrefixString()
          Render string representation of QName using format: prefix:name
 java.lang.String toPrefixString(NamespacePrefixResolver prefixResolver)
          Render string representation of QName using format: prefix:name according to namespace prefix mappings of specified namespace resolver.
 java.lang.String toString()
          Render string representation of QName using format: {namespace}name
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

EMPTY_URI_SUBSTITUTE

public static final java.lang.String EMPTY_URI_SUBSTITUTE
See Also:
Constant Field Values

NAMESPACE_PREFIX

public static final char NAMESPACE_PREFIX
See Also:
Constant Field Values

NAMESPACE_BEGIN

public static final char NAMESPACE_BEGIN
See Also:
Constant Field Values

NAMESPACE_END

public static final char NAMESPACE_END
See Also:
Constant Field Values

MAX_LENGTH

public static final int MAX_LENGTH
See Also:
Constant Field Values
Method Detail

createQName

public static QName createQName(java.lang.String namespaceURI,
                                java.lang.String localName)
                         throws InvalidQNameException
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(java.lang.String prefix,
                                java.lang.String localName,
                                NamespacePrefixResolver prefixResolver)
                         throws InvalidQNameException,
                                NamespaceException
Create a QName

Parameters:
prefix - namespace prefix (maybe null or empty string)
localName - local name
prefixResolver - lookup to resolve mappings between prefix and namespace
Returns:
the QName
Throws:
InvalidQNameException
NamespaceException

createQName

public static QName createQName(java.lang.String qname,
                                NamespacePrefixResolver prefixResolver)
                         throws InvalidQNameException,
                                NamespaceException
Create a QName (from prefix format) prefix:localName

Parameters:
qname - qualified name of the following format prefix:localName
prefixResolver - lookup to resolve mappings between prefix and namespace
Returns:
the QName
Throws:
InvalidQNameException
NamespaceException

createQName

public static QName createQName(java.lang.String qname)
                         throws InvalidQNameException
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:
java.lang.IllegalArgumentException
InvalidQNameException

createQNameWithValidLocalName

public static QName createQNameWithValidLocalName(java.lang.String namespaceURI,
                                                  java.lang.String localName)
Create a QName, optionally truncating the localname to QName.MAX_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

public static java.lang.String createValidLocalName(java.lang.String name)
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 java.lang.String[] splitPrefixedQName(java.lang.String qname)
                                             throws InvalidQNameException,
                                                    NamespaceException
Create a QName

Parameters:
qname - qualified name of the following format prefix:localName
Returns:
string array where index 0 => prefix and index 1 => local name
Throws:
InvalidQNameException
NamespaceException

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
Overrides:
clone in class java.lang.Object
Throws:
java.lang.CloneNotSupportedException

getLocalName

public java.lang.String getLocalName()
Gets the name

Returns:
the name

getNamespaceURI

public java.lang.String getNamespaceURI()
Gets the namespace

Returns:
the namespace (empty string when not specified, but never null)

getPrefixedQName

public QName getPrefixedQName(NamespacePrefixResolver resolver)
Gets a prefix resolved version of this QName

Parameters:
resolver - namespace prefix resolver
Returns:
QName with prefix resolved

equals

public boolean equals(java.lang.Object object)
Two QNames are equal only when both their name and namespace match. Note: The prefix is ignored during the comparison.

Overrides:
equals in class java.lang.Object

isMatch

public boolean isMatch(QName qname)
Performs a direct comparison between qnames.

Specified by:
isMatch in interface QNamePattern
Parameters:
qname - the instance to check
Returns:
Returns true if the qname matches this pattern
See Also:
QName.equals(Object)

hashCode

public int hashCode()
Calculate hashCode. Follows pattern used by String where hashCode is cached (QName is immutable).

Overrides:
hashCode in class java.lang.Object

toString

public java.lang.String toString()
Render string representation of QName using format: {namespace}name

Overrides:
toString in class java.lang.Object
Returns:
the string representation

compareTo

public int compareTo(QName qname)
Uses the namespace URI and then the localname to do the comparison i.e. the comparison is alphabetical.

Specified by:
compareTo in interface java.lang.Comparable

toPrefixString

public java.lang.String toPrefixString()
Render string representation of QName using format: prefix:name

Returns:
the string representation

getPrefixString

public java.lang.String getPrefixString()
Getter version of toPrefixString()

Returns:
the string representation of QName

toPrefixString

public java.lang.String toPrefixString(NamespacePrefixResolver prefixResolver)
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

public static QName resolveToQName(NamespacePrefixResolver prefixResolver,
                                   java.lang.String str)
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

public static java.lang.String resolveToQNameString(NamespacePrefixResolver prefixResolver,
                                                    java.lang.String str)
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


Copyright © 2005 - 2010 Alfresco Software, Inc. All Rights Reserved.