org.base.apps.beans.util
Class BetwixtUtil

java.lang.Object
  extended by org.base.apps.beans.util.BetwixtUtil

public class BetwixtUtil
extends Object

Utility methods to persist and load objects using Betwixt library.

Author:
Kevan Simpson

Nested Class Summary
static class BetwixtUtil.BaseSuppressionStrategy
           
static class BetwixtUtil.BaseTypeBindingStrategy
          Identifies Enum types as primitives, simplifying their persistence.
 
Constructor Summary
BetwixtUtil()
           
 
Method Summary
(package private) static void configure(XMLIntrospector xml, BindingConfiguration cfg)
          Configures Betwixt utities consistently for read-write reflexiveness.
(package private) static BeanReader newReader(Class<?> clz)
           
static
<T> T
readObject(Class<T> clz, File file)
          Reads an object of the specified type from the given file.
static
<T> T
readObject(Class<T> clz, String data)
          Reads an object of the specified type from the given file.
(package private) static void write(Object data, Writer out, boolean decl)
          ; Writes the specified object to the given file.
static String writeObject(Object data)
          ; Writes the specified object to a string
static void writeObject(Object data, File file)
          ; Writes the specified object to the given file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BetwixtUtil

public BetwixtUtil()
Method Detail

readObject

public static <T> T readObject(Class<T> clz,
                               String data)
                    throws Exception
Reads an object of the specified type from the given file.

Type Parameters:
T - The type of the object to read.
Parameters:
clz - The object's class instance.
data - The serialized data.
Returns:
The read object or null.
Throws:
org.apache.commons.lang.NullArgumentException - if either argument is null.
ClassCastException - if the data is not of type T.
Exception - if an severe occurs reading object.

readObject

public static <T> T readObject(Class<T> clz,
                               File file)
                    throws Exception
Reads an object of the specified type from the given file.

Type Parameters:
T - The type of the object to read.
Parameters:
clz - The object's class instance.
file - The file containing serialized data.
Returns:
The read object or null.
Throws:
org.apache.commons.lang.NullArgumentException - if either argument is null.
ClassCastException - if the data is not of type T.
Exception - if an severe occurs reading object.

newReader

static BeanReader newReader(Class<?> clz)
                     throws Exception
Throws:
Exception

configure

static void configure(XMLIntrospector xml,
                      BindingConfiguration cfg)
Configures Betwixt utities consistently for read-write reflexiveness.

Parameters:
xml - The xml introspector.
cfg - The binding configuration.

writeObject

public static void writeObject(Object data,
                               File file)
                        throws Exception
; Writes the specified object to the given file.

Parameters:
data - The object to write.
file - The file to which object is written.
Throws:
org.apache.commons.lang.NullArgumentException - if either argument is null.
Exception - if an severe occurs writing object.

writeObject

public static String writeObject(Object data)
                          throws Exception
; Writes the specified object to a string

Parameters:
data - The object to write.
Throws:
org.apache.commons.lang.NullArgumentException - if either argument is null.
Exception - if an severe occurs writing object.

write

static void write(Object data,
                  Writer out,
                  boolean decl)
           throws Exception
; Writes the specified object to the given file.

Parameters:
data - The object to write.
out - The writer for this object.
decl - true if an XML declaration should be included
Throws:
org.apache.commons.lang.NullArgumentException - if either argument is null.
Exception - if an severe occurs writing object.

Please visit Base Apps, hosted on Sourceforge.net.

Copyright 2011, Blue Agate Software Entity (BASE)