java.lang.Object
   ↳ org.springframework.oxm.jaxb.Jaxb2Marshaller

Class Overview

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.

Summary

Fields
protected final Log logger Logger available to subclasses.
Public Constructors
Jaxb2Marshaller()
Public Methods
final void afterPropertiesSet()
Invoked by a BeanFactory after it has set all bean properties supplied (and satisfied BeanFactoryAware and ApplicationContextAware).
Class[]<?> getClassesToBeBound()
Return the list of Java classes to be recognized by a newly created JAXBContext.
String getContextPath()
Return the JAXB context path.
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)
Specify the XmlAdapters to be registered with the JAXB Marshaller and Unmarshaller
void setBeanClassLoader(ClassLoader classLoader)
Callback that supplies the bean class loader to a bean instance.
void setClassesToBeBound(Class...<?> classesToBeBound)
Set the list of Java classes to be recognized by a newly created JAXBContext.
void setContextPath(String contextPath)
Set a JAXB context path.
void setContextPaths(String... contextPaths)
Set multiple JAXB context paths.
void setJaxbContextProperties(Map<String, ?> jaxbContextProperties)
Set the JAXBContext properties.
void setLazyInit(boolean lazyInit)
Set whether to lazily initialize the JAXBContext for this marshaller.
void setMarshallerListener(Marshaller.Listener marshallerListener)
Specify the Marshaller.Listener to be registered with the JAXB Marshaller.
void setMarshallerProperties(Map<String, ?> properties)
Set the JAXB Marshaller properties.
void setMtomEnabled(boolean mtomEnabled)
Specify whether MTOM support should be enabled or not.
void setSchema(Resource schemaResource)
Set the schema resource to use for validation.
void setSchemaLanguage(String schemaLanguage)
Set the schema language.
void setSchemas(Resource[] schemaResources)
Set the schema resources to use for validation.
void setUnmarshallerListener(Unmarshaller.Listener unmarshallerListener)
Set the Unmarshaller.Listener to be registered with the JAXB Unmarshaller.
void setUnmarshallerProperties(Map<String, ?> properties)
Set the JAXB Unmarshaller properties.
void setValidationEventHandler(ValidationEventHandler validationEventHandler)
Set the JAXB validation event handler.
boolean supports(Class<?> clazz)
Indicates whether this marshaller can marshal instances of the supplied type.
boolean supports(Type genericType)
Indicates whether this marshaller can marshal instances of the supplied generic 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.
Protected Methods
XmlMappingException convertJaxbException(JAXBException ex)
Convert the given JAXBException to an appropriate exception from the org.springframework.oxm hierarchy.
Marshaller createMarshaller()
Return a newly created JAXB marshaller.
Unmarshaller createUnmarshaller()
Return a newly created JAXB unmarshaller.
synchronized JAXBContext getJaxbContext()
void initJaxbMarshaller(Marshaller marshaller)
Template method that can be overridden by concrete JAXB marshallers for custom initialization behavior.
void initJaxbUnmarshaller(Unmarshaller unmarshaller)
Template method that can be overridden by concrete JAXB marshallers for custom initialization behavior.
[Expand]
Inherited Methods
From class java.lang.Object
From interface org.springframework.beans.factory.BeanClassLoaderAware
From interface org.springframework.beans.factory.InitializingBean
From interface org.springframework.oxm.GenericMarshaller
From interface org.springframework.oxm.GenericUnmarshaller
From interface org.springframework.oxm.Marshaller
From interface org.springframework.oxm.Unmarshaller
From interface org.springframework.oxm.mime.MimeMarshaller
From interface org.springframework.oxm.mime.MimeUnmarshaller

Fields

protected final Log logger

Logger available to subclasses.

Public Constructors

public Jaxb2Marshaller ()

Public Methods

public final void afterPropertiesSet ()

Invoked by a BeanFactory after it has set all bean properties supplied (and satisfied BeanFactoryAware and ApplicationContextAware).

This method allows the bean instance to perform initialization only possible when all bean properties have been set and to throw an exception in the event of misconfiguration.

Throws
Exception

public Class[]<?> getClassesToBeBound ()

Return the list of Java classes to be recognized by a newly created JAXBContext.

public String getContextPath ()

Return the JAXB context path.

public void marshal (Object graph, Result result)

Marshals the object graph with the given root into the provided Result.

Parameters
graph the root of the object graph to marshal
result the result to marshal to

public 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.

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

public void setAdapters (XmlAdapter[]<?, ?> adapters)

Specify the XmlAdapters to be registered with the JAXB Marshaller and Unmarshaller

public void setBeanClassLoader (ClassLoader classLoader)

Callback that supplies the bean class loader to a bean instance.

Invoked after the population of normal bean properties but before an initialization callback such as InitializingBean's afterPropertiesSet() method or a custom init-method.

Parameters
classLoader the owning class loader; may be null in which case a default ClassLoader must be used, for example the ClassLoader obtained via getDefaultClassLoader()

public void setClassesToBeBound (Class...<?> classesToBeBound)

Set the list of Java classes to be recognized by a newly created JAXBContext. Setting this property or "contextPath" is required.

public void setContextPath (String contextPath)

Set a JAXB context path.

public void setContextPaths (String... contextPaths)

Set multiple JAXB context paths. The given array of context paths is converted to a colon-delimited string, as supported by JAXB.

public void setJaxbContextProperties (Map<String, ?> jaxbContextProperties)

Set the JAXBContext properties. These implementation-specific properties will be set on the underlying JAXBContext.

public void setLazyInit (boolean lazyInit)

Set whether to lazily initialize the JAXBContext for this marshaller. Default is false to initialize on startup; can be switched to true.

Early initialization just applies if afterPropertiesSet() is called.

public void setMarshallerListener (Marshaller.Listener marshallerListener)

Specify the Marshaller.Listener to be registered with the JAXB Marshaller.

public void setMarshallerProperties (Map<String, ?> properties)

Set the JAXB Marshaller properties. These properties will be set on the underlying JAXB Marshaller, and allow for features such as indentation.

Parameters
properties the properties

public void setMtomEnabled (boolean mtomEnabled)

Specify whether MTOM support should be enabled or not. Default is false: marshalling using XOP/MTOM not being enabled.

public void setSchema (Resource schemaResource)

Set the schema resource to use for validation.

public void setSchemaLanguage (String schemaLanguage)

Set the schema language. Default is the W3C XML Schema: http://www.w3.org/2001/XMLSchema".

public void setSchemas (Resource[] schemaResources)

Set the schema resources to use for validation.

public void setUnmarshallerListener (Unmarshaller.Listener unmarshallerListener)

Set the Unmarshaller.Listener to be registered with the JAXB Unmarshaller.

public void setUnmarshallerProperties (Map<String, ?> properties)

Set the JAXB Unmarshaller properties. These properties will be set on the underlying JAXB Unmarshaller.

Parameters
properties the properties

public void setValidationEventHandler (ValidationEventHandler validationEventHandler)

Set the JAXB validation event handler. This event handler will be called by JAXB if any validation errors are encountered during calls to any of the marshal APIs.

public boolean supports (Class<?> clazz)

Indicates whether this marshaller can marshal instances of the supplied type.

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

public boolean supports (Type genericType)

Indicates whether this marshaller can marshal instances of the supplied generic type.

Parameters
genericType 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

public Object unmarshal (Source source)

Unmarshals the given Source into an object graph.

Parameters
source the source to marshal from
Returns
  • the object graph

public Object unmarshal (Source source, MimeContainer mimeContainer)

Unmarshals the given provided Source into an object graph, reading binary attachments from a MimeContainer.

Parameters
source the source to marshal from
mimeContainer the MIME container to read extracted binary content from
Returns
  • the object graph

Protected Methods

protected XmlMappingException convertJaxbException (JAXBException ex)

Convert the given JAXBException to an appropriate exception from the org.springframework.oxm hierarchy.

Parameters
ex JAXBException that occured
Returns
  • the corresponding XmlMappingException

protected Marshaller createMarshaller ()

Return a newly created JAXB marshaller. JAXB marshallers are not necessarily thread safe.

protected Unmarshaller createUnmarshaller ()

Return a newly created JAXB unmarshaller. JAXB unmarshallers are not necessarily thread safe.

protected synchronized JAXBContext getJaxbContext ()

protected void initJaxbMarshaller (Marshaller marshaller)

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.

The default implementation sets the defined properties, the validation event handler, the schemas, listener, and adapters.

Throws
JAXBException

protected void initJaxbUnmarshaller (Unmarshaller unmarshaller)

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.

The default implementation sets the defined properties, the validation event handler, the schemas, listener, and adapters.

Throws
JAXBException