dd.util
Class SimXMLReader

java.lang.Object
  extended bydd.util.SimXMLReader

public class SimXMLReader
extends java.lang.Object

Reads SimObjects from XML descriptions. This class encapsulates all of the reading of SimObject (and its subclasses) from XML. The methods here are closely associated with corresponding methods in SimXMLWriter. The structure of what is read depends implicity on what is written by SimXMLWriter.

For SimObject and each subclass, there are two complementary methods:
public static ObjectType readObjectTypeXML(Node node) (in SimXMLReader), and
public Node writeObjectTypeXML(ObjectType obj) (in SimXMLWriter).
where ObjectType is a SimObject or one of its subclasses (MapCell, Layer, and so on).

This mechanism makes it possible to read arbitrary SimObject objects directly from XML files and dynamically returning the proper kind of object. Because of the delicate nature of XML, it is very important that the kind of data expected by the reader is the format that the writer is generating for that class type. It is possible to verify this with the aid of a DTD for SimObjects, but this code does not enforce validation to that DTD.

Author:
Eric Scharff

Constructor Summary
SimXMLReader(java.io.Reader reader)
          Create an new reader on an XML file.
SimXMLReader(java.lang.String fileName)
          Create an new reader on an XML file.
 
Method Summary
 SimObject read()
          Reads from the input source provided and creates a new SimObject.
static SimObject read(org.w3c.dom.Element root)
           
static Layer readLayerXML(org.w3c.dom.Node node)
          Reads a Layer object from an XML representation.
static MapCell readMapCellXML(org.w3c.dom.Node node, Map map)
           
static Map readMapXML(org.w3c.dom.Node node)
          Reads a Map object from an XML representation.
static Proposal readProposalXML(org.w3c.dom.Node node)
           
static SimObject readSimObjectXML(org.w3c.dom.Node node)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SimXMLReader

public SimXMLReader(java.lang.String fileName)
Create an new reader on an XML file. The file specified should be an XML file containing a single SimObject.

Parameters:
fileName - name of the XML file to read

SimXMLReader

public SimXMLReader(java.io.Reader reader)
Create an new reader on an XML file. The file specified should be an XML file containing a single SimObject.

Parameters:
reader - character stream from which XML will be read
Method Detail

read

public SimObject read()
Reads from the input source provided and creates a new SimObject. This method parses the XML file and, depending on the element that is present, returns an appropriate type of SimObject. This method should be modified or subclassed if support for new kinds of SimObjects is necessary because it is responsible for dispatching from the names of XML nodes to appropriate XML readers.

Returns:
a new SimObject (or one of its subclasses) initialized based on the contents of the XML input, or null if an error occurs while processing or the node is unknown.

read

public static SimObject read(org.w3c.dom.Element root)

readMapXML

public static Map readMapXML(org.w3c.dom.Node node)
Reads a Map object from an XML representation. A Map object contains layers, cells, and attributes. Reading this object in should return a complete model of the current Map.

Parameters:
node - XML node that represents the Map
Returns:
an initialized Map object based on the contents of the node

readProposalXML

public static Proposal readProposalXML(org.w3c.dom.Node node)

readSimObjectXML

public static SimObject readSimObjectXML(org.w3c.dom.Node node)

readLayerXML

public static Layer readLayerXML(org.w3c.dom.Node node)
Reads a Layer object from an XML representation. A Layer object has a name and attributes. (Note that attributes associated with layers are stored in cells. Reading this object should return a complete model of the Layer.

Parameters:
node - XML node that represents the Layer
Returns:
an initialized Layer object based on the contents of the node

readMapCellXML

public static MapCell readMapCellXML(org.w3c.dom.Node node,
                                     Map map)