org.xeril.xml
Class ObjectToXml

java.lang.Object
  |
  +--org.xeril.xml.ObjectToXml

public class ObjectToXml
extends java.lang.Object

This class is used to display an object in XML


Field Summary
static java.lang.String NULL_TAG
          The constant for null objects
 
Constructor Summary
ObjectToXml(java.io.PrintWriter out)
          Constructor.
 
Method Summary
protected  void displayArray(java.lang.Object array, java.lang.Class cl, Indent ind, XmlMapDescriptor map_desc, java.lang.String tag_name)
          Displays the value provided.
protected  void displayField(java.lang.Object value, java.lang.Class cl, Indent ind, XmlMapDescriptor map_desc, java.lang.String tag_name)
          Displays a field.
 void displayObject(java.lang.Object o)
          Displays an object in XML format.
protected  void displayObject(java.lang.Object o, java.lang.Class cl, Indent ind)
          Displays an object in XML format.
protected  void displayValue(java.lang.Object value, java.lang.Class cl, Indent ind, XmlMapDescriptor map_desc)
          Displays the value provided.
protected  void displayValue(java.lang.Object value, java.lang.Class cl, Indent ind, XmlMapper mapper)
          Displays the value provided.
protected  XmlMapDescriptor getXmlMapDescriptor(java.lang.String field_name, XmlInfo info)
          Tries to extract the map descriptor the field_name and info object.
static void objectToXml(java.lang.Object o, java.io.PrintWriter out)
          Displays an object in XML format.
protected  java.lang.String xmlizeString(java.lang.String original)
          Returns a string which is clean for XML.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NULL_TAG

public static final java.lang.String NULL_TAG
The constant for null objects

Constructor Detail

ObjectToXml

public ObjectToXml(java.io.PrintWriter out)
Constructor. You provide the print writer where xml will be written

Parameters:
out - the writer to write the xml result
Method Detail

objectToXml

public static void objectToXml(java.lang.Object o,
                               java.io.PrintWriter out)
                        throws java.lang.IllegalAccessException,
                               XmlMapperException
Displays an object in XML format. It will try to find an XmlInfo class from which we can extract more information to bypass the default behavior.

Parameters:
o - the object you want to display
out - the print writer for writing the result

displayObject

public void displayObject(java.lang.Object o)
                   throws java.lang.IllegalAccessException,
                          XmlMapperException
Displays an object in XML format. It will try to find an XmlInfo class from which we can extract more information to bypass the default behavior.

Parameters:
o - the object you want to display

displayObject

protected void displayObject(java.lang.Object o,
                             java.lang.Class cl,
                             Indent ind)
                      throws java.lang.IllegalAccessException,
                             XmlMapperException
Displays an object in XML format. It will try to find an XmlInfo class from which we can extract more information to bypass the default behavior.

Parameters:
o - the object you want to display
cl - the class of the object (if o == null.. impossible to find!)
ind - the indentation object

displayField

protected void displayField(java.lang.Object value,
                            java.lang.Class cl,
                            Indent ind,
                            XmlMapDescriptor map_desc,
                            java.lang.String tag_name)
                     throws java.lang.IllegalAccessException,
                            XmlMapperException
Displays a field. You must also provide the info value (which can be null) to be able to (eventually) extract some information from it.

Parameters:
value - the value of the field
cl - the class of the field
ind - the indentation object
map_desc - the map descriptor
tag_name - the name of the tag of the field

displayValue

protected void displayValue(java.lang.Object value,
                            java.lang.Class cl,
                            Indent ind,
                            XmlMapDescriptor map_desc)
                     throws XmlMapperException,
                            java.lang.IllegalAccessException
Displays the value provided. It will use a mapper to display it if necessary.

Parameters:
value - the value to display
cl - the class of the value
ind - the indentation object
map_desc - the map descriptor object to find (eventually) a mapper

displayValue

protected void displayValue(java.lang.Object value,
                            java.lang.Class cl,
                            Indent ind,
                            XmlMapper mapper)
                     throws XmlMapperException,
                            java.lang.IllegalAccessException
Displays the value provided. It will use a mapper to display it if necessary.

Parameters:
value - the value to display
cl - the class of the value
ind - the indentation object
mapper - the mapper to display the value

displayArray

protected void displayArray(java.lang.Object array,
                            java.lang.Class cl,
                            Indent ind,
                            XmlMapDescriptor map_desc,
                            java.lang.String tag_name)
                     throws XmlMapperException,
                            java.lang.IllegalAccessException
Displays the value provided. It will use a mapper to display it if necessary.

Parameters:
array - the array to display
cl - the class of the array
ind - the indentation object
map_desc - the map descriptor object to find (eventually) a mapper
tag_name - the name of the tag

getXmlMapDescriptor

protected XmlMapDescriptor getXmlMapDescriptor(java.lang.String field_name,
                                               XmlInfo info)
Tries to extract the map descriptor the field_name and info object. If no information is found in the info object then null is returned.

Parameters:
field_name - the name of the field we are looking for its map desc
info - the info object that may hold the tag name
Returns:
the map descriptor

xmlizeString

protected java.lang.String xmlizeString(java.lang.String original)
Returns a string which is clean for XML. It replaces the different signs '<', and '&' by their equivalent in XML. The string returned will be exactly the same one if original doesn't contain any of this character.

Parameters:
original - the string to clean (it is safe to use null)
Returns:
the cleaned string (or "" if original == null)