public class

JibxMarshaller

extends AbstractMarshaller
implements InitializingBean
java.lang.Object
   ↳ org.springframework.oxm.support.AbstractMarshaller
     ↳ org.springframework.oxm.jibx.JibxMarshaller

Class Overview

Implementation of the Marshaller and Unmarshaller interfaces for JiBX.

The typical usage will be to set the targetClass and optionally the bindingName property on this bean.

See Also
  • org.jibx.runtime.IMarshallingContext
  • org.jibx.runtime.IUnmarshallingContext

Summary

[Expand]
Inherited Fields
From class org.springframework.oxm.support.AbstractMarshaller
Public Constructors
JibxMarshaller()
Public Methods
void afterPropertiesSet()
Invoked by a BeanFactory after it has set all bean properties supplied (and satisfied BeanFactoryAware and ApplicationContextAware).
XmlMappingException convertJibxException(JiBXException ex, boolean marshalling)
Convert the given JiBXException to an appropriate exception from the org.springframework.oxm hierarchy.
void setBindingName(String bindingName)
Set the optional binding name for this instance.
void setDocTypeInternalSubset(String docTypeInternalSubset)
Sets the internal subset Id for the DTD declaration written when marshalling.
void setDocTypePublicId(String docTypePublicId)
Sets the public Id for the DTD declaration written when marshalling.
void setDocTypeRootElementName(String docTypeRootElementName)
Sets the root element name for the DTD declaration written when marshalling.
void setDocTypeSystemId(String docTypeSystemId)
Sets the system Id for the DTD declaration written when marshalling.
void setEncoding(String encoding)
Set the document encoding using for marshalling.
void setIndent(int indent)
Set the number of nesting indent spaces.
void setStandalone(Boolean standalone)
Set the document standalone flag for marshalling.
void setTargetClass(Class<?> targetClass)
Set the target class for this instance.
boolean supports(Class<?> clazz)
Protected Methods
IMarshallingContext createMarshallingContext()
Create a new IMarshallingContext, configured with the correct indentation.
IUnmarshallingContext createUnmarshallingContext()
Create a new IUnmarshallingContext.
void marshalDomNode(Object graph, Node node)
Abstract template method for marshalling the given object graph to a DOM Node.
void marshalOutputStream(Object graph, OutputStream outputStream)
Abstract template method for marshalling the given object graph to a OutputStream.
void marshalSaxHandlers(Object graph, ContentHandler contentHandler, LexicalHandler lexicalHandler)
Abstract template method for marshalling the given object graph to a SAX ContentHandler.
void marshalWriter(Object graph, Writer writer)
Abstract template method for marshalling the given object graph to a Writer.
void marshalXmlEventWriter(Object graph, XMLEventWriter eventWriter)
Abstract template method for marshalling the given object to a StAX XMLEventWriter.
void marshalXmlStreamWriter(Object graph, XMLStreamWriter streamWriter)
Abstract template method for marshalling the given object to a StAX XMLStreamWriter.
Object unmarshalDomNode(Node node)
Abstract template method for unmarshalling from a given DOM Node.
Object unmarshalInputStream(InputStream inputStream)
Abstract template method for unmarshalling from a given InputStream.
Object unmarshalReader(Reader reader)
Abstract template method for unmarshalling from a given Reader.
Object unmarshalSaxReader(XMLReader xmlReader, InputSource inputSource)
Abstract template method for unmarshalling using a given SAX XMLReader and InputSource.
Object unmarshalXmlEventReader(XMLEventReader eventReader)
Abstract template method for unmarshalling from a given Stax XMLEventReader.
Object unmarshalXmlStreamReader(XMLStreamReader streamReader)
Abstract template method for unmarshalling from a given Stax XMLStreamReader.
[Expand]
Inherited Methods
From class org.springframework.oxm.support.AbstractMarshaller
From class java.lang.Object
From interface org.springframework.beans.factory.InitializingBean
From interface org.springframework.oxm.Marshaller
From interface org.springframework.oxm.Unmarshaller

Public Constructors

public JibxMarshaller ()

Public Methods

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

public XmlMappingException convertJibxException (JiBXException ex, boolean marshalling)

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

A boolean flag is used to indicate whether this exception occurs during marshalling or unmarshalling, since JiBX itself does not make this distinction in its exception hierarchy.

Parameters
ex JiBXException that occured
marshalling indicates whether the exception occurs during marshalling (true), or unmarshalling (false)
Returns
  • the corresponding XmlMappingException

public void setBindingName (String bindingName)

Set the optional binding name for this instance.

public void setDocTypeInternalSubset (String docTypeInternalSubset)

Sets the internal subset Id for the DTD declaration written when marshalling. By default, this is null. Only used when the root element also has been set.

public void setDocTypePublicId (String docTypePublicId)

Sets the public Id for the DTD declaration written when marshalling. By default, this is null. Only used when the root element also has been set. Set either this property or docTypeSystemId, not both.

public void setDocTypeRootElementName (String docTypeRootElementName)

Sets the root element name for the DTD declaration written when marshalling. By default, this is null (i.e. no DTD declaration is written). If set to a value, the system ID or public ID also need to be set.

public void setDocTypeSystemId (String docTypeSystemId)

Sets the system Id for the DTD declaration written when marshalling. By default, this is null. Only used when the root element also has been set. Set either this property or docTypePublicId, not both.

public void setEncoding (String encoding)

Set the document encoding using for marshalling. Default is UTF-8.

public void setIndent (int indent)

Set the number of nesting indent spaces. Default is -1, i.e. no indentation.

public void setStandalone (Boolean standalone)

Set the document standalone flag for marshalling. By default, this flag is not present.

public void setTargetClass (Class<?> targetClass)

Set the target class for this instance. This property is required.

public boolean supports (Class<?> clazz)

Protected Methods

protected IMarshallingContext createMarshallingContext ()

Create a new IMarshallingContext, configured with the correct indentation.

Returns
  • the created marshalling context
Throws
in case of errors
JiBXException

protected IUnmarshallingContext createUnmarshallingContext ()

Create a new IUnmarshallingContext.

Returns
  • the created unmarshalling context
Throws
in case of errors
JiBXException

protected void marshalDomNode (Object graph, Node node)

Abstract template method for marshalling the given object graph to a DOM Node.

In practice, node is be a Document node, a DocumentFragment node, or a Element node. In other words, a node that accepts children.

Parameters
graph the root of the object graph to marshal
node the DOM node that will contain the result tree

protected void marshalOutputStream (Object graph, OutputStream outputStream)

Abstract template method for marshalling the given object graph to a OutputStream.

Parameters
graph the root of the object graph to marshal
outputStream the OutputStream to write to

protected void marshalSaxHandlers (Object graph, ContentHandler contentHandler, LexicalHandler lexicalHandler)

Abstract template method for marshalling the given object graph to a SAX ContentHandler.

Parameters
graph the root of the object graph to marshal
contentHandler the SAX ContentHandler
lexicalHandler the SAX2 LexicalHandler. Can be null.

protected void marshalWriter (Object graph, Writer writer)

Abstract template method for marshalling the given object graph to a Writer.

Parameters
graph the root of the object graph to marshal
writer the Writer to write to

protected void marshalXmlEventWriter (Object graph, XMLEventWriter eventWriter)

Abstract template method for marshalling the given object to a StAX XMLEventWriter.

Parameters
graph the root of the object graph to marshal
eventWriter the XMLEventWriter to write to

protected void marshalXmlStreamWriter (Object graph, XMLStreamWriter streamWriter)

Abstract template method for marshalling the given object to a StAX XMLStreamWriter.

Parameters
graph the root of the object graph to marshal
streamWriter the XMLStreamWriter to write to

protected Object unmarshalDomNode (Node node)

Abstract template method for unmarshalling from a given DOM Node.

Parameters
node the DOM node that contains the objects to be unmarshalled
Returns
  • the object graph

protected Object unmarshalInputStream (InputStream inputStream)

Abstract template method for unmarshalling from a given InputStream.

Parameters
inputStream the InputStreamStream to read from
Returns
  • the object graph

protected Object unmarshalReader (Reader reader)

Abstract template method for unmarshalling from a given Reader.

Parameters
reader the Reader to read from
Returns
  • the object graph

protected Object unmarshalSaxReader (XMLReader xmlReader, InputSource inputSource)

Abstract template method for unmarshalling using a given SAX XMLReader and InputSource.

Parameters
xmlReader the SAX XMLReader to parse with
inputSource the input source to parse from
Returns
  • the object graph

protected Object unmarshalXmlEventReader (XMLEventReader eventReader)

Abstract template method for unmarshalling from a given Stax XMLEventReader.

Parameters
eventReader the XMLEventReader to read from
Returns
  • the object graph

protected Object unmarshalXmlStreamReader (XMLStreamReader streamReader)

Abstract template method for unmarshalling from a given Stax XMLStreamReader.

Parameters
streamReader the XMLStreamReader to read from
Returns
  • the object graph