org.omnaest.utils.xml
Class JAXBXMLHelper

java.lang.Object
  extended by org.omnaest.utils.xml.JAXBXMLHelper

public class JAXBXMLHelper
extends Object

Helper class for JAXB annotated classes.

Author:
Omnaest
See Also:
XMLHelper, XMLIteratorFactory, JAXBMap, JAXBList, JAXBSet, JAXBCollection

Nested Class Summary
static class JAXBXMLHelper.JAXBContextBasedUnmarshaller<E>
          Holder of a fully instantiated Unmarshaller instance
protected static class JAXBXMLHelper.MarshallingAndUnmarshallingConfigurationAbstractBase
          Configuration for the marshalling process
static class JAXBXMLHelper.MarshallingConfiguration
           
static class JAXBXMLHelper.UnmarshallingConfiguration
           
 
Field Summary
static String DEFAULT_ENCODING
           
 
Constructor Summary
JAXBXMLHelper()
           
 
Method Summary
static
<E> E
cloneObject(E object)
          Clones a given Object using storeObjectAsXML(Object) and loadObjectFromXML(CharSequence, Class)
static
<E> E
cloneObject(E object, JAXBXMLHelper.MarshallingConfiguration marshallingConfiguration)
          Similar to cloneObject(Object) allowing to specify a JAXBXMLHelper.MarshallingConfiguration
static QName determineRootName(Class<?> type)
          Returns the QName defined by the XmlRootElement of the given Class type
static
<E> E
loadObjectFromNode(Node node, Class<E> type)
          Similar to loadObjectFromNode(Node, Class, ExceptionHandler) but ignoring Exceptions
static
<E> E
loadObjectFromNode(Node node, Class<E> type, ExceptionHandler exceptionHandler)
          Loads an object of the given class type from an Node.
static
<E> E
loadObjectFromXML(CharSequence charSequence, Class<E> type)
          Loads an Object from a CharSequence which contains valid xml text content.
static
<E> E
loadObjectFromXML(CharSequence charSequence, Class<E> type, ExceptionHandler exceptionHandler)
          Loads an Object from a CharSequence which contains valid xml text content.
static
<E> E
loadObjectFromXML(CharSequence charSequence, Class<E> type, JAXBXMLHelper.UnmarshallingConfiguration unmarshallingConfiguration)
          Similar to loadObjectFromXML(CharSequence, Class) allowing to specify an JAXBXMLHelper.UnmarshallingConfiguration
static
<E> E
loadObjectFromXML(InputStream inputStream, Class<E> typeClazz)
          Loads an object from the given class type from an InputStream.
static
<E> E
loadObjectFromXML(InputStream inputStream, Class<E> type, ExceptionHandler exceptionHandler)
          Loads an object of the given class type from an InputStream.
static
<E> E
loadObjectFromXML(InputStream inputStream, Class<E> type, JAXBXMLHelper.UnmarshallingConfiguration unmarshallingConfiguration)
          Similar to loadObjectFromXML(InputStream, Class) allowing to declare a JAXBXMLHelper.UnmarshallingConfiguration
static
<E> E
loadObjectFromXML(String xmlContent, Class<E> typeClazz)
           
static
<E> E
loadObjectFromXML(String xmlContent, Class<E> type, ExceptionHandler exceptionHandler)
           
static
<E> JAXBXMLHelper.JAXBContextBasedUnmarshaller<E>
newJAXBContextBasedUnmarshaller(Class<E> type, JAXBXMLHelper.UnmarshallingConfiguration unmarshallingConfiguration)
          Returns a new JAXBXMLHelper.JAXBContextBasedUnmarshaller instance.
static String storeObjectAsXML(Object object)
          Stores the given object as XML String using the DEFAULT_ENCODING
static void storeObjectAsXML(Object object, Appendable appendable)
          Stores the given objects as XML within the given Appendable using the DEFAULT_ENCODING
static void storeObjectAsXML(Object object, Appendable appendable, String encoding)
          Stores the given object as XML within the given Appendable using the given encoding.
static String storeObjectAsXML(Object object, ExceptionHandler exceptionHandler)
          Stores the given object as XML String using the DEFAULT_ENCODING
static String storeObjectAsXML(Object object, JAXBXMLHelper.MarshallingConfiguration marshallingConfiguration)
          Similar to storeObjectAsXML(Object) but allows to specify a JAXBXMLHelper.MarshallingConfiguration instance
static void storeObjectAsXML(Object object, OutputStream outputStream)
          Stores a given JAXB annotated object to the given OutputStream using the DEFAULT_ENCODING
static void storeObjectAsXML(Object object, OutputStream outputStream, ExceptionHandler exceptionHandler)
           
static void storeObjectAsXML(Object object, OutputStream outputStream, JAXBXMLHelper.MarshallingConfiguration marshallingConfiguration)
          Stores a given JAXB annotated object to the given OutputStream using the given JAXBXMLHelper.MarshallingConfiguration
static void storeObjectAsXML(Object object, OutputStream outputStream, String encoding)
          Stores a given JAXB annotated object to the given OutputStream using the given character encoding
static void storeObjectAsXML(Object object, OutputStream outputStream, String encoding, ExceptionHandler exceptionHandler)
          Stores a given JAXB annotated object to the given OutputStream using the given character encoding
static String storeObjectAsXML(Object object, String encoding)
          Stores the given object as XML String using the given encoding.
static String storeObjectAsXML(Object object, String encoding, ExceptionHandler exceptionHandler)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_ENCODING

public static final String DEFAULT_ENCODING
See Also:
Constant Field Values
Constructor Detail

JAXBXMLHelper

public JAXBXMLHelper()
Method Detail

storeObjectAsXML

public static void storeObjectAsXML(Object object,
                                    OutputStream outputStream)
Stores a given JAXB annotated object to the given OutputStream using the DEFAULT_ENCODING

Parameters:
object -
outputStream -
See Also:
storeObjectAsXML(Object, OutputStream, String)

storeObjectAsXML

public static void storeObjectAsXML(Object object,
                                    OutputStream outputStream,
                                    ExceptionHandler exceptionHandler)
Parameters:
object -
outputStream -
exceptionHandler -
See Also:
storeObjectAsXML(Object)

storeObjectAsXML

public static void storeObjectAsXML(Object object,
                                    OutputStream outputStream,
                                    String encoding)
Stores a given JAXB annotated object to the given OutputStream using the given character encoding

Parameters:
object -
outputStream -
encoding -
See Also:
storeObjectAsXML(Object, OutputStream)

storeObjectAsXML

public static void storeObjectAsXML(Object object,
                                    OutputStream outputStream,
                                    String encoding,
                                    ExceptionHandler exceptionHandler)
Stores a given JAXB annotated object to the given OutputStream using the given character encoding

Parameters:
object -
outputStream -
encoding -
exceptionHandler - ExceptionHandler
See Also:
storeObjectAsXML(Object, OutputStream)

storeObjectAsXML

public static void storeObjectAsXML(Object object,
                                    OutputStream outputStream,
                                    JAXBXMLHelper.MarshallingConfiguration marshallingConfiguration)
Stores a given JAXB annotated object to the given OutputStream using the given JAXBXMLHelper.MarshallingConfiguration

Parameters:
object -
outputStream -
marshallingConfiguration - JAXBXMLHelper.MarshallingConfiguration
See Also:
storeObjectAsXML(Object, OutputStream)

storeObjectAsXML

public static void storeObjectAsXML(Object object,
                                    Appendable appendable)
Stores the given objects as XML within the given Appendable using the DEFAULT_ENCODING

Parameters:
object -
appendable -

storeObjectAsXML

public static void storeObjectAsXML(Object object,
                                    Appendable appendable,
                                    String encoding)
Stores the given object as XML within the given Appendable using the given encoding. E.g as Appendable a StringBuilder or StringBuffer can be used.

Parameters:
object -
appendable -
encoding -

storeObjectAsXML

public static String storeObjectAsXML(Object object)
Stores the given object as XML String using the DEFAULT_ENCODING

Parameters:
object -
Returns:
See Also:
storeObjectAsXML(Object, String)

storeObjectAsXML

public static String storeObjectAsXML(Object object,
                                      JAXBXMLHelper.MarshallingConfiguration marshallingConfiguration)
Similar to storeObjectAsXML(Object) but allows to specify a JAXBXMLHelper.MarshallingConfiguration instance

Parameters:
object -
marshallingConfiguration - JAXBXMLHelper.MarshallingConfiguration
Returns:
xml content

storeObjectAsXML

public static String storeObjectAsXML(Object object,
                                      ExceptionHandler exceptionHandler)
Stores the given object as XML String using the DEFAULT_ENCODING

Parameters:
object -
exceptionHandler - ExceptionHandler
Returns:
See Also:
storeObjectAsXML(Object, String)

storeObjectAsXML

public static String storeObjectAsXML(Object object,
                                      String encoding)
Stores the given object as XML String using the given encoding.

Parameters:
object -
encoding -
Returns:
See Also:
storeObjectAsXML(Object, OutputStream), storeObjectAsXML(Object)

storeObjectAsXML

public static String storeObjectAsXML(Object object,
                                      String encoding,
                                      ExceptionHandler exceptionHandler)
Parameters:
object -
encoding -
exceptionHandler -
Returns:
See Also:
storeObjectAsXML(Object, String)

loadObjectFromXML

public static <E> E loadObjectFromXML(InputStream inputStream,
                                      Class<E> typeClazz)
Loads an object from the given class type from an InputStream. The class has to have JAXB annotations.

Type Parameters:
E -
Parameters:
inputStream -
typeClazz -
Returns:

loadObjectFromXML

public static <E> E loadObjectFromXML(InputStream inputStream,
                                      Class<E> type,
                                      ExceptionHandler exceptionHandler)
Loads an object of the given class type from an InputStream. The class has to have JAXB annotations.

Type Parameters:
E -
Parameters:
inputStream -
type -
exceptionHandler -
Returns:

newJAXBContextBasedUnmarshaller

public static <E> JAXBXMLHelper.JAXBContextBasedUnmarshaller<E> newJAXBContextBasedUnmarshaller(Class<E> type,
                                                                                                JAXBXMLHelper.UnmarshallingConfiguration unmarshallingConfiguration)
Returns a new JAXBXMLHelper.JAXBContextBasedUnmarshaller instance. This can be used to marshal multiple InputStreams without the costly overhead of constructing a new JAXBContext each time.

Parameters:
type -
unmarshallingConfiguration -
Returns:
new JAXBXMLHelper.JAXBContextBasedUnmarshaller

loadObjectFromXML

public static <E> E loadObjectFromXML(InputStream inputStream,
                                      Class<E> type,
                                      JAXBXMLHelper.UnmarshallingConfiguration unmarshallingConfiguration)
Similar to loadObjectFromXML(InputStream, Class) allowing to declare a JAXBXMLHelper.UnmarshallingConfiguration

Type Parameters:
E -
Parameters:
inputStream - InputStream
type - Class
unmarshallingConfiguration - JAXBXMLHelper.UnmarshallingConfiguration
Returns:
new instance of type based on the xml content provided by the given InputStream
See Also:
newJAXBContextBasedUnmarshaller(Class, UnmarshallingConfiguration)

loadObjectFromNode

public static <E> E loadObjectFromNode(Node node,
                                       Class<E> type)
Similar to loadObjectFromNode(Node, Class, ExceptionHandler) but ignoring Exceptions

Type Parameters:
E -
Parameters:
node - Node
type -
Returns:

loadObjectFromNode

public static <E> E loadObjectFromNode(Node node,
                                       Class<E> type,
                                       ExceptionHandler exceptionHandler)
Loads an object of the given class type from an Node. The class has to have JAXB annotations.

Type Parameters:
E -
Parameters:
node - Node
type -
exceptionHandler -
Returns:

loadObjectFromXML

public static <E> E loadObjectFromXML(CharSequence charSequence,
                                      Class<E> type)
Loads an Object from a CharSequence which contains valid xml text content. The given Class type specifies the root object type.

Parameters:
charSequence -
type -
Returns:

loadObjectFromXML

public static <E> E loadObjectFromXML(CharSequence charSequence,
                                      Class<E> type,
                                      ExceptionHandler exceptionHandler)
Loads an Object from a CharSequence which contains valid xml text content. The given Class type specifies the root object type.

Parameters:
charSequence -
type -
exceptionHandler -
Returns:

loadObjectFromXML

public static <E> E loadObjectFromXML(CharSequence charSequence,
                                      Class<E> type,
                                      JAXBXMLHelper.UnmarshallingConfiguration unmarshallingConfiguration)
Similar to loadObjectFromXML(CharSequence, Class) allowing to specify an JAXBXMLHelper.UnmarshallingConfiguration

Parameters:
charSequence - CharSequence
type -
unmarshallingConfiguration - JAXBXMLHelper.UnmarshallingConfiguration
Returns:

loadObjectFromXML

public static <E> E loadObjectFromXML(String xmlContent,
                                      Class<E> typeClazz)
Parameters:
xmlContent -
typeClazz -
Returns:

loadObjectFromXML

public static <E> E loadObjectFromXML(String xmlContent,
                                      Class<E> type,
                                      ExceptionHandler exceptionHandler)
Parameters:
xmlContent -
type -
exceptionHandler -
Returns:

cloneObject

public static <E> E cloneObject(E object)
Clones a given Object using storeObjectAsXML(Object) and loadObjectFromXML(CharSequence, Class)

Parameters:
object -
Returns:

cloneObject

public static <E> E cloneObject(E object,
                                JAXBXMLHelper.MarshallingConfiguration marshallingConfiguration)
Similar to cloneObject(Object) allowing to specify a JAXBXMLHelper.MarshallingConfiguration

Parameters:
object -
Returns:

determineRootName

public static QName determineRootName(Class<?> type)
Returns the QName defined by the XmlRootElement of the given Class type

Parameters:
type -
Returns:
QName
Throws:
MissingXMLRootElementAnnotationException


Copyright © 2013. All Rights Reserved.