com.marringtons.database
Class ObjectXML

java.lang.Object
  extended bycom.marringtons.database.ObjectXML

public class ObjectXML
extends Object

Helper class for working with XML/object conversion. Has 2 static public methods for converting POJOs to and from XML.

   String xml = ObjectXML.toXML( object);
   to = (ObjectToTest) ObjectXML.fromXML( new StringReader( xml));
 
Objects are recorded in XML in the following format:
 <com.marringtons.database.ObjectsTest$ObjectToTest>
   <aString>a string</aString>
   <anInteger>19582003</anInteger>
   <innerObject>
     <anotherString>inner string</anotherString>
     <anotherInteger>12345678</anotherInteger>
     <anotherLongInteger>-9223372036854775808</anotherLongInteger>
   </innerObject>
   <longInteger>9223372036854775807</longInteger>
   <aMap>
     <java.lang.String>1of2</java.lang.String>
     <java.lang.String>one</java.lang.String>
     <java.lang.String>2of2</java.lang.String>
     <com.marringtons.database.ObjectsTest$InnerObject>
       <anotherString>innerObject in map</anotherString>
       <anotherInteger>222</anotherInteger>
       <anotherLongInteger>22222222</anotherLongInteger>
     </com.marringtons.database.ObjectsTest$InnerObject>
   </aMap>
   <aCollection>
     <java.lang.String>1of3</java.lang.String>
     <java.lang.String>2of3</java.lang.String>
     <java.lang.String>3of3</java.lang.String>
   </aCollection>
   <bytes length='4'>0,1,2,3</bytes>
   <innerObjects length='2'>
     <com.marringtons.database.ObjectsTest$InnerObject>
       <anotherString>1of2</anotherString>
       <anotherInteger>102</anotherInteger>
       <anotherLongInteger>11111111</anotherLongInteger>
     </com.marringtons.database.ObjectsTest$InnerObject>
     <com.marringtons.database.ObjectsTest$InnerObject>
       <anotherString>2of2</anotherString>
       <anotherInteger>202</anotherInteger>
       <anotherLongInteger>22222222</anotherLongInteger>
     </com.marringtons.database.ObjectsTest$InnerObject>
   </innerObjects>
 </com.marringtons.database.ObjectsTest$ObjectToTest>
 

Author:
Paul Marrington

Constructor Summary
ObjectXML()
           
 
Method Summary
static Object fromXML(Reader xml)
          Convert an XML stream into a POJO - using a static class directory for the purpose.
static String toXML(Object object)
          Convert a POJO to an XML representation.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ObjectXML

public ObjectXML()
Method Detail

toXML

public static String toXML(Object object)
                    throws IllegalArgumentException,
                           IllegalAccessException,
                           IOException
Convert a POJO to an XML representation. It uses a private common class directory not associated with any database.

Parameters:
object - POJO to create an XML representation from.
Returns:
string representation of the object as XML
Throws:
IOException
IllegalAccessException
IllegalArgumentException

fromXML

public static Object fromXML(Reader xml)
                      throws XMLexception
Convert an XML stream into a POJO - using a static class directory for the purpose.

Parameters:
xml - stream of object representations in XML
Returns:
One object converted from the stream.
Throws:
XMLexception - if anything goes wrong.


Copyright © 2004 Paul Marrington http://marringtons.com