|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.springframework.oxm.AbstractMarshaller
org.springframework.oxm.castor.CastorMarshaller
public class CastorMarshaller
Implementation of the Marshaller interface for Castor. By default, Castor does not require any further
configuration, though setting a target class or providing a mapping file can be used to have more control over the
behavior of Castor.
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 Castor's API, it is required to set the encoding used for writing to output streams. It defaults to
UTF-8.
setEncoding(String),
setTargetClass(Class),
setMappingLocation(org.springframework.core.io.Resource),
setMappingLocations(org.springframework.core.io.Resource[])| Field Summary | |
|---|---|
static java.lang.String |
DEFAULT_ENCODING
The default encoding used for stream access. |
| Fields inherited from class org.springframework.oxm.AbstractMarshaller |
|---|
logger |
| Constructor Summary | |
|---|---|
CastorMarshaller()
|
|
| Method Summary | |
|---|---|
void |
afterPropertiesSet()
|
XmlMappingException |
convertCastorException(org.exolab.castor.xml.XMLException ex,
boolean marshalling)
Converts the given CastorException to an appropriate exception from the
org.springframework.oxm hierarchy. |
protected org.exolab.castor.xml.XMLContext |
createXMLContext(org.springframework.core.io.Resource[] mappingLocations,
java.lang.Class targetClass)
Creates the Castor XMLContext. |
protected void |
customizeMarshaller(org.exolab.castor.xml.Marshaller marshaller)
Template method that allows for customizing of the given Castor Marshaller. |
protected void |
customizeUnmarshaller(org.exolab.castor.xml.Unmarshaller unmarshaller)
Template method that allows for customizing of the given Castor Unmarshaller. |
boolean |
getIgnoreExtraAttributes()
Returns whether the Castor Unmarshaller should ignore attributes that do not match a specific field. |
boolean |
getIgnoreExtraElements()
Returns whether the Castor Unmarshaller should ignore elements that do not match a specific field. |
java.util.Properties |
getNamespaceMappings()
Returns the namespace mappings. |
boolean |
getWhitespacePreserve()
Returns whether the Castor Unmarshaller should preserve "ignorable" whitespace. |
boolean |
isSuppressNamespaces()
Returns whether this marshaller should output namespaces. |
boolean |
isSuppressXsiType()
Sets whether this marshaller should output the xsi:type attribute. |
boolean |
isValidating()
Returns whether this marshaller should validate in- and outgoing documents. |
protected void |
marshalDomNode(java.lang.Object graph,
org.w3c.dom.Node node)
Abstract template method for marshalling the given object graph to a DOM Node. |
protected void |
marshalOutputStream(java.lang.Object graph,
java.io.OutputStream outputStream)
Abstract template method for marshalling the given object graph to a OutputStream. |
protected void |
marshalSaxHandlers(java.lang.Object graph,
org.xml.sax.ContentHandler contentHandler,
org.xml.sax.ext.LexicalHandler lexicalHandler)
Abstract template method for marshalling the given object graph to a SAX ContentHandler. |
protected void |
marshalWriter(java.lang.Object graph,
java.io.Writer writer)
Abstract template method for marshalling the given object graph to a Writer. |
protected void |
marshalXmlEventWriter(java.lang.Object graph,
javax.xml.stream.XMLEventWriter eventWriter)
Abstract template method for marshalling the given object to a StAX XMLEventWriter. |
protected void |
marshalXmlStreamWriter(java.lang.Object graph,
javax.xml.stream.XMLStreamWriter streamWriter)
Abstract template method for marshalling the given object to a StAX XMLStreamWriter. |
void |
setEncoding(java.lang.String encoding)
Sets the encoding to be used for stream access. |
void |
setIgnoreExtraAttributes(boolean ignoreExtraAttributes)
Sets whether the Castor Unmarshaller should ignore attributes that do not match a specific field. |
void |
setIgnoreExtraElements(boolean ignoreExtraElements)
Sets whether the Castor Unmarshaller should ignore elements that do not match a specific field. |
void |
setMappingLocation(org.springframework.core.io.Resource mappingLocation)
Sets the locations of the Castor XML Mapping files. |
void |
setMappingLocations(org.springframework.core.io.Resource[] mappingLocations)
Sets the locations of the Castor XML Mapping files. |
void |
setNamespaceMappings(java.util.Properties namespaceMappings)
Sets the namespace mappings. |
void |
setSuppressNamespaces(boolean suppressNamespaces)
Sets whether this marshaller should output namespaces. |
void |
setSuppressXsiType(boolean suppressXsiType)
Sets whether this marshaller should output the xsi:type attribute. |
void |
setTargetClass(java.lang.Class targetClass)
Sets the Castor target class. |
void |
setValidating(boolean validating)
Sets whether this marshaller should validate in- and outgoing documents. |
void |
setWhitespacePreserve(boolean whitespacePreserve)
Sets whether the Castor Unmarshaller should preserve "ignorable" whitespace. |
boolean |
supports(java.lang.Class clazz)
Returns true for all classes, i.e. |
protected java.lang.Object |
unmarshalDomNode(org.w3c.dom.Node node)
Abstract template method for unmarshalling from a given DOM Node. |
protected java.lang.Object |
unmarshalInputStream(java.io.InputStream inputStream)
Abstract template method for unmarshalling from a given InputStream. |
protected java.lang.Object |
unmarshalReader(java.io.Reader reader)
Abstract template method for unmarshalling from a given Reader. |
protected java.lang.Object |
unmarshalSaxReader(org.xml.sax.XMLReader xmlReader,
org.xml.sax.InputSource inputSource)
Abstract template method for unmarshalling using a given SAX XMLReader and
InputSource. |
protected java.lang.Object |
unmarshalXmlEventReader(javax.xml.stream.XMLEventReader eventReader)
Abstract template method for unmarshalling from a given Stax XMLEventReader. |
protected java.lang.Object |
unmarshalXmlStreamReader(javax.xml.stream.XMLStreamReader streamReader)
Abstract template method for unmarshalling from a given Stax XMLStreamReader. |
| Methods inherited from class org.springframework.oxm.AbstractMarshaller |
|---|
createDocumentBuilder, createDocumentBuilderFactory, createXmlReader, marshal, marshalDomResult, marshalSaxResult, marshalStaxResult, marshalStreamResult, unmarshal, unmarshalDomSource, unmarshalSaxSource, unmarshalStaxSource, unmarshalStreamSource |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final java.lang.String DEFAULT_ENCODING
| Constructor Detail |
|---|
public CastorMarshaller()
| Method Detail |
|---|
public boolean getIgnoreExtraAttributes()
Unmarshaller should ignore attributes that do not match a specific field.
public void setIgnoreExtraAttributes(boolean ignoreExtraAttributes)
Unmarshaller should ignore attributes that do not match a specific field.
Default is true: extra attributes are ignored.
Unmarshaller.setIgnoreExtraAttributes(boolean)public boolean getIgnoreExtraElements()
Unmarshaller should ignore elements that do not match a specific field.
public void setIgnoreExtraElements(boolean ignoreExtraElements)
Unmarshaller should ignore elements that do not match a specific field. Default
is false, extra attributes are flagged as an error.
Unmarshaller.setIgnoreExtraElements(boolean)public boolean getWhitespacePreserve()
Unmarshaller should preserve "ignorable" whitespace.
public void setWhitespacePreserve(boolean whitespacePreserve)
Unmarshaller should preserve "ignorable" whitespace. Default is
false.
Unmarshaller.setWhitespacePreserve(boolean)public boolean isValidating()
public void setValidating(boolean validating)
false.
Marshaller.setValidation(boolean)public java.util.Properties getNamespaceMappings()
public void setNamespaceMappings(java.util.Properties namespaceMappings)
Marshaller.setNamespaceMapping(String, String)public void setEncoding(java.lang.String encoding)
DEFAULT_ENCODINGpublic void setMappingLocation(org.springframework.core.io.Resource mappingLocation)
public void setMappingLocations(org.springframework.core.io.Resource[] mappingLocations)
public boolean isSuppressNamespaces()
public void setSuppressNamespaces(boolean suppressNamespaces)
false, i.e. namespaces are
written.
Marshaller.setSuppressNamespaces(boolean)public boolean isSuppressXsiType()
public void setSuppressXsiType(boolean suppressXsiType)
xsi:type attribute. The default is false, i.e. the
xsi:type is written.
Marshaller.setSuppressXSIType(boolean)public void setTargetClass(java.lang.Class targetClass)
CastorMarshaller is tied to this one
specific class. Use a mapping file for unmarshalling multiple classes.
public final void afterPropertiesSet()
throws java.io.IOException
afterPropertiesSet in interface org.springframework.beans.factory.InitializingBeanjava.io.IOExceptionpublic boolean supports(java.lang.Class clazz)
true for all classes, i.e. Castor supports arbitrary classes.
supports in interface Marshallersupports in interface Unmarshallerclazz - 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 otherwise
protected org.exolab.castor.xml.XMLContext createXMLContext(org.springframework.core.io.Resource[] mappingLocations,
java.lang.Class targetClass)
throws org.exolab.castor.mapping.MappingException,
java.io.IOException,
org.exolab.castor.xml.ResolverException
XMLContext. Subclasses can override this to create a custom context.
The default implementation loads mapping files if defined, and the target class if not defined.
org.exolab.castor.mapping.MappingException - when the mapping file cannot be loaded
java.io.IOException - in case of I/O errors
org.exolab.castor.xml.ResolverExceptionXMLContext.addMapping(org.exolab.castor.mapping.Mapping),
XMLContext.addClass(Class)
protected final void marshalDomNode(java.lang.Object graph,
org.w3c.dom.Node node)
throws XmlMappingException
AbstractMarshallerNode.
In practice, node is be a Document node, a DocumentFragment node, or a
Element node. In other words, a node that accepts children.
marshalDomNode in class AbstractMarshallergraph - the root of the object graph to marshalnode - The DOM node that will contain the result tree
XmlMappingException - if the given object cannot be marshalled to the DOM nodeDocument,
DocumentFragment,
Element
protected final void marshalSaxHandlers(java.lang.Object graph,
org.xml.sax.ContentHandler contentHandler,
org.xml.sax.ext.LexicalHandler lexicalHandler)
throws XmlMappingException
AbstractMarshallerContentHandler.
marshalSaxHandlers in class AbstractMarshallergraph - the root of the object graph to marshalcontentHandler - the SAX ContentHandlerlexicalHandler - the SAX2 LexicalHandler. Can be null.
XmlMappingException - if the given object cannot be marshalled to the handlers
protected final void marshalOutputStream(java.lang.Object graph,
java.io.OutputStream outputStream)
throws XmlMappingException,
java.io.IOException
AbstractMarshallerOutputStream.
marshalOutputStream in class AbstractMarshallergraph - the root of the object graph to marshaloutputStream - the OutputStream to write to
XmlMappingException - if the given object cannot be marshalled to the writer
java.io.IOException - if an I/O exception occurs
protected final void marshalWriter(java.lang.Object graph,
java.io.Writer writer)
throws XmlMappingException,
java.io.IOException
AbstractMarshallerWriter.
marshalWriter in class AbstractMarshallergraph - the root of the object graph to marshalwriter - the Writer to write to
XmlMappingException - if the given object cannot be marshalled to the writer
java.io.IOException - if an I/O exception occurs
protected final void marshalXmlEventWriter(java.lang.Object graph,
javax.xml.stream.XMLEventWriter eventWriter)
throws XmlMappingException
AbstractMarshallerXMLEventWriter.
marshalXmlEventWriter in class AbstractMarshallergraph - the root of the object graph to marshaleventWriter - the XMLEventWriter to write to
XmlMappingException - if the given object cannot be marshalled to the DOM node
protected final void marshalXmlStreamWriter(java.lang.Object graph,
javax.xml.stream.XMLStreamWriter streamWriter)
throws XmlMappingException
AbstractMarshallerXMLStreamWriter.
marshalXmlStreamWriter in class AbstractMarshallergraph - the root of the object graph to marshalstreamWriter - the XMLStreamWriter to write to
XmlMappingException - if the given object cannot be marshalled to the DOM nodeprotected void customizeMarshaller(org.exolab.castor.xml.Marshaller marshaller)
Marshaller.
Default implementation invokes Marshaller.setValidation(boolean) with the property set on this
marshaller, and calls Marshaller.setNamespaceMapping(String, String) with the namespace mappings.
protected final java.lang.Object unmarshalDomNode(org.w3c.dom.Node node)
throws XmlMappingException
AbstractMarshallerNode.
unmarshalDomNode in class AbstractMarshallernode - The DOM node that contains the objects to be unmarshalled
XmlMappingException - if the given DOM node cannot be mapped to an object
protected final java.lang.Object unmarshalInputStream(java.io.InputStream inputStream)
throws XmlMappingException,
java.io.IOException
AbstractMarshallerInputStream.
unmarshalInputStream in class AbstractMarshallerinputStream - the InputStreamStream to read from
XmlMappingException - if the given stream cannot be converted to an object
java.io.IOException - if an I/O exception occurs
protected final java.lang.Object unmarshalReader(java.io.Reader reader)
throws XmlMappingException,
java.io.IOException
AbstractMarshallerReader.
unmarshalReader in class AbstractMarshallerreader - the Reader to read from
XmlMappingException - if the given reader cannot be converted to an object
java.io.IOException - if an I/O exception occursprotected final java.lang.Object unmarshalXmlEventReader(javax.xml.stream.XMLEventReader eventReader)
AbstractMarshallerXMLEventReader.
unmarshalXmlEventReader in class AbstractMarshallereventReader - The XMLEventReader to read from
protected final java.lang.Object unmarshalSaxReader(org.xml.sax.XMLReader xmlReader,
org.xml.sax.InputSource inputSource)
throws XmlMappingException,
java.io.IOException
AbstractMarshallerXMLReader and
InputSource.
unmarshalSaxReader in class AbstractMarshallerxmlReader - the SAX XMLReader to parse withinputSource - the input source to parse from
XmlMappingException - if the given reader and input source cannot be converted to an object
java.io.IOException - if an I/O exception occursprotected final java.lang.Object unmarshalXmlStreamReader(javax.xml.stream.XMLStreamReader streamReader)
AbstractMarshallerXMLStreamReader.
unmarshalXmlStreamReader in class AbstractMarshallerstreamReader - The XMLStreamReader to read from
protected void customizeUnmarshaller(org.exolab.castor.xml.Unmarshaller unmarshaller)
Unmarshaller.
Default implementation invokes Unmarshaller.setValidation(boolean), Unmarshaller.setWhitespacePreserve(boolean), Unmarshaller.setIgnoreExtraAttributes(boolean), and Unmarshaller.setIgnoreExtraElements(boolean) with the properties set on this marshaller.
public XmlMappingException convertCastorException(org.exolab.castor.xml.XMLException ex,
boolean marshalling)
CastorException to an appropriate exception from the
org.springframework.oxm hierarchy.
The default implementation delegates to CastorUtils. Can be overridden in subclasses.
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 occuredmarshalling - indicates whether the exception occurs during marshalling (true), or
unmarshalling (false)
XmlMappingExceptionCastorUtils.convertXmlException(org.exolab.castor.xml.XMLException, boolean)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||