Top Description Fields Constructors Methods
org.dom4j.tree

public Class NamespaceStack

extends Object
Class Inheritance
Imports
org.dom4j.DocumentFactory, .Namespace, .QName, java.util.ArrayList, .HashMap, .Map

NamespaceStack implements a stack of namespaces and optionally maintains a cache of all the fully qualified names (QName) which are in scope. This is useful when building or navigating a dom4j document.
Author
James Strachan
Version
$Revision: 1.13 $

Field Summary

Modifier and TypeField and Description
private Map<String, QName>
currentNamespaceCache

A cache of current namespace context cache of mapping from qualifiedName to QName

private Namespace
defaultNamespace

Caches the default namespace defined via xmlns=""

private DocumentFactory
documentFactory

The factory used to create new Namespace instances

private ArrayList<Map<String, QName>>
namespaceCacheList

The cache of qualifiedNames to QNames per namespace context

private ArrayList<Namespace>
namespaceStack

The Stack of namespaces

private Map<String, QName>
rootNamespaceCache

A cache of mapping from qualifiedName to QName before any namespaces are declared

Constructor Summary

AccessConstructor and Description
public
public

Method Summary

Modifier and TypeMethod and Description
public Namespace

Returns:

DOCUMENT ME!
addNamespace
(String
DOCUMENT ME!
prefix
,
String
DOCUMENT ME!
uri
)

Adds a new namespace to the stack

public void
clear()

Clears the stack

public boolean

Returns:

true if the given prefix is in the stack.
contains
(Namespace
DOCUMENT ME!
namespace
)

DOCUMENT ME!

protected Namespace

Returns:

DOCUMENT ME!
createNamespace
(String
DOCUMENT ME!
prefix
,
String
DOCUMENT ME!
namespaceURI
)

Factory method to creeate new Namespace instances.

protected QName

Returns:

DOCUMENT ME!
createQName
(String
DOCUMENT ME!
localName
,
String
DOCUMENT ME!
qualifiedName
,
Namespace
DOCUMENT ME!
namespace
)

Factory method to creeate new QName instances.

protected Namespace

Returns:

DOCUMENT ME!
findDefaultNamespace
()

Attempts to find the current default namespace on the stack right now or returns null if one could not be found

public QName
getAttributeQName(String namespaceURI, String localName, String qualifiedName)

public Namespace
public DocumentFactory
public Namespace

Returns:

the namespace at the specified index on the stack
getNamespace
(int
DOCUMENT ME!
index
)

DOCUMENT ME!

protected Map<String, QName>
public Namespace

Returns:

the namespace for the given prefix or null if it could not be found.
getNamespaceForPrefix
(String
DOCUMENT ME!
prefix
)

DOCUMENT ME!

public QName
getQName(String namespaceURI, String localName, String qualifiedName)

public String

Returns:

the URI for the given prefix or null if it could not be found.
getURI
(String
DOCUMENT ME!
prefix
)

DOCUMENT ME!

public Namespace

Returns:

Namespace popped from the stack
pop
()

Pops the most recently used Namespace from the stack

public Namespace

Returns:

DOCUMENT ME!
pop
(String
DOCUMENT ME!
prefix
)

Pops a namepace from the stack with the given prefix and URI

public void
push(Namespace
is the Namespace to add to the stack.
namespace
)

Pushes the given namespace onto the stack so that its prefix becomes available.

public void
push(String
DOCUMENT ME!
prefix
,
String
DOCUMENT ME!
uri
)

Adds a namepace to the stack with the given prefix and URI

protected QName

Returns:

DOCUMENT ME!
pushQName
(String
DOCUMENT ME!
localName
,
String
DOCUMENT ME!
qualifiedName
,
Namespace
DOCUMENT ME!
namespace
,
String
DOCUMENT ME!
prefix
)

Adds the QName to the stack of available QNames

protected Namespace

Returns:

DOCUMENT ME!
remove
(int
DOCUMENT ME!
index
)

Removes the namespace at the given index of the stack

public void
public int

Returns:

the number of namespaces on the stackce stack.
size
()

DOCUMENT ME!

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

currentNamespaceCacheback to summary
private Map<String, QName> currentNamespaceCache

A cache of current namespace context cache of mapping from qualifiedName to QName

defaultNamespaceback to summary
private Namespace defaultNamespace

Caches the default namespace defined via xmlns=""

documentFactoryback to summary
private DocumentFactory documentFactory

The factory used to create new Namespace instances

namespaceCacheListback to summary
private ArrayList<Map<String, QName>> namespaceCacheList

The cache of qualifiedNames to QNames per namespace context

namespaceStackback to summary
private ArrayList<Namespace> namespaceStack

The Stack of namespaces

rootNamespaceCacheback to summary
private Map<String, QName> rootNamespaceCache

A cache of mapping from qualifiedName to QName before any namespaces are declared

Constructor Detail

NamespaceStackback to summary
public NamespaceStack()
NamespaceStackback to summary
public NamespaceStack(DocumentFactory documentFactory)

Method Detail

addNamespaceback to summary
public Namespace addNamespace(String prefix, String uri)

Adds a new namespace to the stack

Parameters
prefix:String

DOCUMENT ME!

uri:String

DOCUMENT ME!

Returns:Namespace

DOCUMENT ME!

clearback to summary
public void clear()

Clears the stack

containsback to summary
public boolean contains(Namespace namespace)

DOCUMENT ME!

Parameters
namespace:Namespace

DOCUMENT ME!

Returns:boolean

true if the given prefix is in the stack.

createNamespaceback to summary
protected Namespace createNamespace(String prefix, String namespaceURI)

Factory method to creeate new Namespace instances. By default this method interns the Namespace

Parameters
prefix:String

DOCUMENT ME!

namespaceURI:String

DOCUMENT ME!

Returns:Namespace

DOCUMENT ME!

createQNameback to summary
protected QName createQName(String localName, String qualifiedName, Namespace namespace)

Factory method to creeate new QName instances. By default this method interns the QName

Parameters
localName:String

DOCUMENT ME!

qualifiedName:String

DOCUMENT ME!

namespace:Namespace

DOCUMENT ME!

Returns:QName

DOCUMENT ME!

findDefaultNamespaceback to summary
protected Namespace findDefaultNamespace()

Attempts to find the current default namespace on the stack right now or returns null if one could not be found

Returns:Namespace

DOCUMENT ME!

getAttributeQNameback to summary
public QName getAttributeQName(String namespaceURI, String localName, String qualifiedName)
getDefaultNamespaceback to summary
public Namespace getDefaultNamespace()
getDocumentFactoryback to summary
public DocumentFactory getDocumentFactory()
getNamespaceback to summary
public Namespace getNamespace(int index)

DOCUMENT ME!

Parameters
index:int

DOCUMENT ME!

Returns:Namespace

the namespace at the specified index on the stack

getNamespaceCacheback to summary
protected Map<String, QName> getNamespaceCache()
getNamespaceForPrefixback to summary
public Namespace getNamespaceForPrefix(String prefix)

DOCUMENT ME!

Parameters
prefix:String

DOCUMENT ME!

Returns:Namespace

the namespace for the given prefix or null if it could not be found.

getQNameback to summary
public QName getQName(String namespaceURI, String localName, String qualifiedName)
getURIback to summary
public String getURI(String prefix)

DOCUMENT ME!

Parameters
prefix:String

DOCUMENT ME!

Returns:String

the URI for the given prefix or null if it could not be found.

popback to summary
public Namespace pop()

Pops the most recently used Namespace from the stack

Returns:Namespace

Namespace popped from the stack

popback to summary
public Namespace pop(String prefix)

Pops a namepace from the stack with the given prefix and URI

Parameters
prefix:String

DOCUMENT ME!

Returns:Namespace

DOCUMENT ME!

pushback to summary
public void push(Namespace namespace)

Pushes the given namespace onto the stack so that its prefix becomes available.

Parameters
namespace:Namespace

is the Namespace to add to the stack.

pushback to summary
public void push(String prefix, String uri)

Adds a namepace to the stack with the given prefix and URI

Parameters
prefix:String

DOCUMENT ME!

uri:String

DOCUMENT ME!

pushQNameback to summary
protected QName pushQName(String localName, String qualifiedName, Namespace namespace, String prefix)

Adds the QName to the stack of available QNames

Parameters
localName:String

DOCUMENT ME!

qualifiedName:String

DOCUMENT ME!

namespace:Namespace

DOCUMENT ME!

prefix:String

DOCUMENT ME!

Returns:QName

DOCUMENT ME!

removeback to summary
protected Namespace remove(int index)

Removes the namespace at the given index of the stack

Parameters
index:int

DOCUMENT ME!

Returns:Namespace

DOCUMENT ME!

setDocumentFactoryback to summary
public void setDocumentFactory(DocumentFactory documentFactory)
sizeback to summary
public int size()

DOCUMENT ME!

Returns:int

the number of namespaces on the stackce stack.

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.