org.jscience.architecture.traffic.xml
Class XMLLoader

java.lang.Object
  extended by org.jscience.architecture.traffic.xml.XMLLoader

public class XMLLoader
extends java.lang.Object

This class can restore the state of the program from an XML file. It also provides methods which XMLSerializable objects can use to retrieve their child objects.


Field Summary
protected  boolean atEOF
           
protected  XMLElement nextElement
           
protected  org.jscience.architecture.traffic.xml.XMLReader reader
           
protected  XMLStack stack
           
 
Constructor Summary
protected XMLLoader()
          Simple constructor
  XMLLoader(java.io.File file)
          Make a new XMLLoader which loads from a file
  XMLLoader(java.net.Socket socket)
          Make a new XMLLoader which load from a socket
 
Method Summary
 void close()
          Close this XMLLoader
 void doStackDump()
          This method is just for debugging
 java.util.Enumeration getEnumeration(XMLSerializable parent)
          Ignores the further child objects of this XMLSerializable

/** Returns an enumeration of XML elements which can be loaded.

 java.util.Enumeration getEnumeration(XMLSerializable parent, java.lang.String tagName)
          Returns an enumeration of XML elements with a specific name which can be loaded.
 XMLElement getNextElement(XMLSerializable parent)
          Get the next element from the file
 XMLElement getNextElement(XMLSerializable parent, java.lang.String name)
          Get the next element from the file if it has a specific name
 java.lang.String getNextElementName()
           
 boolean hasNextElement(XMLSerializable parent)
          Checks if an XMLSerializable can get another element from the file
 boolean hasNextElement(XMLSerializable parent, java.lang.String name)
          Checks if an XMLSerializable can get an element with a specific name from the file.
 void load(XMLSerializable parent, XMLSerializable object)
          Load an XMLSerializable from the XML file
 void loadEnumeration(XMLSerializable parent, java.util.Enumeration o)
          Load an enumeration of XMLSerializables from the XML file
protected  void lookAhead()
          Fill the nextElement buffer if it is empty
protected  XMLElement pullNextElement()
          Tranfer the contents of the nextElement buffer to a XMLSerializable and fill the buffer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

reader

protected org.jscience.architecture.traffic.xml.XMLReader reader

nextElement

protected XMLElement nextElement

stack

protected XMLStack stack

atEOF

protected boolean atEOF
Constructor Detail

XMLLoader

protected XMLLoader()
Simple constructor


XMLLoader

public XMLLoader(java.io.File file)
          throws java.io.IOException,
                 XMLTreeException,
                 XMLInvalidInputException
Make a new XMLLoader which loads from a file

Parameters:
file - The file to load from
Throws:
java.io.IOException - If the XMLLoader cannot read from the XML file because of an IO error.
XMLTreeException - If something goes wrong while the parser is initializing the XML tree structure.
XMLInvalidInputException - If the XML file contains invalid values.

XMLLoader

public XMLLoader(java.net.Socket socket)
          throws java.io.IOException,
                 XMLTreeException,
                 XMLInvalidInputException
Make a new XMLLoader which load from a socket

Parameters:
file - The file to load from
Throws:
java.io.IOException - If the XMLLoader cannot read from the XML file because of an IO error.
XMLTreeException - If something goes wrong while the parser is initializing the XML tree structure.
XMLInvalidInputException - If the XML file contains invalid values.
Method Detail

load

public void load(XMLSerializable parent,
                 XMLSerializable object)
          throws XMLTreeException,
                 XMLInvalidInputException,
                 java.io.IOException
Load an XMLSerializable from the XML file

Parameters:
parent - The parent of this XMLSerializable
object - The XMLSerializable object itself
Throws:
java.io.IOException - If the XMLLoader cannot read from the XML file because of an IO error.
XMLTreeException - If something goes wrong while the parser is building the XML tree structure.
XMLInvalidInputException - If this XMLSerializable encounters invalid input or cannot load itself for another reason.

close

public void close()
Close this XMLLoader


loadEnumeration

public void loadEnumeration(XMLSerializable parent,
                            java.util.Enumeration o)
                     throws XMLTreeException,
                            XMLInvalidInputException,
                            java.io.IOException,
                            java.lang.ClassCastException
Load an enumeration of XMLSerializables from the XML file

Parameters:
parent - The parent of the XMLSerializables
o - The enumeration of XML serializables
Throws:
java.io.IOException - If the XMLLoader cannot read from the XML file because of an IO error.
XMLTreeException - If something goes wrong while the parser is building the XML tree structure.
XMLInvalidInputException - If one of the XMLSerializables encounters invalid input or cannot load itself for another reason.
java.lang.ClassCastException - If the enumeration contains an object that is not XMLSerializable

lookAhead

protected void lookAhead()
                  throws XMLTreeException,
                         java.io.IOException
Fill the nextElement buffer if it is empty

Throws:
java.io.IOException - If the XMLLoader cannot read from the XML file because of an IO error.
XMLTreeException - If something goes wrong while the parser is building the XML tree structure.

getNextElement

public XMLElement getNextElement(XMLSerializable parent)
                          throws XMLTreeException,
                                 java.io.IOException
Get the next element from the file

Parameters:
parent - The XMLSerializable which is asking for the next element
Returns:
The next XMLElement
Throws:
java.io.IOException - If the XMLLoader cannot read from the XML file because of an IO error.
XMLTreeException - If something goes wrong while the parser is building the XML tree structure or if the next element has another parent.

hasNextElement

public boolean hasNextElement(XMLSerializable parent)
Checks if an XMLSerializable can get another element from the file

Parameters:
parent - The XMLSerializable that wants to request the next element
Returns:
A boolean value which indicates if another element can be fetched.

getNextElement

public XMLElement getNextElement(XMLSerializable parent,
                                 java.lang.String name)
                          throws XMLTreeException,
                                 java.io.IOException
Get the next element from the file if it has a specific name

Parameters:
parent - The XMLSerializable which is asking for the next element
name - The name which the next element has to have
Returns:
The next XMLElement
Throws:
java.io.IOException - If the XMLLoader cannot read from the XML file because of an IO error.
XMLTreeException - If something goes wrong while the parser is building the XML tree structure or if the next element in the file has another name/parent.

hasNextElement

public boolean hasNextElement(XMLSerializable parent,
                              java.lang.String name)
Checks if an XMLSerializable can get an element with a specific name from the file.

Parameters:
parent - The XMLSerializable that wants to request the next element
name - The requested name
Returns:
A boolean value which indicates if an element with such a name can be fetched.

pullNextElement

protected XMLElement pullNextElement()
                              throws java.io.IOException,
                                     XMLTreeException
Tranfer the contents of the nextElement buffer to a XMLSerializable and fill the buffer.

Returns:
The XMLElement in the buffer
Throws:
java.io.IOException - If the XMLLoader cannot read from the XML file because of an IO error.
XMLTreeException - If something goes wrong while the parser is building the XML tree structure.

getNextElementName

public java.lang.String getNextElementName()
Returns:
The name of the XMLElement in the buffer, regardless of its parent. If the buffer is empty, then the return value is null.

getEnumeration

public java.util.Enumeration getEnumeration(XMLSerializable parent)
Ignores the further child objects of this XMLSerializable

/** Returns an enumeration of XML elements which can be loaded. More or less the enumeration form of getNextElement(parent). WARNING : using more than one of these enumerations simultaneously may result in unpredictable behaviour.

Parameters:
parent - The object which is requesting the enumeration
Returns:
An enumeration of XMLElements

getEnumeration

public java.util.Enumeration getEnumeration(XMLSerializable parent,
                                            java.lang.String tagName)
Returns an enumeration of XML elements with a specific name which can be loaded. More or less the enumeration form of getNextElement(parent,name). WARNING : using more than one of these enumerations simultaneously may result in unpredictable behaviour.

Parameters:
parent - The object which is requesting the enumeration
name - The requested name
Returns:
An enumeration of XMLElements

doStackDump

public void doStackDump()
This method is just for debugging