java.lang.Object | ||
↳ | org.springframework.oxm.support.AbstractMarshaller | |
↳ | org.springframework.oxm.castor.CastorMarshaller |
Implementation of the Marshaller
interface for Castor. By default, Castor does not require any further
configuration, though setting target classes, target packages or providing a mapping file can be used to have more control over the
behavior of Castor.
If a target class is specified using setTargetClass
, the CastorMarshaller
can only be
used to unmarshall XML that represents that specific class. If you want to unmarshall multiple classes, you have to
provide a mapping file using setMappingLocations
.
Due to limitations of Castor's API, it is required to set the encoding used for writing to output streams. It
defaults to UTF-8
.
Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
String | DEFAULT_ENCODING | The default encoding used for stream access: UTF-8. |
[Expand]
Inherited Fields | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
org.springframework.oxm.support.AbstractMarshaller
|
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Invoked by a BeanFactory after it has set all bean properties supplied
(and satisfied BeanFactoryAware and ApplicationContextAware).
| |||||||||||
Returns whether this marshaller should output namespaces.
| |||||||||||
Sets whether this marshaller should output the xsi:type attribute.
| |||||||||||
Set the encoding to be used for stream access.
| |||||||||||
Set whether the Castor Unmarshaller should ignore attributes that do not match a specific field.
| |||||||||||
Set whether the Castor Unmarshaller should ignore elements that do not match a specific field.
| |||||||||||
Set the locations of the Castor XML Mapping files.
| |||||||||||
Set the locations of the Castor XML Mapping files.
| |||||||||||
Set the namespace mappings.
| |||||||||||
Sets whether this marshaller should output namespaces.
| |||||||||||
Sets whether this marshaller should output the
xsi:type attribute. | |||||||||||
Set the Castor target class.
| |||||||||||
Set the Castor target classes.
| |||||||||||
Set the package names of packages with the Castor descriptor classes.
| |||||||||||
Set whether this marshaller should validate in- and outgoing documents.
| |||||||||||
Set whether the Castor Unmarshaller should preserve "ignorable" whitespace.
| |||||||||||
Returns
true for all classes, i.e. |
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Convert the given
XMLException to an appropriate exception
from the org.springframework.oxm hierarchy. | |||||||||||
Create the Castor
XMLContext . | |||||||||||
Template method that allows for customizing of the given Castor Marshaller.
| |||||||||||
Template method that allows for customizing of the given Castor
Unmarshaller.
| |||||||||||
Abstract template method for marshalling the given object graph to a DOM
Node . | |||||||||||
Abstract template method for marshalling the given object graph to a
OutputStream . | |||||||||||
Abstract template method for marshalling the given object graph to a SAX
ContentHandler . | |||||||||||
Abstract template method for marshalling the given object graph to a
Writer . | |||||||||||
Abstract template method for marshalling the given object to a StAX
XMLEventWriter . | |||||||||||
Abstract template method for marshalling the given object to a StAX
XMLStreamWriter . | |||||||||||
Abstract template method for unmarshalling from a given DOM
Node . | |||||||||||
Abstract template method for unmarshalling from a given
InputStream . | |||||||||||
Abstract template method for unmarshalling from a given
Reader . | |||||||||||
Abstract template method for unmarshalling using a given SAX
XMLReader
and InputSource . | |||||||||||
Abstract template method for unmarshalling from a given Stax
XMLEventReader . | |||||||||||
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
|
The default encoding used for stream access: UTF-8.
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.
Returns whether this marshaller should output namespaces.
Sets whether this marshaller should output the xsi:type attribute.
Set whether the Castor Unmarshaller should ignore attributes that do not match a specific field.
Default is true
: extra attributes are ignored.
Set whether the Castor Unmarshaller should ignore elements that do not match a specific field.
Default is false
, extra attributes are flagged as an error.
Set the locations of the Castor XML Mapping files.
Set the locations of the Castor XML Mapping files.
Set the namespace mappings. Property names are interpreted as namespace prefixes; values are namespace URIs.
Sets whether this marshaller should output namespaces. The default is false
, i.e. namespaces are
written.
Sets whether this marshaller should output the xsi:type
attribute. The default is false
, i.e. the
xsi:type
is written.
Set the Castor target class. Alternative means of configuring
CastorMarshaller
for unmarshalling multiple classes include
use of mapping files, and specifying packages with Castor descriptor classes.
Set the Castor target classes. Alternative means of configuring
CastorMarshaller
for unmarshalling multiple classes include
use of mapping files, and specifying packages with Castor descriptor classes.
Set the package names of packages with the Castor descriptor classes.
Set whether this marshaller should validate in- and outgoing documents.
Default is false
.
Set whether the Castor Unmarshaller should preserve "ignorable" whitespace.
Default is false
.
Returns true
for all classes, i.e. Castor supports arbitrary classes.
Convert the given XMLException
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 Castor itself does not make this distinction in its exception hierarchy.
ex | Castor XMLException that occured |
---|---|
marshalling | indicates whether the exception occurs during
marshalling (true ), or unmarshalling (false ) |
XmlMappingException
Create the Castor XMLContext
. Subclasses can override this to create a custom context.
The default implementation loads mapping files if defined, or the target class or packages if defined.
when the mapping file cannot be loaded | |
IOException | in case of I/O errors |
MappingException | |
ResolverException |
Template method that allows for customizing of the given Castor Marshaller.
The default implementation invokes Marshaller#setValidation(boolean)
with the property set on this marshaller, and calls Marshaller#setNamespaceMapping(String, String)
with the namespace mappings
.
Template method that allows for customizing of the given Castor Unmarshaller.
The default implementation invokes Unmarshaller#setValidation(boolean), Unmarshaller#setWhitespacePreserve(boolean), Unmarshaller#setIgnoreExtraAttributes(boolean), and Unmarshaller#setIgnoreExtraElements(boolean) with the properties set on this marshaller.
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.
graph | the root of the object graph to marshal |
---|---|
node | the DOM node that will contain the result tree |
XmlMappingException |
---|
Abstract template method for marshalling the given object graph to a OutputStream
.
graph | the root of the object graph to marshal |
---|---|
outputStream | the OutputStream to write to |
IOException | |
---|---|
XmlMappingException |
Abstract template method for marshalling the given object graph to a SAX ContentHandler
.
graph | the root of the object graph to marshal |
---|---|
contentHandler | the SAX ContentHandler |
lexicalHandler | the SAX2 LexicalHandler . Can be null . |
XmlMappingException |
---|
Abstract template method for marshalling the given object graph to a Writer
.
graph | the root of the object graph to marshal |
---|---|
writer | the Writer to write to |
IOException | |
---|---|
XmlMappingException |
Abstract template method for marshalling the given object to a StAX XMLEventWriter
.
graph | the root of the object graph to marshal |
---|---|
eventWriter | the XMLEventWriter to write to |
XmlMappingException |
---|
Abstract template method for marshalling the given object to a StAX XMLStreamWriter
.
graph | the root of the object graph to marshal |
---|---|
streamWriter | the XMLStreamWriter to write to |
XmlMappingException |
---|
Abstract template method for unmarshalling from a given DOM Node
.
node | the DOM node that contains the objects to be unmarshalled |
---|
XmlMappingException |
---|
Abstract template method for unmarshalling from a given InputStream
.
inputStream | the InputStreamStream to read from |
---|
IOException | |
---|---|
XmlMappingException |
Abstract template method for unmarshalling from a given Reader
.
reader | the Reader to read from |
---|
IOException | |
---|---|
XmlMappingException |
Abstract template method for unmarshalling using a given SAX XMLReader
and InputSource
.
xmlReader | the SAX XMLReader to parse with |
---|---|
inputSource | the input source to parse from |
IOException | |
---|---|
XmlMappingException |
Abstract template method for unmarshalling from a given Stax XMLEventReader
.
eventReader | the XMLEventReader to read from |
---|
Abstract template method for unmarshalling from a given Stax XMLStreamReader
.
streamReader | the XMLStreamReader to read from |
---|