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
-
SEPARATOR
- The character used to separate the URI from the local name.
-
create(String)
- Construct an XMLName from a universal name.
-
create(String, Hashtable)
- Construct an XMLName from a qualified name and a hashtable mapping
prefixes to namespace URIS.
-
create(String, String)
- Construct an XMLName from a local name and a namespace URI.
-
create(String, String, String)
- Construct an XMLName from a local name, prefix, and namespace URI.
-
equals(Object)
- Overrides Object.equals(Object).
-
getLocalFromQualified(String)
- Get the local name from a qualified name.
-
getLocalFromUniversal(String)
- Get the local name from a universal name.
-
getLocalName()
- Get the local name.
-
getPrefix()
- Get the namespace prefix.
-
getPrefixFromQualified(String)
- Get the prefix from a qualified name.
-
getQualifiedName()
- Get the qualified name.
-
getQualifiedName(String, Hashtable)
- Construct a qualified name from a universal name and a hashtable
mapping URIs to prefixes.
-
getQualifiedName(String, String)
- Construct a qualified name.
-
getUniversalName()
- Get the universal name.
-
getUniversalName(String, Hashtable)
- Construct a universal name from a qualified name and a hashtable mapping
prefixes to namespace URIS.
-
getUniversalName(String, String)
- Construct a universal name.
-
getURI()
- Get the namespace URI.
-
getURIFromUniversal(String)
- Get the URI from a universal name.
-
hashCode()
- Overrides Object.hashCode().
-
setPrefix(String)
- Set the namespace prefix.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
getLocalFromQualified
public static String getLocalFromQualified(String qualifiedName)
- Get the local name from a qualified name.
- Parameters:
- qualifiedName - Qualified name.
- Returns:
- The local name.
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.
getLocalFromUniversal
public static String getLocalFromUniversal(String universalName)
- Get the local name from a universal name.
- Parameters:
- universalName - Universal name.
- Returns:
- The local name.
getLocalName
public final String getLocalName()
- Get the local name.
- Returns:
- The local name.
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.
getUniversalName
public final String getUniversalName()
- Get the universal name.
- Returns:
- The universal name.
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.
getURI
public final String getURI()
- Get the namespace URI.
- Returns:
- The namespace URI.
setPrefix
public final void setPrefix(String prefix)
- Set the namespace prefix.
- Parameters:
- prefix - The namespace prefix.
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
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