Project JXTA

net.jxta.util.documentSerializable
Class DocumentSerializableUtilities

java.lang.Object
  extended bynet.jxta.util.documentSerializable.DocumentSerializableUtilities

public class DocumentSerializableUtilities
extends Object


Constructor Summary
DocumentSerializableUtilities()
           
 
Method Summary
static void addBoolean(Element element, String tagName, boolean value)
          Add an Element with the specified tagname and value (converted to a String)
static void addDocumentSerializable(Element element, String tagName, DocumentSerializable documentSerializable)
          Add an Element with the specified tagname and value (converted to a String)
static void addDouble(Element element, String tagName, double value)
          Add an Element with the specified tagname and value (converted to a String)
static void addInt(Element element, String tagName, int value)
          Add an Element with the specified tagname and value (converted to a String)
static void addLong(Element element, String tagName, long value)
          Add an Element with the specified tagname and value (converted to a String)
static void addString(Element element, String tagName, String value)
          Add an Element with the specified tagname and value
static void copyChildren(Element toElement, Element fromElement)
          Deeply copy an element into another element
static DocumentSerializable copyDocumentSerializable(DocumentSerializable documentSerializable)
          Create a copy of any Document Serializable object.
static Element createChildElement(Element element, String tagName)
          Create a child element of the specified tagName This is done by serializing and then deserializing the object (ie not very efficient)
static XMLDocument createStructuredXmlDocument(String docType, DocumentSerializable documentSerializable)
          Creates a Structured XML Document containing the serialized object
static boolean getBoolean(Element element)
          Get the value of an element converted from a String ("true" or "false")
static boolean getBoolean(Element element, String tagName, boolean defaultValue)
          Get the value of a Child Element
static Element getChildElement(Element element, String tagName)
          Get a child element of the specified tagName This is done by serializing and then deserializing the object (ie not very efficient)
static DocumentSerializable getDocumentSerializable(Element element, Class clazz)
          Create an object from its Document Serialized components
static DocumentSerializable getDocumentSerializable(Element element, DocumentSerializable documentSerializable)
          Initialize an object from its Document Serialized components
static DocumentSerializable getDocumentSerializable(Element element, String tagName, Class clazz)
          Create an object from its Document Serialized components
static DocumentSerializable getDocumentSerializableFromXml(byte[] buf, Class clazz)
          Create a DocumentSerializable Object from an XML Document
static DocumentSerializable getDocumentSerializableFromXml(InputStream in, Class clazz)
          Create a DocumentSerializable Object from an XML Document
static DocumentSerializable getDocumentSerializableFromXml(String buf, Class clazz)
          Create a DocumentSerializable Object from an XML Document
static double getDouble(Element element)
          Get the value of an element converted from a String
static double getDouble(Element element, String tagName, double defaultValue)
          Get the value of a Child Element
static int getInt(Element element)
          Get the value of an element converted from a String
static int getInt(Element element, String tagName, int defaultValue)
          Get the value of a Child Element
static long getLong(Element element)
          Get the value of an element converted from a String
static long getLong(Element element, String tagName, long defaultValue)
          Get the value of a Child Element
static String getString(Element element)
          Get the value of an element as a String
static String getString(Element element, String tagName, String defaultValue)
          Get the value of a Child Element
static void printAsXmlString(DocumentSerializable documentSerializable)
          Write a DocumentSerializable object as an XML Document to StdErr The Root TagName will be 'documentSerializable' by default
static String toXmlString(DocumentSerializable documentSerializable)
          Convert a DocumentSerializable object to its XML representation as a String The Root TagName will be 'documentSerializable' by default
static String toXmlString(DocumentSerializable documentSerializable, String rootTagName)
          Convert a DocumentSerializable object to its XML representation as a String The Root TagName will be 'documentSerializable' by default
static void writeAsXmlString(OutputStream out, DocumentSerializable documentSerializable)
          Write a DocumentSerializable object as an XML Document to a Stream The Root TagName will be 'documentSerializable' by default
static void writeAsXmlString(OutputStream out, DocumentSerializable documentSerializable, String rootTagName)
          Write a DocumentSerializable object as an XML Document to a Stream The Root TagName will be 'documentSerializable' by default
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DocumentSerializableUtilities

public DocumentSerializableUtilities()
Method Detail

createStructuredXmlDocument

public static XMLDocument createStructuredXmlDocument(String docType,
                                                      DocumentSerializable documentSerializable)
                                               throws DocumentSerializationException
Creates a Structured XML Document containing the serialized object

Returns:
The created Document
Throws:
DocumentSerializationException - if Unable to parse the serialized object.

copyChildren

public static void copyChildren(Element toElement,
                                Element fromElement)
Deeply copy an element into another element

Parameters:
toElement - The target Element
fromElement - The source Element

addDocumentSerializable

public static void addDocumentSerializable(Element element,
                                           String tagName,
                                           DocumentSerializable documentSerializable)
                                    throws DocumentSerializationException
Add an Element with the specified tagname and value (converted to a String)

Parameters:
element - Parent Element that the new child element will be added to
tagName - TagName to be used for the created Child Element
documentSerializable - This value will be serialized into the created child element \ * @throws DocumentSerializationException if Unable to serialized object.
Throws:
DocumentSerializationException

getDocumentSerializable

public static DocumentSerializable getDocumentSerializable(Element element,
                                                           Class clazz)
                                                    throws DocumentSerializationException
Create an object from its Document Serialized components

Parameters:
element - The relative root element of a Document Serialized Object
clazz - The Class of the resurrected object (must implement DocumentSerializable and have a public no-arg constructor)
Returns:
An object of type 'clazz'
Throws:
DocumentSerializationException - if Unable to parse the serialized object.

getDocumentSerializable

public static DocumentSerializable getDocumentSerializable(Element element,
                                                           DocumentSerializable documentSerializable)
                                                    throws DocumentSerializationException
Initialize an object from its Document Serialized components

Parameters:
element - The relative root element of a Document Serialized Object
documentSerializable - The object that will be populated from the Element
Returns:
The same parameter passed to it 'documentSerializable'
Throws:
DocumentSerializationException - if Unable to parse the serialized object.

getDocumentSerializable

public static DocumentSerializable getDocumentSerializable(Element element,
                                                           String tagName,
                                                           Class clazz)
                                                    throws DocumentSerializationException
Create an object from its Document Serialized components

Parameters:
element - The Parent element which has a child Element with the serialized value
tagName - The tagname of the element that contains the relative root element of a Document Serialized Object
clazz - The Class of the resurrected object (must implement DocumentSerializable and have a public no-arg constructor)
Returns:
An object of type 'clazz'
Throws:
DocumentSerializationException - if Unable to parse the serialized object.

copyDocumentSerializable

public static DocumentSerializable copyDocumentSerializable(DocumentSerializable documentSerializable)
                                                     throws DocumentSerializationException
Create a copy of any Document Serializable object. This is done by serializing and then deserializing the object (ie not very efficient)

Parameters:
documentSerializable - The Object to be copied
Returns:
An copy of the presented object
Throws:
DocumentSerializationException - if Unable to serialize or parse object.

createChildElement

public static Element createChildElement(Element element,
                                         String tagName)
Create a child element of the specified tagName This is done by serializing and then deserializing the object (ie not very efficient)

Parameters:
element - The Parent Element
tagName - The Tag Name for the new Element
Returns:
The created Element

getChildElement

public static Element getChildElement(Element element,
                                      String tagName)
Get a child element of the specified tagName This is done by serializing and then deserializing the object (ie not very efficient)

Parameters:
element - The Parent Element
tagName - The Tag Name for the new Element
Returns:
The found Element

addInt

public static void addInt(Element element,
                          String tagName,
                          int value)
Add an Element with the specified tagname and value (converted to a String)

Parameters:
element - Parent Element that the new element will be added to
tagName - TagName to be used for the created Child Element
value - The value that will be stored in the Element as a String

getInt

public static int getInt(Element element)
Get the value of an element converted from a String

Parameters:
element - Element that contains the value
Returns:
the value converted from a String

getInt

public static int getInt(Element element,
                         String tagName,
                         int defaultValue)
Get the value of a Child Element

Parameters:
element - The Parant Element
tagName - The Tag Name of the Child Element that will contain the value
defaultValue - The return value if there is no Child Element with that Tag Name
Returns:
the value converted from a String

addLong

public static void addLong(Element element,
                           String tagName,
                           long value)
Add an Element with the specified tagname and value (converted to a String)

Parameters:
element - Parent Element that the new element will be added to
tagName - TagName to be used for the created Child Element
value - The value that will be stored in the Element as a String

getLong

public static long getLong(Element element)
Get the value of an element converted from a String

Parameters:
element - Element that contains the value
Returns:
the value converted from a String

getLong

public static long getLong(Element element,
                           String tagName,
                           long defaultValue)
Get the value of a Child Element

Parameters:
element - The Parant Element
tagName - The Tag Name of the Child Element that will contain the value
defaultValue - The return value if there is no Child Element with that Tag Name
Returns:
the value converted from a String

addDouble

public static void addDouble(Element element,
                             String tagName,
                             double value)
Add an Element with the specified tagname and value (converted to a String)

Parameters:
element - Parent Element that the new element will be added to
tagName - TagName to be used for the created Child Element
value - The value that will be stored in the Element as a String

getDouble

public static double getDouble(Element element)
Get the value of an element converted from a String

Parameters:
element - Element that contains the value
Returns:
the value converted from a String

getDouble

public static double getDouble(Element element,
                               String tagName,
                               double defaultValue)
Get the value of a Child Element

Parameters:
element - The Parant Element
tagName - The Tag Name of the Child Element that will contain the value
defaultValue - The return value if there is no Child Element with that Tag Name
Returns:
the value converted from a String

addBoolean

public static void addBoolean(Element element,
                              String tagName,
                              boolean value)
Add an Element with the specified tagname and value (converted to a String)

Parameters:
element - Parent Element that the new element will be added to
tagName - TagName to be used for the created Child Element
value - The value that will be stored in the Element as a String

getBoolean

public static boolean getBoolean(Element element)
Get the value of an element converted from a String ("true" or "false")

Parameters:
element - Element that contains the value
Returns:
the value converted from a String

getBoolean

public static boolean getBoolean(Element element,
                                 String tagName,
                                 boolean defaultValue)
Get the value of a Child Element

Parameters:
element - The Parant Element
tagName - The Tag Name of the Child Element that will contain the value
defaultValue - The return value if there is no Child Element with that Tag Name
Returns:
the value converted from a String

addString

public static void addString(Element element,
                             String tagName,
                             String value)
Add an Element with the specified tagname and value

Parameters:
element - Parent Element that the new element will be added to
tagName - TagName to be used for the created Child Element
value - The value that will be stored in the Element

getString

public static String getString(Element element)
Get the value of an element as a String

Parameters:
element - Element that contains the value
Returns:
the value converted from a String

getString

public static String getString(Element element,
                               String tagName,
                               String defaultValue)
Get the value of a Child Element

Parameters:
element - The Parant Element
tagName - The Tag Name of the Child Element that will contain the value
defaultValue - The return value if there is no Child Element with that Tag Name
Returns:
The value found in the Element

toXmlString

public static String toXmlString(DocumentSerializable documentSerializable)
                          throws DocumentSerializationException
Convert a DocumentSerializable object to its XML representation as a String The Root TagName will be 'documentSerializable' by default

Parameters:
documentSerializable - The Object to be converted to an XML Document
Returns:
The String representation of an XML Document
Throws:
DocumentSerializationException - if Unable to serialize object.

toXmlString

public static String toXmlString(DocumentSerializable documentSerializable,
                                 String rootTagName)
                          throws DocumentSerializationException
Convert a DocumentSerializable object to its XML representation as a String The Root TagName will be 'documentSerializable' by default

Parameters:
documentSerializable - The Object to be converted to an XML Document
Returns:
The String representation of an XML Document
Throws:
DocumentSerializationException - if Unable to serialize object.

writeAsXmlString

public static void writeAsXmlString(OutputStream out,
                                    DocumentSerializable documentSerializable)
                             throws IOException,
                                    DocumentSerializationException
Write a DocumentSerializable object as an XML Document to a Stream The Root TagName will be 'documentSerializable' by default

Parameters:
out - The Stream to write the document to
documentSerializable - The Object to be converted to an XML Document
Throws:
DocumentSerializationException - if Unable to serialize object.
IOException - if I/O error while writing

writeAsXmlString

public static void writeAsXmlString(OutputStream out,
                                    DocumentSerializable documentSerializable,
                                    String rootTagName)
                             throws IOException,
                                    DocumentSerializationException
Write a DocumentSerializable object as an XML Document to a Stream The Root TagName will be 'documentSerializable' by default

Parameters:
out - The Stream to write the document to
documentSerializable - The Object to be converted to an XML Document
Throws:
DocumentSerializationException - if Unable to serialize object.
IOException - if I/O error while writing

printAsXmlString

public static void printAsXmlString(DocumentSerializable documentSerializable)
Write a DocumentSerializable object as an XML Document to StdErr The Root TagName will be 'documentSerializable' by default

Parameters:
documentSerializable - The Object to be converted to an XML Document

getDocumentSerializableFromXml

public static DocumentSerializable getDocumentSerializableFromXml(String buf,
                                                                  Class clazz)
                                                           throws DocumentSerializationException
Create a DocumentSerializable Object from an XML Document

Parameters:
buf - The XML document contained in a String
clazz - The Class of the resurrected object (must implement DocumentSerializable and have a public no-arg constructor)
Returns:
An object of type 'clazz'
Throws:
DocumentSerializationException - if Unable to parse object.

getDocumentSerializableFromXml

public static DocumentSerializable getDocumentSerializableFromXml(byte[] buf,
                                                                  Class clazz)
                                                           throws DocumentSerializationException
Create a DocumentSerializable Object from an XML Document

Parameters:
buf - The XML document contained in a byte buffer
clazz - The Class of the resurrected object (must implement DocumentSerializable and have a public no-arg constructor)
Returns:
An object of type 'clazz'
Throws:
DocumentSerializationException - if Unable to parse object.

getDocumentSerializableFromXml

public static DocumentSerializable getDocumentSerializableFromXml(InputStream in,
                                                                  Class clazz)
                                                           throws DocumentSerializationException
Create a DocumentSerializable Object from an XML Document

Parameters:
in - The Stream containing an XML Document to be read
clazz - The Class of the resurrected object (must implement DocumentSerializable and have a public no-arg constructor)
Returns:
An object of type 'clazz'
Throws:
DocumentSerializationException - if Unable to parse object.

JXTA J2SE