Class XMLSerializer

java.lang.Object
com.topologi.diffx.xml.XMLSerializer

public final class XMLSerializer extends Object
This class provides methods to serialize objects to XML.

There is no mechanism to prevent infinite loops if some objects (lists,...) reference themselves.

The underlying XML document is generated using an XML string buffer.

Version:
7 March 2005
  • Field Details

    • DF

      private static final DateFormat DF
      Date formatter.
    • xml

      private final XMLWriter xml
      Used to store the xml document of this class.

      Classes extending this class should use their constructors to set the size of the XMLStringBuffer.

  • Constructor Details

    • XMLSerializer

      public XMLSerializer(XMLWriter xml)
      Creates a new XML serializer using the specified XML writer.
      Parameters:
      xml - The XML string buffer to be used
  • Method Details

    • getXML

      public XMLWriter getXML()
      Returns the underlying XML document.
      Returns:
      the xml stringbuffer
    • serialize

      public void serialize(Object o, String name) throws IOException
      Serialises the given object using the given name as element name.

      This implementation is recursive. It calls itself for fields which are not of primitive type.

      Parameters:
      o - Object to be serialised as xml
      name - Name of object
      Throws:
      IOException - Should an I/O error occur.
    • serializeCollection

      public void serializeCollection(Collection<?> c) throws IOException
      Serialises the given Collection to xml.

      Iterates over every object and call the serialize(java.lang.Object, java.lang.String) method.

      Parameters:
      c - The Collection to be serialised to XML
      Throws:
      IOException - Should an I/O error occur.
    • serializeHashtable

      public void serializeHashtable(Hashtable<?,?> h) throws IOException
      Serialise the given Hashtable to xml.

      This methods only works if the Hashtable contains String objects.

      Parameters:
      h - The hashtable to be serialized to XML
      Throws:
      IOException - Should an I/O error occur.
    • serializeObject

      public void serializeObject(Object o) throws IOException
      Serialises the given object to xml by using the public methods getXXX().

      This method calls every getXXX() method from the object to get the returned object and then calls the serialize(Object, String) method with the returned object and the name xxx in lower case.

      Parameters:
      o - The object to be serialised as XML
      Throws:
      IOException - Should an I/O error occur.