Package repast.simphony.xml
Class XMLSerializer
- java.lang.Object
-
- repast.simphony.xml.XMLSerializer
-
public class XMLSerializer extends Object
Wraps an XStream instance and adds converters specialized for simphony.- Author:
- Nick Collier
-
-
Constructor Summary
Constructors Constructor Description XMLSerializer()
Creates an XMLSerializer.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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.void
setXmlFile(File xmlFile)
Set the XML file for converters that need the file path for serializing out objects to other file types in the same folder as the XML file.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.
-
-
-
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 serializedwriter
- 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 serializedstream
- 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
-
setXmlFile
public void setXmlFile(File xmlFile)
Set the XML file for converters that need the file path for serializing out objects to other file types in the same folder as the XML file.- Parameters:
xmlFile
-
-
-