TrueUpdate Core 0.1.7

net.java.trueupdate.core.codec
Class JaxbCodec

java.lang.Object
  extended by net.java.trueupdate.core.codec.JaxbCodec
All Implemented Interfaces:
Codec

@Immutable
public class JaxbCodec
extends Object
implements Codec

A codec which encodes/decodes objects to/from XML with a Marshaller/Unmarshaller derived from a JAXBContext.

This type of codec does not support encoding or decoding null.

Author:
Christian Schlichtherle (copied and edited from TrueLicense Core 2.3.1)

Field Summary
protected  JAXBContext context
          The JAXB context provided to the constructor.
 
Constructor Summary
JaxbCodec(JAXBContext context)
           
 
Method Summary
 String contentTransferEncoding()
          Returns an identifier for the content transfer encoding used by this codec.
 String contentType()
          Returns an identifier for the content type used by this codec.
<T> T
decode(Source source, Type expected)
          Decodes a nullable object graph from the given source.
 void encode(Sink sink, Object obj)
          Encodes a nullable object graph to the given sink.
protected  Marshaller marshaller()
          Returns a new marshaller.
protected  Unmarshaller unmarshaller()
          Returns a new unmarshaller.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

context

protected final JAXBContext context
The JAXB context provided to the constructor.

Constructor Detail

JaxbCodec

public JaxbCodec(JAXBContext context)
Method Detail

contentTransferEncoding

public String contentTransferEncoding()
Returns an identifier for the content transfer encoding used by this codec. The returned string must conform to the syntax specified in RFC2045 "Multipurpose Internet Mail Extensions (MIME) Part One: Format of Internet Message Bodies", Section 6.1 "Content-Transfer-Encoding Syntax", except that it must not start with "Content-Transfer-Encoding:" and optional spaces, i.e. the field name must be stripped.

If the Content-Transfer-Encoding equals (ignoring case) "8bit" and the Content-Type does not specify a charset parameter, then UTF-8 is assumed as the charset.

The implementation in the class JaxbCodec returns "8bit".

Specified by:
contentTransferEncoding in interface Codec
See Also:
RFC 3023

contentType

public String contentType()
Returns an identifier for the content type used by this codec. The returned string must conform to the syntax specified in RFC2045 "Multipurpose Internet Mail Extensions (MIME) Part One: Format of Internet Message Bodies", Section 5.1 "Syntax of the Content-Type Header Field", except that it must not start with "Content-Type:" and optional spaces, i.e. the field name is stripped.

The implementation in the class JaxbCodec returns "application/xml; charset=utf-8".

Specified by:
contentType in interface Codec
See Also:
RFC 3023

decode

public <T> T decode(Source source,
                    Type expected)
         throws Exception
Description copied from interface: Codec
Decodes a nullable object graph from the given source.

Specified by:
decode in interface Codec
Type Parameters:
T - the expected generic type of the decoded object.
Parameters:
source - the source from where to read the encoded object graph from.
expected - the expected generic type of the decoded object graph, e.g. String.class. This is just a hint and the implementation may ignore it.
Returns:
A duplicate of the original object graph. Its actual type may differ from the expected generic type. It may be null if and only if the original object graph was null.
Throws:
Exception

encode

public void encode(Sink sink,
                   Object obj)
            throws Exception
Description copied from interface: Codec
Encodes a nullable object graph to the given sink.

Specified by:
encode in interface Codec
Parameters:
sink - the sink to write the encoded object graph to.
obj - the nullable object graph. Implementations should support encoding null. If they do not support this, then this should be documented in the Javadoc.
Throws:
Exception

marshaller

protected Marshaller marshaller()
                         throws JAXBException
Returns a new marshaller.

Throws:
JAXBException

unmarshaller

protected Unmarshaller unmarshaller()
                             throws JAXBException
Returns a new unmarshaller.

Throws:
JAXBException

TrueUpdate Core 0.1.7

Copyright © 2013 Stimulus Software. All rights reserved.