org.ow2.weblab.core.extended.jaxb
Class WebLabMarshaller

java.lang.Object
  extended by org.ow2.weblab.core.extended.jaxb.WebLabMarshaller

public final class WebLabMarshaller
extends Object

A wrapping class for a JAXB Marshaller and a JAXB Unmarshaler. Many functions are available on Writer since it's easy for the use to create a Writer from a file or from an output stream. new OutputStreamWriter(new FileOutputStream(file)), "UTF-8"); Note that you need to close the I/O streams, readers and writers that you gave to this class. When you use a file, we close the opened stream.

Author:
Cassidian WebLab Team

Constructor Summary
WebLabMarshaller()
          Constructors of a marshaller that does not validate read/written XML files.
WebLabMarshaller(boolean validateWithSchema)
          Constructor of a marshaller that could use schema validation to ensure correctness of read/written XML files.
 
Method Summary
 void marshal(Resource resource, Writer writer, QName qname)
           
 void marshal(Resource resource, Writer writer, String qnameLocalPart)
           
 void marshalResource(Resource resource, File file)
           
 void marshalResource(Resource resource, OutputStream stream)
           
 void marshalResource(Resource resource, Writer writer)
           
 void marshalResource(Resource resource, Writer writer, boolean checkXML)
           
 void reset()
          Deprecated. 
 boolean setMarshallerProperty(String key, Object value)
           
 boolean setUnmarshallerProperty(String key, Object value)
           
<T extends Resource>
T
unmarshal(File file, Class<T> resourceClass)
           
<T extends Resource>
T
unmarshal(InputStream stream, Class<T> resourceClass)
           
<T extends Resource>
T
unmarshal(Reader reader, Class<T> resourceClass)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WebLabMarshaller

public WebLabMarshaller()
Constructors of a marshaller that does not validate read/written XML files.

See Also:
WebLabMarshaller(boolean)

WebLabMarshaller

public WebLabMarshaller(boolean validateWithSchema)
Constructor of a marshaller that could use schema validation to ensure correctness of read/written XML files.

Parameters:
validateWithSchema - Whether or not to validate read/written XML files using the WebLab Model XSD.
Method Detail

marshal

public void marshal(Resource resource,
                    Writer writer,
                    QName qname)
             throws WebLabCheckedException
Parameters:
resource - The Resource to be marshaled.
writer - The Writer to be written. Note that you need to close the writer after using this method.
qname - The QName of the field containing resource.
Throws:
WebLabCheckedException - if a JAXBException occurred.

marshal

public void marshal(Resource resource,
                    Writer writer,
                    String qnameLocalPart)
             throws WebLabCheckedException
Parameters:
resource - The Resource to be marshaled.
writer - The Writer to be written. Note that you need to close the writer after using this method.
qnameLocalPart - The name of the field containing resource.
Throws:
WebLabCheckedException - if a JAXBException occurred.

marshalResource

public void marshalResource(Resource resource,
                            File file)
                     throws WebLabCheckedException
Parameters:
resource - The resource to be marshaled.
file - The File to be written.
Throws:
WebLabCheckedException - if a JAXBException occurred.

marshalResource

public void marshalResource(Resource resource,
                            OutputStream stream)
                     throws WebLabCheckedException
Parameters:
resource - The Resource to be marshaled.
stream - The OutputStream to be written. Note that you need to close the stream after using this method.
Throws:
WebLabCheckedException - if a JAXBException occurred.

marshalResource

public void marshalResource(Resource resource,
                            Writer writer)
                     throws WebLabCheckedException
Parameters:
resource - The Resource to be marshaled.
writer - The Writer to be written. Note that you need to close the writer after using this method.
Throws:
WebLabCheckedException - if a JAXBException occurred.

marshalResource

public void marshalResource(Resource resource,
                            Writer writer,
                            boolean checkXML)
                     throws WebLabCheckedException
Parameters:
resource - The Resource to be marshaled.
writer - The Writer to be written. Note that you need to close the writer after using this method.
checkXML - Whether or not to clean the Resource from any not recommended XML char. Time of the process will be increased.
Throws:
WebLabCheckedException - if a JAXBException occurred.
See Also:
XMLStringCleaner

reset

@Deprecated
public void reset()
Deprecated. 

Reset marshaller, unmarshaller and jaxbContext.


setMarshallerProperty

public boolean setMarshallerProperty(String key,
                                     Object value)
Parameters:
key - The String key of the property to set.
value - The Object value of the property to set.
Returns:
false if an PropertyException occurred while setting the property.
See Also:
for key values.

setUnmarshallerProperty

public boolean setUnmarshallerProperty(String key,
                                       Object value)
Parameters:
key - The String key of the property to set
value - The Object value of the property to set
Returns:
false if an PropertyException occurred while setting the property
See Also:
for key values

unmarshal

public <T extends Resource> T unmarshal(File file,
                                        Class<T> resourceClass)
                             throws WebLabCheckedException
Type Parameters:
T - Class of the Resource to be unmarshaled
Parameters:
file - File to be read.
resourceClass - Class of the Resource to be unmarshaled. Using Resource will prevent from cast errors when the content of the File isn't compatible with resourceClass.
Returns:
an instance of resourceClass from the content of File.
Throws:
WebLabCheckedException - if a JAXBException, an IOException or a ClassCastException occurred.

unmarshal

public <T extends Resource> T unmarshal(InputStream stream,
                                        Class<T> resourceClass)
                             throws WebLabCheckedException
Type Parameters:
T - Class of the Resource to be unmarshaled
Parameters:
stream - InputStream to be read. Note that you need to close the stream after using this method.
resourceClass - Class of the Resource to be unmarshaled. Using Resource will prevent from cast errors when the content of the InputStream isn't compatible with resourceClass.
Returns:
an instance of resourceClass from the content of the InputStream.
Throws:
WebLabCheckedException - if a JAXBException or a ClassCastException occurred.

unmarshal

public <T extends Resource> T unmarshal(Reader reader,
                                        Class<T> resourceClass)
                             throws WebLabCheckedException
Type Parameters:
T - Class of the Resource to be unmarshaled
Parameters:
reader - Reader to be read. Note that you need to close the reader after using this method.
resourceClass - Class of the Resource to be unmarshaled. Using Resource will prevent from cast errors when the content of the Reader isn't compatible with resourceClass.
Returns:
an instance of resourceClass from the content of source.
Throws:
WebLabCheckedException - if a JAXBException or a ClassCastException occurred.


Copyright © 2012. All Rights Reserved.