Spring Web Services Framework

org.springframework.oxm.jaxb
Class AbstractJaxbMarshaller

java.lang.Object
  extended by org.springframework.oxm.jaxb.AbstractJaxbMarshaller
All Implemented Interfaces:
InitializingBean, Marshaller, Unmarshaller
Direct Known Subclasses:
Jaxb1Marshaller, Jaxb2Marshaller

public abstract class AbstractJaxbMarshaller
extends Object
implements Marshaller, Unmarshaller, InitializingBean

Abstract base class for implementations of the Marshaller and Unmarshaller interfaces that use JAXB. This base class is responsible for creating JAXB marshallers from a JAXBContext.

JAXB 2.0 added breaking API changes, so specific subclasses must be used for JAXB 1.0 and 2.0 (Jaxb1Marshaller and Jaxb2Marshaller respectivaly).

Since:
1.0.0
Author:
Arjen Poutsma
See Also:
Jaxb1Marshaller, Jaxb2Marshaller

Field Summary
protected  Log logger
          Logger available to subclasses.
 
Constructor Summary
AbstractJaxbMarshaller()
           
 
Method Summary
 void afterPropertiesSet()
           
protected  XmlMappingException convertJaxbException(JAXBException ex)
          Convert the given JAXBException to an appropriate exception from the org.springframework.oxm hierarchy.
protected abstract  JAXBContext createJaxbContext()
          Template method that returns a newly created JAXB context.
protected  Marshaller createMarshaller()
          Returns a newly created JAXB marshaller.
protected  Unmarshaller createUnmarshaller()
          Returns a newly created JAXB unmarshaller.
protected  String getContextPath()
          Returns the JAXB Context path.
 JAXBContext getJaxbContext()
          Returns the JAXBContext created in afterPropertiesSet().
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 setContextPath(String contextPath)
          Sets the JAXB Context path.
 void setContextPaths(String[] contextPaths)
          Sets multiple JAXB Context paths.
 void setMarshallerProperties(Map properties)
          Sets the JAXB Marshaller properties.
 void setUnmarshallerProperties(Map properties)
          Sets the JAXB Unmarshaller properties.
 void setValidationEventHandler(ValidationEventHandler validationEventHandler)
          Sets the JAXB validation event handler.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.springframework.oxm.Marshaller
marshal, supports
 
Methods inherited from interface org.springframework.oxm.Unmarshaller
supports, unmarshal
 

Field Detail

logger

protected final Log logger
Logger available to subclasses.

Constructor Detail

AbstractJaxbMarshaller

public AbstractJaxbMarshaller()
Method Detail

getContextPath

protected String getContextPath()
Returns the JAXB Context path.


setContextPath

public void setContextPath(String contextPath)
Sets the JAXB Context path.


setContextPaths

public void setContextPaths(String[] contextPaths)
Sets multiple JAXB Context paths. The given array of context paths is converted to a colon-delimited string, as supported by JAXB.


setMarshallerProperties

public void setMarshallerProperties(Map properties)
Sets 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
See Also:
Marshaller.setProperty(String,Object), Marshaller.JAXB_ENCODING, Marshaller.JAXB_FORMATTED_OUTPUT, Marshaller.JAXB_NO_NAMESPACE_SCHEMA_LOCATION, Marshaller.JAXB_SCHEMA_LOCATION

setUnmarshallerProperties

public void setUnmarshallerProperties(Map properties)
Sets the JAXB Unmarshaller properties. These properties will be set on the underlying JAXB Unmarshaller.

Parameters:
properties - the properties
See Also:
Unmarshaller.setProperty(String,Object)

setValidationEventHandler

public void setValidationEventHandler(ValidationEventHandler validationEventHandler)
Sets 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 API's.

Parameters:
validationEventHandler - the event handler

getJaxbContext

public JAXBContext getJaxbContext()
Returns the JAXBContext created in afterPropertiesSet().


afterPropertiesSet

public final void afterPropertiesSet()
                              throws Exception
Specified by:
afterPropertiesSet in interface InitializingBean
Throws:
Exception

convertJaxbException

protected XmlMappingException convertJaxbException(JAXBException ex)
Convert the given JAXBException to an appropriate exception from the org.springframework.oxm hierarchy.

The default implementation delegates to JaxbUtils. Can be overridden in subclasses.

Parameters:
ex - JAXBException that occured
Returns:
the corresponding XmlMappingException instance
See Also:
JaxbUtils.convertJaxbException(javax.xml.bind.JAXBException)

createMarshaller

protected Marshaller createMarshaller()
Returns a newly created JAXB marshaller. JAXB marshallers are not necessarily thread safe.


createUnmarshaller

protected Unmarshaller createUnmarshaller()
Returns a newly created JAXB unmarshaller. JAXB unmarshallers are not necessarily thread safe.


initJaxbMarshaller

protected void initJaxbMarshaller(Marshaller marshaller)
                           throws JAXBException
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.

Throws:
JAXBException

initJaxbUnmarshaller

protected void initJaxbUnmarshaller(Unmarshaller unmarshaller)
                             throws JAXBException
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.

Throws:
JAXBException

createJaxbContext

protected abstract JAXBContext createJaxbContext()
                                          throws Exception
Template method that returns a newly created JAXB context. Called from afterPropertiesSet().

Throws:
Exception

Spring Web Services Framework

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