Spring Web Services Framework

org.springframework.oxm.jaxb
Class Jaxb2Marshaller

java.lang.Object
  extended by org.springframework.oxm.jaxb.AbstractJaxbMarshaller
      extended by org.springframework.oxm.jaxb.Jaxb2Marshaller
All Implemented Interfaces:
InitializingBean, GenericMarshaller, GenericUnmarshaller, Marshaller, MimeMarshaller, MimeUnmarshaller, Unmarshaller

public class Jaxb2Marshaller
extends AbstractJaxbMarshaller
implements MimeMarshaller, MimeUnmarshaller, GenericMarshaller, GenericUnmarshaller

Implementation of the Marshaller interface for JAXB 2.0.

The typical usage will be to set either the contextPath or the classesToBeBound property on this bean, possibly customize the marshaller and unmarshaller by setting properties, schemas, adapters, and listeners, and to refer to it.

Since:
1.0.0
Author:
Arjen Poutsma
See Also:
AbstractJaxbMarshaller.setContextPath(String), setClassesToBeBound(Class[]), setJaxbContextProperties(java.util.Map), AbstractJaxbMarshaller.setMarshallerProperties(java.util.Map), AbstractJaxbMarshaller.setUnmarshallerProperties(java.util.Map), setSchema(org.springframework.core.io.Resource), setSchemas(org.springframework.core.io.Resource[]), setMarshallerListener(javax.xml.bind.Marshaller.Listener), setUnmarshallerListener(javax.xml.bind.Unmarshaller.Listener), setAdapters(javax.xml.bind.annotation.adapters.XmlAdapter[])

Field Summary
 
Fields inherited from class org.springframework.oxm.jaxb.AbstractJaxbMarshaller
logger
 
Constructor Summary
Jaxb2Marshaller()
           
 
Method Summary
protected  JAXBContext createJaxbContext()
          Template method that returns a newly created JAXB context.
protected  void initJaxbMarshaller(Marshaller marshaller)
          Template method that can be overridden by concrete JAXB marshallers for custom initialization behavior.
protected  void initJaxbUnmarshaller(Unmarshaller unmarshaller)
          Template method that can overridden by concrete JAXB marshallers for custom initialization behavior.
 void marshal(Object graph, Result result)
          Marshals the object graph with the given root into the provided Result.
 void marshal(Object graph, Result result, MimeContainer mimeContainer)
          Marshals the object graph with the given root into the provided Result, writing binary data to a MimeContainer.
 void setAdapters(XmlAdapter[] adapters)
          Sets the XmlAdapters to be registered with the JAXB Marshaller and Unmarshaller
 void setClassesToBeBound(Class[] classesToBeBound)
          Sets the list of java classes to be recognized by a newly created JAXBContext.
 void setJaxbContextProperties(Map<String,?> jaxbContextProperties)
          Sets the JAXBContext properties.
 void setMarshallerListener(Marshaller.Listener marshallerListener)
          Sets the Marshaller.Listener to be registered with the JAXB Marshaller.
 void setMtomEnabled(boolean mtomEnabled)
          Indicates whether MTOM support should be enabled or not.
 void setSchema(Resource schemaResource)
          Sets the schema resource to use for validation.
 void setSchemaLanguage(String schemaLanguage)
          Sets the schema language.
 void setSchemas(Resource[] schemaResources)
          Sets the schema resources to use for validation.
 void setUnmarshallerListener(Unmarshaller.Listener unmarshallerListener)
          Sets the Unmarshaller.Listener to be registered with the JAXB Unmarshaller.
 boolean supports(Class clazz)
          Indicates whether this marshaller can marshal instances of the supplied type.
 boolean supports(Type type)
          Indicates whether this marshaller can marshal instances of the supplied type.
 Object unmarshal(Source source)
          Unmarshals the given Source into an object graph.
 Object unmarshal(Source source, MimeContainer mimeContainer)
          Unmarshals the given provided Source into an object graph, reading binary attachments from a MimeContainer.
 
Methods inherited from class org.springframework.oxm.jaxb.AbstractJaxbMarshaller
afterPropertiesSet, convertJaxbException, createMarshaller, createUnmarshaller, getContextPath, getJaxbContext, setContextPath, setContextPaths, setMarshallerProperties, setUnmarshallerProperties, setValidationEventHandler
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Jaxb2Marshaller

public Jaxb2Marshaller()
Method Detail

setAdapters

public void setAdapters(XmlAdapter[] adapters)
Sets the XmlAdapters to be registered with the JAXB Marshaller and Unmarshaller


setClassesToBeBound

public void setClassesToBeBound(Class[] classesToBeBound)
Sets the list of java classes to be recognized by a newly created JAXBContext. Setting this property or contextPath is required.

See Also:
AbstractJaxbMarshaller.setContextPath(String)

setJaxbContextProperties

public void setJaxbContextProperties(Map<String,?> jaxbContextProperties)
Sets the JAXBContext properties. These implementation-specific properties will be set on the JAXBContext.


setMarshallerListener

public void setMarshallerListener(Marshaller.Listener marshallerListener)
Sets the Marshaller.Listener to be registered with the JAXB Marshaller.


setMtomEnabled

public void setMtomEnabled(boolean mtomEnabled)
Indicates whether MTOM support should be enabled or not. Default is false, marshalling using XOP/MTOM is not enabled.


setSchemaLanguage

public void setSchemaLanguage(String schemaLanguage)
Sets the schema language. Default is the W3C XML Schema: http://www.w3.org/2001/XMLSchema".

See Also:
XMLConstants.W3C_XML_SCHEMA_NS_URI, XMLConstants.RELAXNG_NS_URI

setSchema

public void setSchema(Resource schemaResource)
Sets the schema resource to use for validation.


setSchemas

public void setSchemas(Resource[] schemaResources)
Sets the schema resources to use for validation.


setUnmarshallerListener

public void setUnmarshallerListener(Unmarshaller.Listener unmarshallerListener)
Sets the Unmarshaller.Listener to be registered with the JAXB Unmarshaller.


supports

public boolean supports(Type type)
Description copied from interface: GenericMarshaller
Indicates whether this marshaller can marshal instances of the supplied type.

Specified by:
supports in interface GenericMarshaller
Specified by:
supports in interface GenericUnmarshaller
Parameters:
type - the type that this marshaller is being asked if it can marshal
Returns:
true if this marshaller can indeed marshal instances of the supplied type; false otherwise

supports

public boolean supports(Class clazz)
Description copied from interface: Marshaller
Indicates whether this marshaller can marshal instances of the supplied type.

Specified by:
supports in interface Marshaller
Specified by:
supports in interface Unmarshaller
Parameters:
clazz - the class that this marshaller is being asked if it can marshal
Returns:
true if this marshaller can indeed marshal instances of the supplied class; false otherwise

createJaxbContext

protected JAXBContext createJaxbContext()
                                 throws Exception
Description copied from class: AbstractJaxbMarshaller
Template method that returns a newly created JAXB context. Called from afterPropertiesSet().

Specified by:
createJaxbContext in class AbstractJaxbMarshaller
Throws:
Exception

initJaxbMarshaller

protected void initJaxbMarshaller(Marshaller marshaller)
                           throws JAXBException
Description copied from class: AbstractJaxbMarshaller
Template method that can be overridden by concrete JAXB marshallers for custom initialization behavior. Gets called after creation of JAXB Marshaller, and after the respective properties have been set.

Default implementation does nothing.

Overrides:
initJaxbMarshaller in class AbstractJaxbMarshaller
Throws:
JAXBException

initJaxbUnmarshaller

protected void initJaxbUnmarshaller(Unmarshaller unmarshaller)
                             throws JAXBException
Description copied from class: AbstractJaxbMarshaller
Template method that can overridden by concrete JAXB marshallers for custom initialization behavior. Gets called after creation of JAXB Unmarshaller, and after the respective properties have been set.

Default implementation does nothing.

Overrides:
initJaxbUnmarshaller in class AbstractJaxbMarshaller
Throws:
JAXBException

marshal

public void marshal(Object graph,
                    Result result)
             throws XmlMappingException
Description copied from interface: Marshaller
Marshals the object graph with the given root into the provided Result.

Specified by:
marshal in interface Marshaller
Parameters:
graph - the root of the object graph to marshal
result - the result to marshal to
Throws:
XmlMappingException - if the given object cannot be marshalled to the result

marshal

public void marshal(Object graph,
                    Result result,
                    MimeContainer mimeContainer)
             throws XmlMappingException
Description copied from interface: MimeMarshaller
Marshals the object graph with the given root into the provided Result, writing binary data to a MimeContainer.

Specified by:
marshal in interface MimeMarshaller
Parameters:
graph - the root of the object graph to marshal
result - the result to marshal to
mimeContainer - the MIME container to write extracted binary content to
Throws:
XmlMappingException - if the given object cannot be marshalled to the result

unmarshal

public Object unmarshal(Source source)
                 throws XmlMappingException
Description copied from interface: Unmarshaller
Unmarshals the given Source into an object graph.

Specified by:
unmarshal in interface Unmarshaller
Parameters:
source - the source to marshal from
Returns:
the object graph
Throws:
XmlMappingException - if the given source cannot be mapped to an object

unmarshal

public Object unmarshal(Source source,
                        MimeContainer mimeContainer)
                 throws XmlMappingException
Description copied from interface: MimeUnmarshaller
Unmarshals the given provided Source into an object graph, reading binary attachments from a MimeContainer.

Specified by:
unmarshal in interface MimeUnmarshaller
Parameters:
source - the source to marshal from
mimeContainer - the MIME container to read extracted binary content from
Returns:
the object graph
Throws:
XmlMappingException - if the given source cannot be mapped to an object

Spring Web Services Framework

Copyright 2005-2008 The Spring Web Services Framework. All Rights Reserved.