repast.simphony.xml
Class XMLSerializer

java.lang.Object
  extended by repast.simphony.xml.XMLSerializer

public class XMLSerializer
extends Object

Wraps an XStream instance and adds converters specialized for simphony.

Author:
Nick Collier

Constructor Summary
XMLSerializer()
          Creates an XMLSerializer.
 
Method Summary
 Object fromXML(InputStream input)
          Deserializes an object from an xml input stream.
 Object fromXML(Reader reader)
          Deserializes an object from an xml reader.
 Object fromXML(String xml)
          Deserializes an object from an xml String.
 void registerConverter(com.thoughtworks.xstream.converters.Converter converter)
          Registers a xstream converter.
 void setClassLoader(ClassLoader classLoader)
          Sets the classloader used when serializing / deserializing.
 String toXML(Object obj)
          Serializes the specified object to XML and returns that XML as a String.
 void toXML(Object obj, OutputStream stream)
          Serializes the specified object to the specified OutputStream.
 void toXML(Object obj, Writer writer)
          Serializes the specified object to the specified writer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XMLSerializer

public XMLSerializer()
Creates an XMLSerializer.

Method Detail

registerConverter

public void registerConverter(com.thoughtworks.xstream.converters.Converter converter)
Registers a xstream converter.

Parameters:
converter - the converter to register

toXML

public String toXML(Object obj)
Serializes the specified object to XML and returns that XML as a String.

Parameters:
obj - the object to serialize
Returns:
the XML
Throws:
com.thoughtworks.xstream.XStreamException - if the object cannot be serialized

toXML

public void toXML(Object obj,
                  Writer writer)
Serializes the specified object to the specified writer.

Parameters:
obj - the object to serialized
writer - the writer to write the XML to
Throws:
com.thoughtworks.xstream.XStreamException - if the object cannot be serialized

toXML

public void toXML(Object obj,
                  OutputStream stream)
Serializes the specified object to the specified OutputStream.

Parameters:
obj - the object to serialized
stream - the OutputStream to write the XML to
Throws:
com.thoughtworks.xstream.XStreamException - if the object cannot be serialized

fromXML

public Object fromXML(InputStream input)
Deserializes an object from an xml input stream.

Parameters:
input - the input stream
Returns:
the deserialized object.
Throws:
com.thoughtworks.xstream.XStreamException - if the object cannot be deserialized

fromXML

public Object fromXML(Reader reader)
Deserializes an object from an xml reader.

Parameters:
reader - the xml reader
Returns:
the deserialized object.
Throws:
com.thoughtworks.xstream.XStreamException - if the object cannot be deserialized

fromXML

public Object fromXML(String xml)
Deserializes an object from an xml String.

Parameters:
xml - the xml String
Returns:
the deserialized object.
Throws:
com.thoughtworks.xstream.XStreamException - if the object cannot be deserialized

setClassLoader

public void setClassLoader(ClassLoader classLoader)
Sets the classloader used when serializing / deserializing.

Parameters:
classLoader - the classloader to use