org.tinyjee.maven.dim.utils
Class JaxbXmlSerializer<E>

java.lang.Object
  extended by org.tinyjee.maven.dim.utils.JaxbXmlSerializer<E>

public class JaxbXmlSerializer<E>
extends Object

Implements a helper class that can serialize JAXB annotated classes between class tree and DOM document.

Author:
Juergen_Kellerer, 2011-10-23

Field Summary
 String defaultSchemaBasename
           
 String namespace
           
 
Constructor Summary
JaxbXmlSerializer(Class<E> type)
          Constructs a new XmlSerializer for the given type.
JaxbXmlSerializer(Class<E> type, String defaultSchemaBasename)
          Constructs a new XmlSerializer for the given type.
JaxbXmlSerializer(Class<E> type, String namespace, String defaultSchemaBasename)
          Constructs a new XmlSerializer for the given type.
JaxbXmlSerializer(String namespace, String defaultSchemaBasename, Class<? extends E>... types)
          Constructs a new XmlSerializer for the given types.
 
Method Summary
 E deserialize(Document document)
          De-serializes the next type from the given document.
 Map<String,Document> generateSchema()
          Generates the XSD schema and returns a map of all generated documents.
 Map<String,Document> generateSchema(String basename)
          Generates the XSD schema and returns a map of all generated documents.
 javax.xml.bind.JAXBContext getJaxbContext()
           
 Document serialize(E instance, boolean includeSchema)
          Serializes the given instance and returns a DOM document of the serialized content.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

defaultSchemaBasename

public final String defaultSchemaBasename

namespace

public String namespace
Constructor Detail

JaxbXmlSerializer

public JaxbXmlSerializer(String namespace,
                         String defaultSchemaBasename,
                         Class<? extends E>... types)
Constructs a new XmlSerializer for the given types.

Parameters:
namespace - the namespace to use.
defaultSchemaBasename - the base filename to use when creating a XSD schema.
types - the types to include in this serializer.

JaxbXmlSerializer

public JaxbXmlSerializer(Class<E> type)
Constructs a new XmlSerializer for the given type.

Parameters:
type - the type to serialize and de-serialize.

JaxbXmlSerializer

public JaxbXmlSerializer(Class<E> type,
                         String defaultSchemaBasename)
Constructs a new XmlSerializer for the given type.

Parameters:
type - the type to serialize and de-serialize.
defaultSchemaBasename - the base filename to use when creating a XSD schema.

JaxbXmlSerializer

public JaxbXmlSerializer(Class<E> type,
                         String namespace,
                         String defaultSchemaBasename)
Constructs a new XmlSerializer for the given type.

Parameters:
type - the type to serialize and de-serialize.
namespace - the namespace to use.
defaultSchemaBasename - the base filename to use when creating a XSD schema.
Method Detail

getJaxbContext

public javax.xml.bind.JAXBContext getJaxbContext()

generateSchema

public Map<String,Document> generateSchema()
                                    throws Exception
Generates the XSD schema and returns a map of all generated documents.

Returns:
a list of all files that were generated.
Throws:
Exception - in case of schema creation failed.

generateSchema

public Map<String,Document> generateSchema(String basename)
                                    throws Exception
Generates the XSD schema and returns a map of all generated documents.

Parameters:
basename - the basename to use for naming the XSD files.
Returns:
a list of all files that were generated.
Throws:
Exception - in case of schema creation failed.

deserialize

public E deserialize(Document document)
              throws Exception
De-serializes the next type from the given document.

Parameters:
document - the document to read from.
Returns:
the next de-serialized type contained in the stream.
Throws:
Exception - in case of reading or de-serializing fails.

serialize

public Document serialize(E instance,
                          boolean includeSchema)
                   throws Exception
Serializes the given instance and returns a DOM document of the serialized content.

Parameters:
instance - the instance to save.
includeSchema - Whether the XSD schema shall be referenced and created inside the output directory.
Returns:
The serialized document.
Throws:
Exception - in case of writing or serializing failed.