tuwien.auto.calimero.xml.def
Class DefaultXMLReader

java.lang.Object
  extended by tuwien.auto.calimero.xml.def.DefaultXMLReader
All Implemented Interfaces:
XMLReader

public class DefaultXMLReader
extends java.lang.Object
implements XMLReader

Default XML reader implementation of the XMLReader interface.

Does not add any feature not already documented in the implemented interface.
This reader is not thread safe.


Field Summary
 
Fields inherited from interface tuwien.auto.calimero.xml.XMLReader
CHAR_DATA, END_DOC, END_TAG, NO_INPUT, START_DOC, START_TAG
 
Constructor Summary
DefaultXMLReader()
          Creates a new XML reader.
DefaultXMLReader(java.io.Reader r, boolean close)
          Creates a new XML reader with input r.
 
Method Summary
 void close()
          Closes this XML reader.
 void complete(Element e)
          Reads until end of element e.
 Element getCurrent()
          Returns the current element read with the last invocation of XMLReader.read().
 int getLineNumber()
          Returns the line number for the current position in a XML input source processed by this XML reader.
 int getPosition()
          Returns the current logical position in a XML document for this XML reader.
 int read()
          Reads to the next XML element tag, a CDATA section or character data.
 void setInput(java.io.Reader input, boolean close)
          Sets the input source for this XML reader.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultXMLReader

public DefaultXMLReader()
Creates a new XML reader.


DefaultXMLReader

public DefaultXMLReader(java.io.Reader r,
                        boolean close)
Creates a new XML reader with input r.

The Reader should already be buffered or wrapped with a buffered reader, if necessary (e.g. when reading from a file).

Parameters:
r - a Reader for input
close - true to close r if XML reader is closed, false otherwise
See Also:
XMLReader.setInput(Reader, boolean)
Method Detail

close

public void close()
           throws KNXMLException
Description copied from interface: XMLReader
Closes this XML reader.

If this XML reader is already closed, no action is performed. If for an input source was specified to get closed on invocation of this method, it is closed first (calling Reader.close().

Specified by:
close in interface XMLReader
Throws:
KNXMLException

complete

public void complete(Element e)
              throws KNXMLException
Description copied from interface: XMLReader
Reads until end of element e.

All gathered relevant information is stored into e.

Specified by:
complete in interface XMLReader
Parameters:
e - the element to be completed
Throws:
KNXMLException - if document is not well-formed, e.g. end of input or end-tag of parent element was reached before end of specified element

getCurrent

public final Element getCurrent()
Description copied from interface: XMLReader
Returns the current element read with the last invocation of XMLReader.read().

Specified by:
getCurrent in interface XMLReader
Returns:
current element or null if no element is available

getLineNumber

public final int getLineNumber()
Description copied from interface: XMLReader
Returns the line number for the current position in a XML input source processed by this XML reader.

On no input source, or before an input source is first read, 0 is returned.

Specified by:
getLineNumber in interface XMLReader
Returns:
line number, or 0 if no line number is available

getPosition

public final int getPosition()
Description copied from interface: XMLReader
Returns the current logical position in a XML document for this XML reader.

The position is given with constants like XMLReader.START_DOC or similar. If no input was set or the reader is closed, XMLReader.NO_INPUT is returned.

Specified by:
getPosition in interface XMLReader
Returns:
the logical position in the document

read

public int read()
         throws KNXMLException
Description copied from interface: XMLReader
Reads to the next XML element tag, a CDATA section or character data.

The logical position returned by this method can also be obtained with XMLReader.getPosition().
Comments and processing instructions can be ignored, i.e. skipped on reading.

Specified by:
read in interface XMLReader
Returns:
the current logical position after reading
Throws:
KNXMLException - on read error or a not well-formed XML document

setInput

public void setInput(java.io.Reader input,
                     boolean close)
Description copied from interface: XMLReader
Sets the input source for this XML reader.

If this XML reader was already closed, setting a new input has no effect.

Specified by:
setInput in interface XMLReader
Parameters:
input - a reader with input, like obtained from EntityResolver.getInputReader(java.io.InputStream)
close - true if the specified input reader should be closed on XMLReader.close(), false to leave it open