walker
Class ExtendedXMLStreamReader

java.lang.Object
  extended by walker.ExtendedXMLStreamReader
All Implemented Interfaces:
java.io.Serializable

public class ExtendedXMLStreamReader
extends java.lang.Object
implements java.io.Serializable

Created by IntelliJ IDEA. User: andy Date: Mar 24, 2010 Extends XMLStreamReader with basic helper functions for parsing a wiseml with Stax.

See Also:
Serialized Form

Constructor Summary
ExtendedXMLStreamReader(java.io.InputStream is)
          Default Constructor.
 
Method Summary
 java.lang.String attr(java.lang.String attr)
          Parses a single attribute of the current element.
protected  Capability capability()
          Reads a single capability.
 boolean check(java.lang.String expect)
          Make sure that the current element is the one that is expected.
 void close()
           
 void debug()
           
 java.lang.String elementText()
          Parses the Text of the current wiseml element.
 java.lang.String getLocation()
          Returns the current Location of the XMLStreamReader
 javax.xml.stream.XMLStreamReader getReader()
           
 void navigate(java.lang.String expectedElement)
          Navigates to an expected element in the stream.
 java.lang.String navigateRead(java.lang.String expectedElement)
          Navigates to an expected element and reads its text.
 void nextElement()
          Safely navigates to the next element in the stream.
 void nextStaxElement()
          Navigates to the next Stax element.
protected  Position position()
          Reads a single position element.
protected  Rssi rssi()
          Reads a single Rssi object.
 java.lang.String text()
          Fail Safe retrieval of text.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ExtendedXMLStreamReader

public ExtendedXMLStreamReader(java.io.InputStream is)
                        throws javax.xml.stream.XMLStreamException
Default Constructor.

Parameters:
is - the xml InputStream
Throws:
javax.xml.stream.XMLStreamException - if there is an xml syntax
Method Detail

attr

public java.lang.String attr(java.lang.String attr)
Parses a single attribute of the current element. It is useful only if the current stream position is in a XMLStreamConstants.START_ELEMENT. The stream position stays the same as to allow an elementText() call, whick means that if no text is read, nextElement() should be called to move the stream to the std position.

Parameters:
attr - the name of the attribute.
Returns:
a String containing the attribute value.

capability

protected Capability capability()
                         throws badSyntaxException,
                                javax.xml.stream.XMLStreamException
Reads a single capability. The calling code has to move the stream to the next element.

Returns:
the new capability object.
Throws:
badSyntaxException - is thrown if the element values don't have the expected format.
javax.xml.stream.XMLStreamException - is thrown if there is a problem with xml syntax.

check

public boolean check(java.lang.String expect)
Make sure that the current element is the one that is expected.

Parameters:
expect - the expected element name.
Returns:
true if expected, else false.

close

public void close()
           throws javax.xml.stream.XMLStreamException
Throws:
javax.xml.stream.XMLStreamException

debug

public void debug()

elementText

public java.lang.String elementText()
                             throws javax.xml.stream.XMLStreamException,
                                    badSyntaxException,
                                    endDocumentException
Parses the Text of the current wiseml element. It is useful only if the current stream position is in a XMLStreamConstants.START_ELEMENT. In that case, it retrieves the current element's text, which in Stax terms is the next element.

Returns:
a String containing the parsed data or null.
Throws:
javax.xml.stream.XMLStreamException - is thrown if there is a problem with xml syntax.
badSyntaxException - is thrown if there is no text.
endDocumentException - if the root element is closed.

getLocation

public java.lang.String getLocation()
Returns the current Location of the XMLStreamReader

Returns:
a String representation of the Location containing the characterOffset, the collumnNumber and the lineNumber.

getReader

public javax.xml.stream.XMLStreamReader getReader()
Returns:
the XMLStreamReader.

navigate

public void navigate(java.lang.String expectedElement)
              throws javax.xml.stream.XMLStreamException,
                     badSyntaxException,
                     endDocumentException
Navigates to an expected element in the stream.

Parameters:
expectedElement - provide the name of the element to navigate to.
Throws:
javax.xml.stream.XMLStreamException - is thrown if there is no other element.
badSyntaxException - is thrown if after 200 elements no match is found.
endDocumentException - if the root element is closed.

navigateRead

public java.lang.String navigateRead(java.lang.String expectedElement)
                              throws javax.xml.stream.XMLStreamException,
                                     badSyntaxException,
                                     endDocumentException
Navigates to an expected element and reads its text.

Parameters:
expectedElement - provide the name of the element to navigate to.
Returns:
a String containing the parsed data or null.
Throws:
javax.xml.stream.XMLStreamException - is thrown if there is a problem with xml syntax.
badSyntaxException - is thrown if after 20 elements no match is found.
endDocumentException - if the root element is closed.

nextElement

public void nextElement()
                 throws javax.xml.stream.XMLStreamException,
                        endDocumentException
Safely navigates to the next element in the stream.

Throws:
javax.xml.stream.XMLStreamException - is thrown if there is no other element.
endDocumentException - if the root element is closed.

nextStaxElement

public void nextStaxElement()
                     throws javax.xml.stream.XMLStreamException,
                            endDocumentException
Navigates to the next Stax element.

Stax elements are:

Throws:
javax.xml.stream.XMLStreamException - is thrown if there is no other element.
endDocumentException - if the root element is closed.

position

protected Position position()
                     throws badSyntaxException,
                            javax.xml.stream.XMLStreamException
Reads a single position element. Starts at origin (or position) and ends at the following element.

Returns:
a Position object with the parsed information
Throws:
badSyntaxException - throwed if a required element is missing or if a text doesn't match the expected type
javax.xml.stream.XMLStreamException - is thrown if there is a problem with xml syntax.

rssi

protected Rssi rssi()
             throws badSyntaxException
Reads a single Rssi object. The calling code has to move the stream to the next element.

Returns:
a new rssi object.
Throws:
badSyntaxException - is thrown if the element values don't have the expected format.

text

public java.lang.String text()
                      throws badSyntaxException
Fail Safe retrieval of text. Text is retrieved only if stream is at a CDATA Stax element.

Returns:
a String containing the parsed data or null.
Throws:
badSyntaxException - if no text is found.