Spring for Android

org.springframework.http.converter.xml
Class SimpleXmlHttpMessageConverter

java.lang.Object
  extended by org.springframework.http.converter.AbstractHttpMessageConverter<java.lang.Object>
      extended by org.springframework.http.converter.xml.SimpleXmlHttpMessageConverter
All Implemented Interfaces:
HttpMessageConverter<java.lang.Object>

public class SimpleXmlHttpMessageConverter
extends AbstractHttpMessageConverter<java.lang.Object>

Implementation of HttpMessageConverter that can read and write XML using Simple's Serializer abstraction. *

By default, this converter supports text/xml and application/xml. This can be overridden by setting the supportedMediaTypes property.

Since:
1.0
Author:
Roy Clarkson

Field Summary
static java.nio.charset.Charset DEFAULT_CHARSET
           
 
Constructor Summary
SimpleXmlHttpMessageConverter()
          Construct a new SimpleXmlHttpMessageConverter with a default Serializer.
SimpleXmlHttpMessageConverter(org.simpleframework.xml.Serializer serializer)
          Construct a new SimpleXmlHttpMessageConverter with a customized Serializer.
 
Method Summary
 boolean canRead(java.lang.Class<?> clazz, MediaType mediaType)
          This implementation checks if the given class is supported, and if the supported media types include the given media type.
 boolean canWrite(java.lang.Class<?> clazz, MediaType mediaType)
          This implementation checks if the given class is supported, and if the supported media types include the given media type.
protected  java.lang.Object readInternal(java.lang.Class<? extends java.lang.Object> clazz, HttpInputMessage inputMessage)
          Abstract template method that reads the actualy object.
 void setSerializer(org.simpleframework.xml.Serializer serializer)
          Sets the Serializer for this view.
protected  boolean supports(java.lang.Class<?> clazz)
          Indicates whether the given class is supported by this converter.
protected  void writeInternal(java.lang.Object o, HttpOutputMessage outputMessage)
          Abstract template method that writes the actual body.
 
Methods inherited from class org.springframework.http.converter.AbstractHttpMessageConverter
canRead, canWrite, getContentLength, getDefaultContentType, getSupportedMediaTypes, read, setSupportedMediaTypes, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_CHARSET

public static final java.nio.charset.Charset DEFAULT_CHARSET
Constructor Detail

SimpleXmlHttpMessageConverter

public SimpleXmlHttpMessageConverter()
Construct a new SimpleXmlHttpMessageConverter with a default Serializer. Sets the supportedMediaTypes to text/xml and application/xml, and application/*+xml.


SimpleXmlHttpMessageConverter

public SimpleXmlHttpMessageConverter(org.simpleframework.xml.Serializer serializer)
Construct a new SimpleXmlHttpMessageConverter with a customized Serializer. Sets the supportedMediaTypes to text/xml and application/xml, and application/*-xml.

Method Detail

setSerializer

public void setSerializer(org.simpleframework.xml.Serializer serializer)
Sets the Serializer for this view. If not set, a default Serializer is used.

Setting a custom-configured Serializer is one way to take further control of the XML serialization process.

Throws:
java.lang.IllegalArgumentException - if serializer is null

canRead

public boolean canRead(java.lang.Class<?> clazz,
                       MediaType mediaType)
Description copied from class: AbstractHttpMessageConverter
This implementation checks if the given class is supported, and if the supported media types include the given media type.

Specified by:
canRead in interface HttpMessageConverter<java.lang.Object>
Overrides:
canRead in class AbstractHttpMessageConverter<java.lang.Object>
Parameters:
clazz - the class to test for readability
mediaType - the media type to read, can be null if not specified. Typically the value of a Content-Type header.
Returns:
true if readable; false otherwise

canWrite

public boolean canWrite(java.lang.Class<?> clazz,
                        MediaType mediaType)
Description copied from class: AbstractHttpMessageConverter
This implementation checks if the given class is supported, and if the supported media types include the given media type.

Specified by:
canWrite in interface HttpMessageConverter<java.lang.Object>
Overrides:
canWrite in class AbstractHttpMessageConverter<java.lang.Object>
Parameters:
clazz - the class to test for writability
mediaType - the media type to write, can be null if not specified. Typically the value of an Accept header.
Returns:
true if writable; false otherwise

supports

protected boolean supports(java.lang.Class<?> clazz)
Description copied from class: AbstractHttpMessageConverter
Indicates whether the given class is supported by this converter.

Specified by:
supports in class AbstractHttpMessageConverter<java.lang.Object>
Parameters:
clazz - the class to test for support
Returns:
true if supported; false otherwise

readInternal

protected java.lang.Object readInternal(java.lang.Class<? extends java.lang.Object> clazz,
                                        HttpInputMessage inputMessage)
                                 throws java.io.IOException,
                                        HttpMessageNotReadableException
Description copied from class: AbstractHttpMessageConverter
Abstract template method that reads the actualy object. Invoked from AbstractHttpMessageConverter.read(java.lang.Class, org.springframework.http.HttpInputMessage).

Specified by:
readInternal in class AbstractHttpMessageConverter<java.lang.Object>
Parameters:
clazz - the type of object to return
inputMessage - the HTTP input message to read from
Returns:
the converted object
Throws:
java.io.IOException - in case of I/O errors
HttpMessageNotReadableException - in case of conversion errors

writeInternal

protected void writeInternal(java.lang.Object o,
                             HttpOutputMessage outputMessage)
                      throws java.io.IOException,
                             HttpMessageNotWritableException
Description copied from class: AbstractHttpMessageConverter
Abstract template method that writes the actual body. Invoked from AbstractHttpMessageConverter.write(T, org.springframework.http.MediaType, org.springframework.http.HttpOutputMessage).

Specified by:
writeInternal in class AbstractHttpMessageConverter<java.lang.Object>
Parameters:
o - the object to write to the output message
outputMessage - the message to write to
Throws:
java.io.IOException - in case of I/O errors
HttpMessageNotWritableException - in case of conversion errors

Spring for Android