|
Spring Web Services Framework | |||||||||
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.xstream.XStreamMarshaller
public class XStreamMarshaller
Implementation of the Marshaller
interface for XStream. By default, XStream does not require any further
configuration, though class aliases can be used to have more control over the behavior of XStream.
UTF-8
.
Note that XStream is an XML serialization library, not a data binding library. Therefore, it has limited
namespace support. As such, it is rather unsuitable for usage within Web services.
setEncoding(String)
,
DEFAULT_ENCODING
,
setAliases(Map)
,
setConverters(ConverterMatcher[])
Field Summary | |
---|---|
static String |
DEFAULT_ENCODING
The default encoding used for stream access. |
Fields inherited from class org.springframework.oxm.AbstractMarshaller |
---|
logger |
Constructor Summary | |
---|---|
XStreamMarshaller()
|
Method Summary | |
---|---|
void |
addAlias(String name,
Class type)
Adds an alias for the given type. |
void |
addImplicitCollection(String name,
Class type)
Adds an implicit Collection for the given type. |
void |
addOmittedField(Class type,
String fieldName)
Adds an omitted field for the given type. |
XmlMappingException |
convertXStreamException(Exception ex,
boolean marshalling)
Convert the given XStream exception to an appropriate exception from the org.springframework.oxm
hierarchy. |
String |
getEncoding()
Returns the encoding to be used for stream access. |
com.thoughtworks.xstream.XStream |
getXStream()
Returns the XStream instance used by this marshaller. |
protected void |
marshalDomNode(Object graph,
Node node)
Abstract template method for marshalling the given object graph to a DOM Node . |
protected void |
marshalOutputStream(Object graph,
OutputStream outputStream)
Abstract template method for marshalling the given object graph to a OutputStream . |
protected void |
marshalSaxHandlers(Object graph,
ContentHandler contentHandler,
LexicalHandler lexicalHandler)
Abstract template method for marshalling the given object graph to a SAX ContentHandler . |
protected void |
marshalWriter(Object graph,
Writer writer)
Abstract template method for marshalling the given object graph to a Writer . |
protected void |
marshalXmlEventWriter(Object graph,
XMLEventWriter eventWriter)
Abstract template method for marshalling the given object to a StAX XMLEventWriter . |
protected void |
marshalXmlStreamWriter(Object graph,
XMLStreamWriter streamWriter)
Abstract template method for marshalling the given object to a StAX XMLStreamWriter . |
void |
setAliases(Map aliases)
Set a alias/type map, consisting of string aliases mapped to Class instances (or Strings to be
converted to Class instances). |
void |
setConverters(com.thoughtworks.xstream.converters.ConverterMatcher[] converters)
Sets the Converters or SingleValueConverters to be registered with the
XStream instance. |
void |
setEncoding(String encoding)
Sets the encoding to be used for stream access. |
void |
setImplicitCollection(Map implicitCollection)
Set a implicit colletion/type map, consisting of string implicit collection mapped to Class
instances (or Strings to be converted to Class instances). |
void |
setMode(int mode)
Sets the XStream mode. |
void |
setOmittedFields(Map omittedFields)
Sets a ommited field map, consisting of Class instances (or Strings to be converted to
Class instances) mapped to comma separated field names. |
void |
setStreamDriver(com.thoughtworks.xstream.io.HierarchicalStreamDriver streamDriver)
Sets the XStream hierarchical stream driver to be used with stream readers and writers |
void |
setSupportedClasses(Class[] supportedClasses)
Sets the classes supported by this marshaller. |
void |
setUseAttributeFor(Map attributes)
Sets the types to use XML attributes for. |
void |
setUseAttributeForTypes(Class[] types)
Sets types to use XML attributes for. |
boolean |
supports(Class clazz)
Indicates whether this marshaller can marshal instances of the supplied type. |
protected Object |
unmarshalDomNode(Node node)
Abstract template method for unmarshalling from a given DOM Node . |
protected Object |
unmarshalInputStream(InputStream inputStream)
Abstract template method for unmarshalling from a given InputStream . |
protected Object |
unmarshalReader(Reader reader)
Abstract template method for unmarshalling from a given Reader . |
protected Object |
unmarshalSaxReader(XMLReader xmlReader,
InputSource inputSource)
Abstract template method for unmarshalling using a given SAX XMLReader and
InputSource . |
protected Object |
unmarshalXmlEventReader(XMLEventReader eventReader)
Abstract template method for unmarshalling from a given Stax XMLEventReader . |
protected Object |
unmarshalXmlStreamReader(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 String DEFAULT_ENCODING
Constructor Detail |
---|
public XStreamMarshaller()
Method Detail |
---|
public String getEncoding()
DEFAULT_ENCODING
public void setEncoding(String encoding)
DEFAULT_ENCODING
public com.thoughtworks.xstream.XStream getXStream()
public void setMode(int mode)
XStream.XPATH_REFERENCES
,
XStream.ID_REFERENCES
,
XStream.NO_REFERENCES
public void setSupportedClasses(Class[] supportedClasses)
supports(Class)
public void setConverters(com.thoughtworks.xstream.converters.ConverterMatcher[] converters)
Converters
or SingleValueConverters
to be registered with the
XStream
instance.
Converter
,
SingleValueConverter
public void setStreamDriver(com.thoughtworks.xstream.io.HierarchicalStreamDriver streamDriver)
public void setAliases(Map aliases)
Class
instances (or Strings to be
converted to Class
instances).
ClassEditor
public void addAlias(String name, Class type)
name
- alias to be used for the typetype
- the type to be aliasedpublic void setUseAttributeForTypes(Class[] types)
XStream.useAttributeFor(Class)
public void setUseAttributeFor(Map attributes)
<String, Class>
pairs, in which case XStream.useAttributeFor(String,Class)
is called, or <Class,
String>
pairs, which results in XStream.useAttributeFor(Class,String)
.
public void addImplicitCollection(String name, Class type)
XStream.addImplicitCollection(Class, String)
public void setImplicitCollection(Map implicitCollection)
Class
instances (or Strings to be converted to Class
instances).
XStream.addImplicitCollection(Class, String)
public void addOmittedField(Class type, String fieldName)
type
- the type to be containing the fieldfieldName
- field to omittXStream.omitField(Class, String)
public void setOmittedFields(Map omittedFields)
Class
instances (or Strings to be converted to
Class
instances) mapped to comma separated field names.
XStream.omitField(Class, String)
public boolean supports(Class clazz)
Marshaller
clazz
- 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
otherwisepublic XmlMappingException convertXStreamException(Exception ex, boolean marshalling)
org.springframework.oxm
hierarchy.
The default implementation delegates to XStreamUtils
. Can be overridden in subclasses.
ex
- exception that occuredmarshalling
- indicates whether the exception occurs during marshalling (true
), or
unmarshalling (false
)
XmlMappingException
instanceXStreamUtils.convertXStreamException(Exception,boolean)
protected void marshalDomNode(Object graph, Node node) throws XmlMappingException
AbstractMarshaller
Node
.
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 AbstractMarshaller
graph
- 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 void marshalXmlEventWriter(Object graph, XMLEventWriter eventWriter) throws XmlMappingException
AbstractMarshaller
XMLEventWriter
.
marshalXmlEventWriter
in class AbstractMarshaller
graph
- the root of the object graph to marshaleventWriter
- the XMLEventWriter
to write to
XmlMappingException
- if the given object cannot be marshalled to the DOM nodeprotected void marshalXmlStreamWriter(Object graph, XMLStreamWriter streamWriter) throws XmlMappingException
AbstractMarshaller
XMLStreamWriter
.
marshalXmlStreamWriter
in class AbstractMarshaller
graph
- 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 marshalOutputStream(Object graph, OutputStream outputStream) throws XmlMappingException, IOException
AbstractMarshaller
OutputStream
.
marshalOutputStream
in class AbstractMarshaller
graph
- the root of the object graph to marshaloutputStream
- the OutputStream
to write to
XmlMappingException
- if the given object cannot be marshalled to the writer
IOException
- if an I/O exception occursprotected void marshalSaxHandlers(Object graph, ContentHandler contentHandler, LexicalHandler lexicalHandler) throws XmlMappingException
AbstractMarshaller
ContentHandler
.
marshalSaxHandlers
in class AbstractMarshaller
graph
- the root of the object graph to marshalcontentHandler
- the SAX ContentHandler
lexicalHandler
- the SAX2 LexicalHandler
. Can be null
.
XmlMappingException
- if the given object cannot be marshalled to the handlersprotected void marshalWriter(Object graph, Writer writer) throws XmlMappingException, IOException
AbstractMarshaller
Writer
.
marshalWriter
in class AbstractMarshaller
graph
- the root of the object graph to marshalwriter
- the Writer
to write to
XmlMappingException
- if the given object cannot be marshalled to the writer
IOException
- if an I/O exception occursprotected Object unmarshalDomNode(Node node) throws XmlMappingException
AbstractMarshaller
Node
.
unmarshalDomNode
in class AbstractMarshaller
node
- The DOM node that contains the objects to be unmarshalled
XmlMappingException
- if the given DOM node cannot be mapped to an objectprotected Object unmarshalXmlEventReader(XMLEventReader eventReader) throws XmlMappingException
AbstractMarshaller
XMLEventReader
.
unmarshalXmlEventReader
in class AbstractMarshaller
eventReader
- The XMLEventReader
to read from
XmlMappingException
- if the given event reader cannot be converted to an objectprotected Object unmarshalXmlStreamReader(XMLStreamReader streamReader) throws XmlMappingException
AbstractMarshaller
XMLStreamReader
.
unmarshalXmlStreamReader
in class AbstractMarshaller
streamReader
- The XMLStreamReader
to read from
XmlMappingException
- if the given stream reader cannot be converted to an objectprotected Object unmarshalInputStream(InputStream inputStream) throws XmlMappingException, IOException
AbstractMarshaller
InputStream
.
unmarshalInputStream
in class AbstractMarshaller
inputStream
- the InputStreamStream
to read from
XmlMappingException
- if the given stream cannot be converted to an object
IOException
- if an I/O exception occursprotected Object unmarshalReader(Reader reader) throws XmlMappingException, IOException
AbstractMarshaller
Reader
.
unmarshalReader
in class AbstractMarshaller
reader
- the Reader
to read from
XmlMappingException
- if the given reader cannot be converted to an object
IOException
- if an I/O exception occursprotected Object unmarshalSaxReader(XMLReader xmlReader, InputSource inputSource) throws XmlMappingException, IOException
AbstractMarshaller
XMLReader
and
InputSource
.
unmarshalSaxReader
in class AbstractMarshaller
xmlReader
- 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
IOException
- if an I/O exception occurs
|
Spring Web Services Framework | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |