sk.baka.ikslibs
Class ElementStack

java.lang.Object
  extended by sk.baka.ikslibs.ElementStack
All Implemented Interfaces:
Iterable<QName>

public final class ElementStack
extends Object
implements Iterable<QName>

A stack of element names. Any element name may be added on top of the stack, however only element with correct qname as the supplied one can be popped. This functionality is intended to catch mismatched element qnames when operating with SAX handlers.

Author:
Martin Vysny

Constructor Summary
ElementStack()
          Constructs an empty stack.
ElementStack(ElementStack other)
          Copy-constructor.
 
Method Summary
 void assertEmpty()
          Ensures that the stack is empty.
 void clear()
          Removes all elements from the stack.
 boolean equals(Object obj)
           
 QName getRoot()
          Returns the root element's qname.
 int hashCode()
           
 boolean isEmpty()
          Tests if this stack is empty.
 Iterator<QName> iterator()
           
 void pop(QName qname)
          Removes the topmost qname from the stack.
 void push(QName qname)
          Pushes a qname onto the top of this stack.
 int size()
          Returns the length of the stack.
 QName topmost()
          Looks at the topmost qname without removing it from the stack.
 QName topmost(int i)
          Looks at the i-th topmost qname without removing it from the stack.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ElementStack

public ElementStack()
Constructs an empty stack.


ElementStack

public ElementStack(ElementStack other)
Copy-constructor.

Parameters:
other - clone given stack.
Method Detail

isEmpty

public boolean isEmpty()
Tests if this stack is empty.

Returns:
true if the stack is empty.

assertEmpty

public void assertEmpty()
                 throws SAXException
Ensures that the stack is empty.

Throws:
SAXException - if the stack is not empty.

topmost

public QName topmost()
Looks at the topmost qname without removing it from the stack.

Returns:
topmost qname.
Throws:
NoSuchElementException - if stack is empty.

topmost

public QName topmost(int i)
Looks at the i-th topmost qname without removing it from the stack.

Parameters:
i - index into the namespace path, 1 is the topmost, 2 is the second topmost etc.
Returns:
topmost qname.
Throws:
NoSuchElementException - if i points beyond root element.

pop

public void pop(QName qname)
         throws SAXException
Removes the topmost qname from the stack.

Parameters:
qname - expected qname of topmost element. You may use DOMUtils.getQName(String, String, String) to convert from the SAX-style qname.
Throws:
SAXException - if path is empty or topmost element's qname does not match.

push

public void push(QName qname)
Pushes a qname onto the top of this stack.

Parameters:
qname - new topmost qname. You may use DOMUtils.getQName(String, String, String) to convert from the SAX-style qname.

size

public int size()
Returns the length of the stack.

Returns:
the element number.

getRoot

public QName getRoot()
Returns the root element's qname.

Returns:
the bottom of the stack.
Throws:
NoSuchElementException - if stack is empty.

equals

public boolean equals(Object obj)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

toString

public String toString()
Overrides:
toString in class Object

iterator

public Iterator<QName> iterator()
Specified by:
iterator in interface Iterable<QName>

clear

public void clear()
Removes all elements from the stack.



Copyright © 2006 Martin Vysny - baka. All Rights Reserved.