org.jcoderz.commons.util
Class JaxbUtil

java.lang.Object
  extended by org.jcoderz.commons.util.JaxbUtil

public final class JaxbUtil
extends Object

Utility class to simplify JAXB marshalling/unmarshalling.

Author:
Albrecht Messner

Nested Class Summary
static class JaxbUtil.MarshalResult
          Holds the Result of an Marshal operation.
static class JaxbUtil.UnmarshalResult
          Holds the Result of an unmarshal operation.
static class JaxbUtil.ValidationEventCollector
          Validation handler for JAXB.
 
Method Summary
static JAXBContext getJaxbContext(String contextPath)
          Returns a JAXB context for the given context path.
static JaxbUtil.MarshalResult marshal(Object data, JAXBContext ctx)
          Serializes (marshals) a given JAXB object and returns the result as byte array, along with the validation events collected during marshalling.
static JaxbUtil.MarshalResult marshal(Object data, String contextPath)
          Serializes (marshals) a given JAXB object and returns the result as byte array, along with the validation events collected during marshalling.
static JaxbUtil.UnmarshalResult unmarshal(InputSource data, JAXBContext ctx)
          Unmarshals the given InputSource and returns the unmarshalled object along with the validation event collector.
static JaxbUtil.UnmarshalResult unmarshal(InputSource data, String ctxPath)
          Unmarshals the given InputSource and returns the unmarshalled object along with the validation event collector.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getJaxbContext

public static JAXBContext getJaxbContext(String contextPath)
                                  throws JAXBException
Returns a JAXB context for the given context path. Contexts are cached in a hash map.

Parameters:
contextPath - the JAXB context path
Returns:
the jaxb context for the given context path
Throws:
JAXBException - if the context could not be retrieved

unmarshal

public static JaxbUtil.UnmarshalResult unmarshal(InputSource data,
                                                 String ctxPath)
                                          throws JAXBException
Unmarshals the given InputSource and returns the unmarshalled object along with the validation event collector.

Parameters:
data - the data to unmarshal
ctxPath - the context path from which the JAXBContext is created to create an unmarshaller
Returns:
the unmarshalled object along with its validation events
Throws:
JAXBException - if unmarshalling or validation fails.

unmarshal

public static JaxbUtil.UnmarshalResult unmarshal(InputSource data,
                                                 JAXBContext ctx)
                                          throws JAXBException
Unmarshals the given InputSource and returns the unmarshalled object along with the validation event collector.

Parameters:
data - the data to unmarshal
ctx - the JAXBContext from which the unmarshaller should be retrieved
Returns:
the unmarshalled object along with its validation events
Throws:
JAXBException - if unmarshalling or validation fails.

marshal

public static JaxbUtil.MarshalResult marshal(Object data,
                                             String contextPath)
                                      throws JAXBException
Serializes (marshals) a given JAXB object and returns the result as byte array, along with the validation events collected during marshalling.

Parameters:
data - the object to marshal
contextPath - the context path to retrieve the corresponding JAXB context for.
Returns:
the marshalled object and marshalling events
Throws:
JAXBException - if marshalling or validation fails.

marshal

public static JaxbUtil.MarshalResult marshal(Object data,
                                             JAXBContext ctx)
                                      throws JAXBException
Serializes (marshals) a given JAXB object and returns the result as byte array, along with the validation events collected during marshalling.

Parameters:
data - the object to marshal
ctx - the JAXBContext from which the unmarshaller can be retrieved.
Returns:
the marshalled object and marshalling events
Throws:
JAXBException - if marshalling or validation fails.


Copyright 2007 The jCoderZ Project.