|
JDOM 2.0.2 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.jdom2.util.NamespaceStack
public final class NamespaceStack
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:
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 namespacestack = new NamespaceStack();
for (Namespace ns : namespacestack) {
...
}
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.
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 |
---|
public NamespaceStack()
for comprehensive notes.
public NamespaceStack(Namespace[] seed)
seed
- The namespaces to set as the top level of the stack.for comprehensive notes.
Method Detail |
---|
public void push(Element element)
addedForward()
Iterable. The order of
the added Namespaces follows the same rules as above: first the
Element Namespace (only if that Namespace is actually added) followed
by the other added namespaces in alphabetical-by-prefix order.
addedReverse()
Iterable.
element
- The element at the new level of the stack.public void push(Attribute att)
att
- The attribute to contribute to the namespace scope.public void pop()
public java.lang.Iterable<Namespace> addedForward()
for the details on the data order.
public java.lang.Iterable<Namespace> addedReverse()
addedForward()
.
for the details on the data order.
public java.util.Iterator<Namespace> iterator()
iterator
in interface java.lang.Iterable<Namespace>
for the details on the data order.
public Namespace[] getScope()
public boolean isInScope(Namespace ns)
ns
- The Namespace to check
|
JDOM 2.0.2 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |