|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.springframework.oxm.jaxb.Jaxb2Marshaller
public class Jaxb2Marshaller
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.
setContextPath(String)
,
setClassesToBeBound(Class[])
,
setJaxbContextProperties(Map)
,
setMarshallerProperties(Map)
,
setUnmarshallerProperties(Map)
,
setSchema(Resource)
,
setSchemas(Resource[])
,
setMarshallerListener(javax.xml.bind.Marshaller.Listener)
,
setUnmarshallerListener(javax.xml.bind.Unmarshaller.Listener)
,
setAdapters(XmlAdapter[])
Field Summary | |
---|---|
protected Log |
logger
Logger available to subclasses. |
Constructor Summary | |
---|---|
Jaxb2Marshaller()
|
Method Summary | |
---|---|
void |
afterPropertiesSet()
Invoked by a BeanFactory after it has set all bean properties supplied (and satisfied BeanFactoryAware and ApplicationContextAware). |
protected XmlMappingException |
convertJaxbException(JAXBException ex)
Convert the given JAXBException to an appropriate exception from the
org.springframework.oxm hierarchy. |
protected Marshaller |
createMarshaller()
Return a newly created JAXB marshaller. |
protected Unmarshaller |
createUnmarshaller()
Return a newly created JAXB unmarshaller. |
Class<?>[] |
getClassesToBeBound()
Return the list of Java classes to be recognized by a newly created JAXBContext. |
String |
getContextPath()
Return the JAXB context path. |
protected JAXBContext |
getJaxbContext()
|
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 be 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)
Specify the XmlAdapter s 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 |
setSchemaResourceResolver(LSResourceResolver schemaResourceResolver)
Sets the resource resolver, as used to load the schema resources. |
void |
setSchemas(Resource[] schemaResources)
Set the schema resources to use for validation. |
void |
setSupportJaxbElementClass(boolean supportJaxbElementClass)
Specify whether the supports(Class) returns true for the JAXBElement class. |
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 . |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected final Log logger
Constructor Detail |
---|
public Jaxb2Marshaller()
Method Detail |
---|
public void setContextPaths(String... contextPaths)
public void setContextPath(String contextPath)
public String getContextPath()
public void setClassesToBeBound(Class<?>... classesToBeBound)
"contextPath"
is required.
public Class<?>[] getClassesToBeBound()
public void setJaxbContextProperties(Map<String,?> jaxbContextProperties)
JAXBContext
properties. These implementation-specific
properties will be set on the underlying JAXBContext
.
public void setMarshallerProperties(Map<String,?> properties)
Marshaller
properties. These properties will be set on the
underlying JAXB Marshaller
, and allow for features such as indentation.
properties
- the propertiesMarshaller.setProperty(String,Object)
,
Marshaller.JAXB_ENCODING
,
Marshaller.JAXB_FORMATTED_OUTPUT
,
Marshaller.JAXB_NO_NAMESPACE_SCHEMA_LOCATION
,
Marshaller.JAXB_SCHEMA_LOCATION
public void setUnmarshallerProperties(Map<String,?> properties)
Unmarshaller
properties. These properties will be set on the
underlying JAXB Unmarshaller
.
properties
- the propertiesUnmarshaller.setProperty(String,Object)
public void setMarshallerListener(Marshaller.Listener marshallerListener)
Marshaller.Listener
to be registered with the JAXB Marshaller
.
public void setUnmarshallerListener(Unmarshaller.Listener unmarshallerListener)
Unmarshaller.Listener
to be registered with the JAXB Unmarshaller
.
public void setValidationEventHandler(ValidationEventHandler validationEventHandler)
public void setAdapters(XmlAdapter<?,?>[] adapters)
XmlAdapter
s to be registered with the JAXB Marshaller
and Unmarshaller
public void setSchema(Resource schemaResource)
public void setSchemas(Resource[] schemaResources)
public void setSchemaLanguage(String schemaLanguage)
http://www.w3.org/2001/XMLSchema"
.
XMLConstants.W3C_XML_SCHEMA_NS_URI
,
XMLConstants.RELAXNG_NS_URI
public void setSchemaResourceResolver(LSResourceResolver schemaResourceResolver)
SchemaFactory.setResourceResolver(org.w3c.dom.ls.LSResourceResolver)
,
setSchema(Resource)
,
setSchemas(Resource[])
public void setMtomEnabled(boolean mtomEnabled)
false
: marshalling using XOP/MTOM not being enabled.
public void setLazyInit(boolean lazyInit)
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 setSupportJaxbElementClass(boolean supportJaxbElementClass)
supports(Class)
returns true
for the JAXBElement
class.
Default is false
, meaning that supports(Class)
always returns false
for
JAXBElement
classes (though supports(Type)
can return true
, since it can obtain the
type parameters of JAXBElement
).
This property is typically enabled in combination with usage of classes like
MarshallingView
, since the ModelAndView
does not offer type parameter information at runtime.
supports(Class)
,
supports(Type)
public void setBeanClassLoader(ClassLoader classLoader)
BeanClassLoaderAware
class loader
to
a bean instance.
Invoked after the population of normal bean properties but
before an initialization callback such as
InitializingBean's
InitializingBean.afterPropertiesSet()
method or a custom init-method.
setBeanClassLoader
in interface BeanClassLoaderAware
classLoader
- the owning class loader; may be null
in
which case a default ClassLoader
must be used, for example
the ClassLoader
obtained via
ClassUtils.getDefaultClassLoader()
public final void afterPropertiesSet() throws Exception
InitializingBean
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.
afterPropertiesSet
in interface InitializingBean
Exception
- in the event of misconfiguration (such
as failure to set an essential property) or if initialization fails.protected JAXBContext getJaxbContext()
public boolean supports(Class<?> clazz)
Marshaller
supports
in interface Marshaller
supports
in interface Unmarshaller
clazz
- the class that this marshaller is being asked if it can marshal
true
if this marshaller can indeed marshal instances of the supplied class;
false
otherwisepublic boolean supports(Type genericType)
GenericMarshaller
supports
in interface GenericMarshaller
supports
in interface GenericUnmarshaller
genericType
- the type that this marshaller is being asked if it can marshal
true
if this marshaller can indeed marshal instances of the supplied type;
false
otherwisepublic void marshal(Object graph, Result result) throws XmlMappingException
Marshaller
Result
.
marshal
in interface Marshaller
graph
- the root of the object graph to marshalresult
- the result to marshal to
XmlMappingException
- if the given object cannot be marshalled to the resultpublic void marshal(Object graph, Result result, MimeContainer mimeContainer) throws XmlMappingException
MimeMarshaller
Result
,
writing binary data to a MimeContainer
.
marshal
in interface MimeMarshaller
graph
- the root of the object graph to marshalresult
- the result to marshal tomimeContainer
- the MIME container to write extracted binary content to
XmlMappingException
- if the given object cannot be marshalled to the resultprotected Marshaller createMarshaller()
protected void initJaxbMarshaller(Marshaller marshaller) throws JAXBException
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
.
JAXBException
public Object unmarshal(Source source) throws XmlMappingException
Unmarshaller
Source
into an object graph.
unmarshal
in interface Unmarshaller
source
- the source to marshal from
XmlMappingException
- if the given source cannot be mapped to an objectpublic Object unmarshal(Source source, MimeContainer mimeContainer) throws XmlMappingException
MimeUnmarshaller
Source
into an object graph,
reading binary attachments from a MimeContainer
.
unmarshal
in interface MimeUnmarshaller
source
- the source to marshal frommimeContainer
- the MIME container to read extracted binary content from
XmlMappingException
- if the given source cannot be mapped to an objectprotected Unmarshaller createUnmarshaller()
protected void initJaxbUnmarshaller(Unmarshaller unmarshaller) throws JAXBException
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
.
JAXBException
protected XmlMappingException convertJaxbException(JAXBException ex)
JAXBException
to an appropriate exception from the
org.springframework.oxm
hierarchy.
ex
- JAXBException
that occured
XmlMappingException
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |