moos.ssds.model
Class XmlBuilder

java.lang.Object
  extended bymoos.ssds.model.XmlBuilder

public class XmlBuilder
extends java.lang.Object

Generate XML from the model

  Use As: // Get an instance XmlBuilder xb = new XmlBuilder(); // Add the elements that are to appear just below the root of the XML doc. // Here we just add an instance of deployment xb.addDeployments(aDeployment) // Transform the object graph to xml xb.marshal() xb.print() // view it in a console. xb.print(anOutputStream) // write it to an OutputStream xb.toFile(aFile) // Write out to a file.
 

Version:
: $Revision: 1.7 $

XmlBuilder uses reflection for marshalling XML from objects. Changes to the model can be handled without requring changes to this class. However, sometimes the result is undesirable, so some modifications may be required.


The Monterey Bay Aquarium Research Institute (MBARI) provides this documentation and code "as is", with no warranty, express or implied, of its quality or consistency. It is provided without support and without obligation on the part of MBARI to assist in its use, correction, modification, or enhancement. This information should not be published or distributed to third parties without specific written permission from MBARI.


Copyright 2002 MBARI.
MBARI Proprietary Information. All rights reserved.



@testcase test.moos.ssds.model.TestXmlBuilder
Author:
: $Author: mccann $

Constructor Summary
XmlBuilder()
           
 
Method Summary
 void add(java.lang.Object obj)
           
 void addAll(java.util.Collection c)
           
 void addDataProducer(DataProducer dataProducer)
           
 void addDeployment(Deployment deployment)
           
 void addDevice(Device device)
           
 void addHumanIntervention(HumanIntervention humanIntervention)
           
 void addProcessRun(ProcessRun processRun)
           
 void build()
          Deprecated. use marshall instead
 nu.xom.Document getDocument()
           
 java.util.Collection getRootElements()
           
 void marshal()
          Generates XML tree.
 void print()
          Print the XMl document to System.out
 void print(java.io.OutputStream out)
           
 void print(java.io.OutputStream out, java.lang.String encoding)
          Write the formated xml out to a stream
 void remove(java.lang.Object obj)
           
 void removeAll(java.util.Collection c)
           
 void removeDataProducer(DataProducer dataProducer)
           
 void removeDeployment(Deployment deployment)
           
 void removeDevice(Device device)
           
 void removeHumanIntervention(HumanIntervention humanIntervention)
           
 void removeProcessRun(ProcessRun processRun)
           
 void toFile(java.io.File file)
          Write formated xml to a file using "ISO-8859-1" encoding
 void toFile(java.io.File file, java.lang.String encoding)
          Write formated xml to a file using the specified encoding
 java.lang.String toFormattedXML()
           
 java.lang.String toString()
           
 java.lang.String toXML()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

XmlBuilder

public XmlBuilder()
Method Detail

build

public void build()
Deprecated. use marshall instead


marshal

public void marshal()
Generates XML tree. Use this after adding all the objects to be marshalled.
        XmlBuilder xb = new XmlBuilder(); xb.addDeployment(aDeployment); xb.marshal(); // Generate the xml tree xb.print(); // do something with the xml tree. Here we dump it to stdout
 


toXML

public java.lang.String toXML()
Returns:
The XML document as text

toFormattedXML

public java.lang.String toFormattedXML()
                                throws java.io.IOException,
                                       java.io.UnsupportedEncodingException
Returns:
The XML document as a formatted (indents & line breaks) string
Throws:
java.io.IOException
java.io.UnsupportedEncodingException

toString

public java.lang.String toString()
Returns:
The XML document as text

getDocument

public nu.xom.Document getDocument()
Returns:
The XML document as an Object

toFile

public void toFile(java.io.File file)
            throws java.io.IOException,
                   java.io.UnsupportedEncodingException
Write formated xml to a file using "ISO-8859-1" encoding

Parameters:
file - The file to write into.
Throws:
java.io.IOException
java.io.UnsupportedEncodingException

toFile

public void toFile(java.io.File file,
                   java.lang.String encoding)
            throws java.io.IOException,
                   java.io.UnsupportedEncodingException
Write formated xml to a file using the specified encoding

Parameters:
file - The file to write into.
encoding - the encodinb to use
Throws:
java.io.IOException
java.io.UnsupportedEncodingException

print

public void print(java.io.OutputStream out,
                  java.lang.String encoding)
           throws java.io.IOException,
                  java.io.UnsupportedEncodingException
Write the formated xml out to a stream

Parameters:
out - An outstream to write to
encoding - the encodinb to use
Throws:
java.io.IOException
java.io.UnsupportedEncodingException

print

public void print(java.io.OutputStream out)
           throws java.io.IOException,
                  java.io.UnsupportedEncodingException
Throws:
java.io.IOException
java.io.UnsupportedEncodingException

print

public void print()
           throws java.io.IOException,
                  java.io.UnsupportedEncodingException
Print the XMl document to System.out

Throws:
java.io.IOException
java.io.UnsupportedEncodingException

addDevice

public void addDevice(Device device)

addDeployment

public void addDeployment(Deployment deployment)

addDataProducer

public void addDataProducer(DataProducer dataProducer)

addHumanIntervention

public void addHumanIntervention(HumanIntervention humanIntervention)

addProcessRun

public void addProcessRun(ProcessRun processRun)

removeDevice

public void removeDevice(Device device)

removeDeployment

public void removeDeployment(Deployment deployment)

removeDataProducer

public void removeDataProducer(DataProducer dataProducer)

removeHumanIntervention

public void removeHumanIntervention(HumanIntervention humanIntervention)

removeProcessRun

public void removeProcessRun(ProcessRun processRun)

add

public void add(java.lang.Object obj)

remove

public void remove(java.lang.Object obj)

addAll

public void addAll(java.util.Collection c)

removeAll

public void removeAll(java.util.Collection c)

getRootElements

public java.util.Collection getRootElements()