org.dellroad.stuff.jibx
Class JiBXUtil

java.lang.Object
  extended by org.dellroad.stuff.jibx.JiBXUtil

public final class JiBXUtil
extends Object

Some simplified API methods for JiBX XML encoding/decoding.


Field Summary
static String XML_ENCODING
           
 
Method Summary
static
<T> T
readObject(Class<T> targetClass, InputStream input)
          Read in an object encoded as XML.
static
<T> T
readObject(Class<T> targetClass, String bindingName, InputStream input)
          Read in an object encoded as XML.
static
<T> T
readObject(Class<T> targetClass, String bindingName, URL url)
          Read in an object encoded as XML from an URL.
static
<T> T
readObject(Class<T> targetClass, URL url)
          Read in an object encoded as XML from an URL.
static String toString(Object obj)
          Encode the given instance as an XML document and return it as a String.
static String toString(Object obj, String bindingName)
          Encode the given instance as an XML document and return it as a String.
static void writeObject(Object obj, String bindingName, Writer writer)
          Write out the given instance encoded as an XML document with "UTF-8" as the declared encoding.
static
<T> void
writeObject(T obj, OutputStream output)
          Write out the given instance encoded as a UTF-8 encoded XML document.
static
<T> void
writeObject(T obj, String bindingName, OutputStream output)
          Write out the given instance encoded as a UTF-8 encoded XML document.
static
<T> void
writeObject(T obj, Writer writer)
          Write out the given instance encoded as an XML document with "UTF-8" as the declared encoding.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

XML_ENCODING

public static final String XML_ENCODING
See Also:
Constant Field Values
Method Detail

readObject

public static <T> T readObject(Class<T> targetClass,
                               InputStream input)
                    throws JiBXException,
                           IOException
Read in an object encoded as XML. This method assumes there is exactly one binding for the given class.

This method runs within a new invocation of IdGenerator.run() to support object references (see IdMapper).

The input is not closed by this method.

Parameters:
targetClass - target class
input - source for the XML document
Throws:
JiBXException - if there is a JiBX parse error
IOException - if an error occurs reading from input

readObject

public static <T> T readObject(Class<T> targetClass,
                               String bindingName,
                               InputStream input)
                    throws JiBXException,
                           IOException
Read in an object encoded as XML.

This method runs within a new invocation of IdGenerator.run() to support object references (see IdMapper).

The input is not closed by this method.

Parameters:
targetClass - target class
bindingName - binding name, or null to choose the only one
input - source for the XML document
Throws:
JiBXException - if there is a JiBX parse error
IOException - if an error occurs reading from input

readObject

public static <T> T readObject(Class<T> targetClass,
                               URL url)
                    throws JiBXException,
                           IOException
Read in an object encoded as XML from an URL. This method assumes there is exactly one binding for the given class.

This method runs within a new invocation of IdGenerator.run() to support object references (see IdMapper).

Parameters:
targetClass - target class
url - source for the XML document
Throws:
JiBXException - if there is a JiBX parse error
IOException - if an error occurs reading the referenced document

readObject

public static <T> T readObject(Class<T> targetClass,
                               String bindingName,
                               URL url)
                    throws JiBXException,
                           IOException
Read in an object encoded as XML from an URL.

This method runs within a new invocation of IdGenerator.run() to support object references (see IdMapper).

Parameters:
targetClass - target class
url - source for the XML document
bindingName - binding name, or null to choose the only one
Throws:
JiBXException - if there is a JiBX parse error
IOException - if an error occurs reading the referenced document

writeObject

public static <T> void writeObject(T obj,
                                   OutputStream output)
                        throws JiBXException,
                               IOException
Write out the given instance encoded as a UTF-8 encoded XML document. This method assumes there is exactly one binding for the given class.

This method runs within a new invocation of IdGenerator.run() to support object references (see IdMapper).

Parameters:
obj - object to write
output - output destination; will not be closed by this method
Throws:
JiBXException - if there is a JiBX encoding error
IOException - if an error occurs writing to output

writeObject

public static <T> void writeObject(T obj,
                                   String bindingName,
                                   OutputStream output)
                        throws JiBXException,
                               IOException
Write out the given instance encoded as a UTF-8 encoded XML document.

This method runs within a new invocation of IdGenerator.run() to support object references (see IdMapper).

Parameters:
obj - object to write
bindingName - binding name, or null to choose the only one
output - output destination; will not be closed by this method
Throws:
JiBXException - if there is a JiBX encoding error
IOException - if an error occurs writing to output

writeObject

public static <T> void writeObject(T obj,
                                   Writer writer)
                        throws JiBXException,
                               IOException
Write out the given instance encoded as an XML document with "UTF-8" as the declared encoding. This method assumes there is exactly one binding for the given class.

This method runs within a new invocation of IdGenerator.run() to support object references (see IdMapper).

Parameters:
obj - object to write
writer - output destination; will not be closed by this method
Throws:
JiBXException
IOException

writeObject

public static void writeObject(Object obj,
                               String bindingName,
                               Writer writer)
                        throws JiBXException,
                               IOException
Write out the given instance encoded as an XML document with "UTF-8" as the declared encoding.

This method runs within a new invocation of IdGenerator.run() to support object references (see IdMapper).

Parameters:
obj - object to write
bindingName - binding name, or null to choose the only one
writer - output destination; will not be closed by this method
Throws:
JiBXException
IOException

toString

public static String toString(Object obj)
                       throws JiBXException
Encode the given instance as an XML document and return it as a String. This method assumes there is exactly one binding for the given class.

This method runs within a new invocation of IdGenerator.run() to support object references (see IdMapper).

Parameters:
obj - object to encode
Throws:
JiBXException - if there is a JiBX encoding error

toString

public static String toString(Object obj,
                              String bindingName)
                       throws JiBXException
Encode the given instance as an XML document and return it as a String.

This method runs within a new invocation of IdGenerator.run() to support object references (see IdMapper).

Parameters:
obj - object to encode
bindingName - binding name, or null to choose the only one
Throws:
JiBXException - if there is a JiBX encoding error