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
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidconvertJibxException(JiBXException ex, boolean marshalling) Convert the givenJiBXExceptionto an appropriate exception from theorg.springframework.oxmhierarchy.protected IMarshallingContextCreate a newIMarshallingContext, configured with the correct indentation.protected IUnmarshallingContextCreate a newIUnmarshallingContext.protected Stringprotected voidmarshalDomNode(Object graph, Node node) protected voidmarshalOutputStream(Object graph, OutputStream outputStream) protected voidmarshalSaxHandlers(Object graph, ContentHandler contentHandler, LexicalHandler lexicalHandler) protected voidmarshalWriter(Object graph, Writer writer) protected voidmarshalXmlEventWriter(Object graph, XMLEventWriter eventWriter) protected voidmarshalXmlStreamWriter(Object graph, XMLStreamWriter streamWriter) voidsetBindingName(String bindingName) Set the optional binding name for this instance.voidsetDocTypeInternalSubset(String docTypeInternalSubset) Set the internal subset Id for the DTD declaration written when marshalling.voidsetDocTypePublicId(String docTypePublicId) Set the public id for the DTD declaration written when marshalling.voidsetDocTypeRootElementName(String docTypeRootElementName) Set the root element name for the DTD declaration written when marshalling.voidsetDocTypeSystemId(String docTypeSystemId) Set the system id for the DTD declaration written when marshalling.voidsetEncoding(String encoding) Set the document encoding using for marshalling.voidsetIndent(int indent) Set the number of nesting indent spaces.voidsetStandalone(Boolean standalone) Set the document standalone flag for marshalling.voidsetTargetClass(Class<?> targetClass) Set the target class for this instance.voidsetTargetPackage(String targetPackage) Set the target package for this instance.booleanprotected ObjectunmarshalDomNode(Node node) protected ObjectunmarshalInputStream(InputStream inputStream) protected ObjectunmarshalReader(Reader reader) protected ObjectunmarshalSaxReader(XMLReader xmlReader, InputSource inputSource) protected ObjectunmarshalXmlEventReader(XMLEventReader eventReader) protected ObjectunmarshalXmlStreamReader(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 thetargetPackageproperty is required.If this property is set,
targetPackageis ignored. -
setTargetPackage
Set the target package for this instance. Setting either this property or thetargetClassproperty is required.If
targetClassis 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:
getDefaultEncodingin 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:
afterPropertiesSetin interfaceInitializingBean- Throws:
JiBXException
-
supports
- Specified by:
supportsin interfaceMarshaller- Specified by:
supportsin interfaceUnmarshaller
-
marshalOutputStream
protected void marshalOutputStream(Object graph, OutputStream outputStream) throws XmlMappingException, IOException - Specified by:
marshalOutputStreamin classAbstractMarshaller- Throws:
XmlMappingExceptionIOException
-
marshalWriter
- Specified by:
marshalWriterin classAbstractMarshaller- Throws:
XmlMappingExceptionIOException
-
marshalDomNode
- Specified by:
marshalDomNodein classAbstractMarshaller- Throws:
XmlMappingException
-
marshalXmlEventWriter
- Specified by:
marshalXmlEventWriterin classAbstractMarshaller
-
marshalXmlStreamWriter
protected void marshalXmlStreamWriter(Object graph, XMLStreamWriter streamWriter) throws XmlMappingException - Specified by:
marshalXmlStreamWriterin classAbstractMarshaller- Throws:
XmlMappingException
-
marshalSaxHandlers
protected void marshalSaxHandlers(Object graph, ContentHandler contentHandler, @Nullable LexicalHandler lexicalHandler) throws XmlMappingException - Specified by:
marshalSaxHandlersin classAbstractMarshaller- Throws:
XmlMappingException
-
unmarshalXmlEventReader
- Specified by:
unmarshalXmlEventReaderin classAbstractMarshaller
-
unmarshalXmlStreamReader
- Specified by:
unmarshalXmlStreamReaderin classAbstractMarshaller
-
unmarshalInputStream
protected Object unmarshalInputStream(InputStream inputStream) throws XmlMappingException, IOException - Specified by:
unmarshalInputStreamin classAbstractMarshaller- Throws:
XmlMappingExceptionIOException
-
unmarshalReader
- Specified by:
unmarshalReaderin classAbstractMarshaller- Throws:
XmlMappingExceptionIOException
-
unmarshalDomNode
- Specified by:
unmarshalDomNodein classAbstractMarshaller- Throws:
XmlMappingException
-
unmarshalSaxReader
protected Object unmarshalSaxReader(XMLReader xmlReader, InputSource inputSource) throws XmlMappingException, IOException - Specified by:
unmarshalSaxReaderin classAbstractMarshaller- Throws:
XmlMappingExceptionIOException
-
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 givenJiBXExceptionto an appropriate exception from theorg.springframework.oxmhierarchy.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-JiBXExceptionthat occurredmarshalling- indicates whether the exception occurs during marshalling (true), or unmarshalling (false)- Returns:
- the corresponding
XmlMappingException
-