Package org.dellroad.stuff.jibx
Class JibxMarshaller
java.lang.Object
org.springframework.oxm.support.AbstractMarshaller
org.dellroad.stuff.jibx.JibxMarshaller
- All Implemented Interfaces:
InitializingBean
,Marshaller
,Unmarshaller
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.
NOTE: This is copied from Spring commit 3c8724ba3d0375e4a50354c15383972fee788e9c
which is the one that removed this class from Spring.
- Author:
- Arjen Poutsma
- See Also:
-
Field Summary
Fields inherited from class org.springframework.oxm.support.AbstractMarshaller
logger
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
convertJibxException
(JiBXException ex, boolean marshalling) Convert the givenJiBXException
to an appropriate exception from theorg.springframework.oxm
hierarchy.protected IMarshallingContext
Create a newIMarshallingContext
, configured with the correct indentation.protected IUnmarshallingContext
Create a newIUnmarshallingContext
.protected String
protected void
marshalDomNode
(Object graph, Node node) protected void
marshalOutputStream
(Object graph, OutputStream outputStream) protected void
marshalSaxHandlers
(Object graph, ContentHandler contentHandler, LexicalHandler lexicalHandler) protected void
marshalWriter
(Object graph, Writer writer) protected void
marshalXmlEventWriter
(Object graph, XMLEventWriter eventWriter) protected void
marshalXmlStreamWriter
(Object graph, XMLStreamWriter streamWriter) void
setBindingName
(String bindingName) Set the optional binding name for this instance.void
setDocTypeInternalSubset
(String docTypeInternalSubset) Set the internal subset Id for the DTD declaration written when marshalling.void
setDocTypePublicId
(String docTypePublicId) Set the public id for the DTD declaration written when marshalling.void
setDocTypeRootElementName
(String docTypeRootElementName) Set the root element name for the DTD declaration written when marshalling.void
setDocTypeSystemId
(String docTypeSystemId) Set 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.void
setTargetPackage
(String targetPackage) Set the target package for this instance.boolean
protected Object
unmarshalDomNode
(Node node) protected Object
unmarshalInputStream
(InputStream inputStream) protected Object
unmarshalReader
(Reader reader) protected Object
unmarshalSaxReader
(XMLReader xmlReader, InputSource inputSource) protected Object
unmarshalXmlEventReader
(XMLEventReader eventReader) protected Object
unmarshalXmlStreamReader
(XMLStreamReader streamReader) Methods inherited from class org.springframework.oxm.support.AbstractMarshaller
buildDocument, createDocumentBuilder, createDocumentBuilderFactory, createXmlReader, isProcessExternalEntities, isSupportDtd, marshal, marshalDomResult, marshalSaxResult, marshalStaxResult, marshalStreamResult, setProcessExternalEntities, setSupportDtd, unmarshal, unmarshalDomSource, unmarshalSaxSource, unmarshalStaxSource, unmarshalStreamSource
-
Constructor Details
-
JibxMarshaller
public JibxMarshaller()
-
-
Method Details
-
setTargetClass
Set the target class for this instance. Setting either this property or thetargetPackage
property is required.If this property is set,
targetPackage
is ignored. -
setTargetPackage
Set the target package for this instance. Setting either this property or thetargetClass
property is required.If
targetClass
is set, this property is ignored. -
setBindingName
Set the optional binding name for this instance. -
setIndent
public void setIndent(int indent) Set the number of nesting indent spaces. Default is-1
, i.e. no indentation. -
setEncoding
Set the document encoding using for marshalling. Default is UTF-8. -
getDefaultEncoding
- Overrides:
getDefaultEncoding
in classAbstractMarshaller
-
setStandalone
Set the document standalone flag for marshalling. By default, this flag is not present. -
setDocTypeRootElementName
Set the root element name for the DTD declaration written when marshalling. By default, this isnull
(i.e. no DTD declaration is written).If set to a value, the system ID or public ID also need to be set.
-
setDocTypeSystemId
Set the system id for the DTD declaration written when marshalling. By default, this isnull
. Only used when the root element also has been set.Set either this property or
docTypePublicId
, not both.- See Also:
-
setDocTypePublicId
Set the public id for the DTD declaration written when marshalling. By default, this isnull
. Only used when the root element also has been set.Set either this property or
docTypeSystemId
, not both.- See Also:
-
setDocTypeInternalSubset
Set the internal subset Id for the DTD declaration written when marshalling. By default, this isnull
. Only used when the root element also has been set.- See Also:
-
afterPropertiesSet
- Specified by:
afterPropertiesSet
in interfaceInitializingBean
- Throws:
JiBXException
-
supports
- Specified by:
supports
in interfaceMarshaller
- Specified by:
supports
in interfaceUnmarshaller
-
marshalOutputStream
protected void marshalOutputStream(Object graph, OutputStream outputStream) throws XmlMappingException, IOException - Specified by:
marshalOutputStream
in classAbstractMarshaller
- Throws:
XmlMappingException
IOException
-
marshalWriter
- Specified by:
marshalWriter
in classAbstractMarshaller
- Throws:
XmlMappingException
IOException
-
marshalDomNode
- Specified by:
marshalDomNode
in classAbstractMarshaller
- Throws:
XmlMappingException
-
marshalXmlEventWriter
- Specified by:
marshalXmlEventWriter
in classAbstractMarshaller
-
marshalXmlStreamWriter
protected void marshalXmlStreamWriter(Object graph, XMLStreamWriter streamWriter) throws XmlMappingException - Specified by:
marshalXmlStreamWriter
in classAbstractMarshaller
- Throws:
XmlMappingException
-
marshalSaxHandlers
protected void marshalSaxHandlers(Object graph, ContentHandler contentHandler, @Nullable LexicalHandler lexicalHandler) throws XmlMappingException - Specified by:
marshalSaxHandlers
in classAbstractMarshaller
- Throws:
XmlMappingException
-
unmarshalXmlEventReader
- Specified by:
unmarshalXmlEventReader
in classAbstractMarshaller
-
unmarshalXmlStreamReader
- Specified by:
unmarshalXmlStreamReader
in classAbstractMarshaller
-
unmarshalInputStream
protected Object unmarshalInputStream(InputStream inputStream) throws XmlMappingException, IOException - Specified by:
unmarshalInputStream
in classAbstractMarshaller
- Throws:
XmlMappingException
IOException
-
unmarshalReader
- Specified by:
unmarshalReader
in classAbstractMarshaller
- Throws:
XmlMappingException
IOException
-
unmarshalDomNode
- Specified by:
unmarshalDomNode
in classAbstractMarshaller
- Throws:
XmlMappingException
-
unmarshalSaxReader
protected Object unmarshalSaxReader(XMLReader xmlReader, InputSource inputSource) throws XmlMappingException, IOException - Specified by:
unmarshalSaxReader
in classAbstractMarshaller
- Throws:
XmlMappingException
IOException
-
createMarshallingContext
Create a newIMarshallingContext
, configured with the correct indentation.- Returns:
- the created marshalling context
- Throws:
JiBXException
- in case of errors
-
createUnmarshallingContext
Create a newIUnmarshallingContext
.- Returns:
- the created unmarshalling context
- Throws:
JiBXException
- in case of errors
-
convertJibxException
Convert the givenJiBXException
to an appropriate exception from theorg.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 occurredmarshalling
- indicates whether the exception occurs during marshalling (true
), or unmarshalling (false
)- Returns:
- the corresponding
XmlMappingException
-