dd.util
Class SimXMLWriter

java.lang.Object
  extended bydd.util.SimXMLWriter

public class SimXMLWriter
extends java.lang.Object

Writes SimObjects into XML descriptions. This class encapsulates all of the writing of SimObject (and its subclasses) into XML. The methods here are closely associated with corresponding methods in SimXMLReader. 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
SimXMLWriter(SimObject object)
          Create a new writer to write the SimObject.
 
Method Summary
 org.w3c.dom.Node getXMLNode()
          Returns an XML node for the current SimObject.
 void setDocument(org.w3c.dom.Document d)
          Sets the XML document associated with this writer.
 java.lang.String write()
          Wrties the SimObject into a String.
 void write(java.lang.String fileName)
          Writes the SimObject into a new XML file.
 org.w3c.dom.Node writeLayerXML(Layer layer)
           
 org.w3c.dom.Node writeMapCellXML(MapCell cell)
           
 org.w3c.dom.Node writeMapXML(Map map)
           
 org.w3c.dom.Node writeProposalXML(Proposal proposal)
           
 org.w3c.dom.Node writeSimObjectXML(SimObject obj)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SimXMLWriter

public SimXMLWriter(SimObject object)
Create a new writer to write the SimObject. By default, this object will be written into a new XML file.

Parameters:
object - simulation object to be written to the XML file
Method Detail

write

public void write(java.lang.String fileName)
Writes the SimObject into a new XML file. The SimObject used by this writer becomes the root element of a new XML file with the file name specified. The file is saved and closed after writing.

Parameters:
fileName - name of the XML file to write

write

public java.lang.String write()
Wrties the SimObject into a String. This string is a more compact representation than what is written to a file, and is suitable for transmission over a network.

Returns:
a strong with the XML contents for this node

setDocument

public void setDocument(org.w3c.dom.Document d)
Sets the XML document associated with this writer. Normally, it is not necessary to specify the document, as a new document is created with every new file. However, if you wish to embed the nodes returned by this document within another document, you must call this method so that all of the XML node fragments are generated from the same document.

Parameters:
d - document into which nodes will be embedded

getXMLNode

public org.w3c.dom.Node getXMLNode()
Returns an XML node for the current SimObject. This method determines the type of the SimObject and writes the description of that SimObject into the node returned by this method. This method is useful if several SimObjects should be added to the same XML file, or if only a fragment of XML is desired.

Returns:
the fully initialized XML representation for the SimObject

writeSimObjectXML

public org.w3c.dom.Node writeSimObjectXML(SimObject obj)

writeProposalXML

public org.w3c.dom.Node writeProposalXML(Proposal proposal)

writeMapXML

public org.w3c.dom.Node writeMapXML(Map map)

writeLayerXML

public org.w3c.dom.Node writeLayerXML(Layer layer)

writeMapCellXML

public org.w3c.dom.Node writeMapCellXML(MapCell cell)