JDOM
2.0.5

org.jdom2.util
Class NamespaceStack

java.lang.Object
  extended by org.jdom2.util.NamespaceStack
All Implemented Interfaces:
java.lang.Iterable<Namespace>

public final class NamespaceStack
extends java.lang.Object
implements java.lang.Iterable<Namespace>

A high-performance stack for processing those Namespaces that are introduced or are in-scope at a point in an Element hierarchy.

This stack implements the 'Namespace Rules' which XML uses, where a Namespace 'redefines' an existing Namespace if they share the same prefix. This class is intended to provide a high-performance mechanism for calculating the Namespace scope for an Element, and identifying what Namespaces an Element introduces in to the scope. This is not a validation tool.

This class implements Iterable which means it can be used in the context of a for-each type loop:

   NamespaceStack namespacestack = new NamespaceStack();
   for (Namespace ns : namespacestack) {
      ...
   }
 
The Iteration in the above example will return those Namespaces which are in-scope for the current level of the stack. The Namespace order will follow the JDOM 'standard'. The first namespace will be the Element's Namespace. The subsequent Namespaces will be the other in-scope namespaces in alphabetical order by the Namespace prefix.

NamespaceStack does not validate the push()/pop() cycles. It does not ensure that the pop() is for the same element that was previously pushed. Further, it does not check to make sure that the pushed() Element is the natural child of the previously pushed() Element.

Author:
Rolf Lear

Constructor Summary
NamespaceStack()
          Create a NamespaceWalker ready to use as a stack.
NamespaceStack(Namespace[] seed)
          Create a NamespaceWalker ready to use as a stack.
 
Method Summary
 java.lang.Iterable<Namespace> addedForward()
          Return an Iterable containing all the Namespaces introduced to the current-level's scope.
 java.lang.Iterable<Namespace> addedReverse()
          Return an Iterable containing all the Namespaces introduced to the current-level's scope but in reverse order to addedForward().
 Namespace[] getScope()
          Return a new array instance representing the current scope.
 boolean isInScope(Namespace ns)
          Inspect the current scope and return true if the specified namespace is in scope.
 java.util.Iterator<Namespace> iterator()
          Get all the Namespaces in-scope at the current level of the stack.
 void pop()
          Restore stack to the level prior to the current one.
 void push(Attribute att)
          Create a new in-scope level for the Stack based on an Attribute.
 void push(Element element)
          Create a new in-scope level for the Stack based on an Element.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NamespaceStack

public NamespaceStack()
Create a NamespaceWalker ready to use as a stack.

See Also:
for comprehensive notes.

NamespaceStack

public NamespaceStack(Namespace[] seed)
Create a NamespaceWalker ready to use as a stack.

Parameters:
seed - The namespaces to set as the top level of the stack.
See Also:
for comprehensive notes.
Method Detail

push

public void push(Element element)
Create a new in-scope level for the Stack based on an Element.
The Namespaces associated with the input Element are used to modify the 'in-scope' Namespaces in this NamespaceStack.
The following 'rules' will be applied:

Parameters:
element - The element at the new level of the stack.

push

public void push(Attribute att)
Create a new in-scope level for the Stack based on an Attribute.

Parameters:
att - The attribute to contribute to the namespace scope.

pop

public void pop()
Restore stack to the level prior to the current one. The various Iterator methods will thus return the data at the previous level.


addedForward

public java.lang.Iterable<Namespace> addedForward()
Return an Iterable containing all the Namespaces introduced to the current-level's scope.

Returns:
A read-only Iterable containing added Namespaces (may be empty);
See Also:
for the details on the data order.

addedReverse

public java.lang.Iterable<Namespace> addedReverse()
Return an Iterable containing all the Namespaces introduced to the current-level's scope but in reverse order to addedForward().

Returns:
A read-only Iterable containing added Namespaces (may be empty);
See Also:
for the details on the data order.

iterator

public java.util.Iterator<Namespace> iterator()
Get all the Namespaces in-scope at the current level of the stack.

Specified by:
iterator in interface java.lang.Iterable<Namespace>
Returns:
A read-only Iterator containing added Namespaces (may be empty);
See Also:
for the details on the data order.

getScope

public Namespace[] getScope()
Return a new array instance representing the current scope. Modifying the returned array will not affect this scope.

Returns:
a copy of the current scope.

isInScope

public boolean isInScope(Namespace ns)
Inspect the current scope and return true if the specified namespace is in scope.

Parameters:
ns - The Namespace to check
Returns:
true if the current scope contains that Namespace.

JDOM
2.0.5

Copyright � 2013 Jason Hunter, Brett McLaughlin. All Rights Reserved.