All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class org.xmlmiddleware.xmlutils.XMLName

java.lang.Object
   |
   +----org.xmlmiddleware.xmlutils.XMLName

public class XMLName
extends Object
Contains information about a name in a namespace.

This class contains the local, qualified, and universal forms of a name, as well as the namespace prefix and URI. The local form of a name is the unprefixed name. The qualified form is constructed from the prefix, a colon, and the local name. The universal form is constructed from the namespace URI, a caret (^), and the local name. If the name does not belong to a namespace, then all three forms are the same and the prefix and URI are null. Note that an empty string ("") is used as the prefix for the default namespace. IMPORTANT: Unprefixed attribute names do not belong to a namespace.

For example:

    <foo:element1 attr1="bar" foo:attr2="baz" xmlns="http://foo">
foo:element1: -------------------------------------- Local name: "element1" Qualified name: "foo:element1" Universal name: "http://foo^element1" Prefix: "foo" Namespace URI: "http://foo"
attr1: -------------------------------------- Local name: "attr1" Qualified name: "attr1" Universal name: "attr1" Prefix: null Namespace URI: null
foo:attr2: -------------------------------------- Local name: "attr2" Qualified name: "foo:attr2" Universal name: "http://foo^attr2" Prefix: "foo" Namespace URI: "http://foo"
<element2>
element2: -------------------------------------- Local name: "element2" Qualified name: "element2" Universal name: "element2" Prefix: null Namespace URI: null
<element3 xmlns="http://foo" >
element2: -------------------------------------- Local name: "element3" Qualified name: "element3" Universal name: "http://foo^element3" Prefix: "" Namespace URI: "http://foo"

XMLName objects that have a namespace URI are not required to have a prefix. However, setPrefix(String) must be called on such objects before getPrefix() or getQualifiedName() can be called.

Note that the methods in this class perform only cursory checks on whether input local names, prefixes, and URIs are legal.

Version:
2.0
Author:
Ronald Bourret, 1998-9, 2001

Variable Index

 o SEPARATOR
The character used to separate the URI from the local name.

Method Index

 o create(String)
Construct an XMLName from a universal name.
 o create(String, Hashtable)
Construct an XMLName from a qualified name and a hashtable mapping prefixes to namespace URIS.
 o create(String, String)
Construct an XMLName from a local name and a namespace URI.
 o create(String, String, String)
Construct an XMLName from a local name, prefix, and namespace URI.
 o equals(Object)
Overrides Object.equals(Object).
 o getLocalFromQualified(String)
Get the local name from a qualified name.
 o getLocalFromUniversal(String)
Get the local name from a universal name.
 o getLocalName()
Get the local name.
 o getPrefix()
Get the namespace prefix.
 o getPrefixFromQualified(String)
Get the prefix from a qualified name.
 o getQualifiedName()
Get the qualified name.
 o getQualifiedName(String, Hashtable)
Construct a qualified name from a universal name and a hashtable mapping URIs to prefixes.
 o getQualifiedName(String, String)
Construct a qualified name.
 o getUniversalName()
Get the universal name.
 o getUniversalName(String, Hashtable)
Construct a universal name from a qualified name and a hashtable mapping prefixes to namespace URIS.
 o getUniversalName(String, String)
Construct a universal name.
 o getURI()
Get the namespace URI.
 o getURIFromUniversal(String)
Get the URI from a universal name.
 o hashCode()
Overrides Object.hashCode().
 o setPrefix(String)
Set the namespace prefix.

Variables

 o SEPARATOR
 public static String SEPARATOR
The character used to separate the URI from the local name.

This follows the convention in John Cowan's SAX namespace filter and uses a caret (^), which is neither a valid URI character nor a valid XML name character.

Methods

 o create
 public static XMLName create(String uri,
                              String localName,
                              String prefix)
Construct an XMLName from a local name, prefix, and namespace URI.

If the URI is non-null, the prefix may be null. In this case, getPrefix() and getQualifiedName() may not be called until the prefix is set.

If the prefix is non-null, the URI must not be null.

Parameters:
uri - The namespace URI. May be null.
local - The local name.
prefix - The namespace prefix. May be null. Use an empty string for the default namespace.
Returns:
The XMLName.
 o create
 public static XMLName create(String uri,
                              String localName)
Construct an XMLName from a local name and a namespace URI.

getPrefix() and getQualifiedName() may not be called until the prefix is set.

Parameters:
uri - The namespace URI. May be null.
local - The local name.
Returns:
The XMLName.
 o create
 public static XMLName create(String qualifiedName,
                              Hashtable uris)
Construct an XMLName from a qualified name and a hashtable mapping prefixes to namespace URIS.

Parameters:
qualifiedName - Qualified name. Not required to contain a prefix.
uris - Hashtable containing prefixes as keys and namespace URIs as values. If qualifiedName does not contain a colon, this may be null. Use an empty string ("") for the prefix of the default namespace.
Returns:
The XMLName.
Throws: IllegalArgumentException
Thrown if the qualified name contains more than one colon or the Hashtable does not contain the prefix as a key.
 o create
 public static XMLName create(String universalName)
Construct an XMLName from a universal name.

getPrefix() and getQualifiedName() may not be called until the prefix is set.

Parameters:
universalName - The universal name.
Returns:
The XMLName.
 o getQualifiedName
 public static String getQualifiedName(String prefix,
                                       String localName)
Construct a qualified name. Returns the local name if the URI is null.

Parameters:
prefix - The namespace prefix. May be null or empty.
localName - The local name.
 o getQualifiedName
 public static String getQualifiedName(String universalName,
                                       Hashtable prefixes)
Construct a qualified name from a universal name and a hashtable mapping URIs to prefixes.

Parameters:
universalName - The universal name. Not required to contain a URI.
prefixes - Hashtable containing namespace URIs as keys and prefixes as values. If the universal name does not contain a caret, this may be null. Use an empty string ("") for the prefix of the default namespace.
Throws: IllegalArgumentException
Thrown if no prefix corresponding to the namespace URI was found.
 o getUniversalName
 public static String getUniversalName(String uri,
                                       String localName)
Construct a universal name. Returns the local name if the URI is null.

Parameters:
uri - The namespace URI.
localName - The local name.
 o getUniversalName
 public static String getUniversalName(String qualifiedName,
                                       Hashtable uris)
Construct a universal name from a qualified name and a hashtable mapping prefixes to namespace URIS.

Parameters:
qualifiedName - Qualified name. Not required to contain a prefix.
uris - Hashtable containing prefixes as keys and namespace URIs as values.
Throws: IllegalArgumentException
Thrown if no URI corresponding to the prefix was found.
 o getPrefixFromQualified
 public static String getPrefixFromQualified(String qualifiedName)
Get the prefix from a qualified name.

Parameters:
qualifiedName - Qualified name.
Returns:
The prefix or null if there is no prefix.
 o getLocalFromQualified
 public static String getLocalFromQualified(String qualifiedName)
Get the local name from a qualified name.

Parameters:
qualifiedName - Qualified name.
Returns:
The local name.
 o getURIFromUniversal
 public static String getURIFromUniversal(String universalName)
Get the URI from a universal name.

Parameters:
universalName - Universal name.
Returns:
The URI or null if there is no URI.
 o getLocalFromUniversal
 public static String getLocalFromUniversal(String universalName)
Get the local name from a universal name.

Parameters:
universalName - Universal name.
Returns:
The local name.
 o getLocalName
 public final String getLocalName()
Get the local name.

Returns:
The local name.
 o getQualifiedName
 public final String getQualifiedName()
Get the qualified name.

Returns:
The qualified name.
Throws: IllegalStateException
Thrown if the namespace URI is non-null and the prefix has not been set.
 o getUniversalName
 public final String getUniversalName()
Get the universal name.

Returns:
The universal name.
 o getPrefix
 public final String getPrefix()
Get the namespace prefix.

Returns:
The prefix.
Throws: IllegalStateException
Thrown if the namespace URI is non-null and the prefix has not been set.
 o getURI
 public final String getURI()
Get the namespace URI.

Returns:
The namespace URI.
 o setPrefix
 public final void setPrefix(String prefix)
Set the namespace prefix.

Parameters:
prefix - The namespace prefix.
 o equals
 public boolean equals(Object obj)
Overrides Object.equals(Object).

An object is equal to this XMLName object if: (1) it is an XMLName object and (2) it has the same URI and local name. Note that two XMLName objects are considered equal even if they have different namespace prefixes.

Parameters:
obj - The reference object with which to compare.
Returns:
true if this object is the same as the obj argument; false otherwise.
Overrides:
equals in class Object
 o hashCode
 public int hashCode()
Overrides Object.hashCode().

Two XMLName objects that are equal according to the equals method return the same hash code.

Returns:
The hash code
Overrides:
hashCode in class Object

All Packages  Class Hierarchy  This Package  Previous  Next  Index