com.flat502.rox.marshal.xmlrpc
Class XmlRpcMarshaller

java.lang.Object
  extended by com.flat502.rox.marshal.xmlrpc.XmlRpcMarshaller
All Implemented Interfaces:
XmlRpcConstants
Direct Known Subclasses:
XmlRpcMarshallerJ5

public class XmlRpcMarshaller
extends java.lang.Object
implements XmlRpcConstants

This class supports marshalling of XML-RPC values, not execution. For that functionality see the XmlRpcClient class.

The relationship between Java and XML-RPC data types is given in the following table:

Java XML-RPC Notes
Integer or int <int> or <i4> This implementation always uses the <int> form when marshalling integers.
Boolean or boolean <boolean>
String or char[] <string> This implementation always uses an explicit <string> tag when marshalling strings.
Float, float, Double or double <double> If the target field is a float (or Float) then the value may be truncated.
java.util.Date <dateTime.iso8601> Date values are interpreted as UTC dates for the purposes of unmarshalling.
byte[] <base64>
Object or java.util.Map <struct> Objects are marshalled (and unmarshalled) by treating their public fields as keys in a map. The names of the public fields are transformed by calls to the encodeFieldName(String) method. transient fields and fields with a null value are ignored during marshalling.
Object[] or java.util.List <array>


Nested Class Summary
 
Nested classes/interfaces inherited from interface com.flat502.rox.marshal.xmlrpc.XmlRpcConstants
XmlRpcConstants.ContentTypes, XmlRpcConstants.Formats, XmlRpcConstants.Tags, XmlRpcConstants.Types
 
Constructor Summary
protected XmlRpcMarshaller(FieldNameEncoder fieldNameEncoder)
          Initialize a new instance of this class.
 
Method Summary
protected  java.lang.String encodeFieldName(java.lang.String name)
          Determine the name of an XML-RPC struct member from an Object field name.
protected  java.lang.String getBase64TagName()
           
protected  java.lang.String getBooleanTagName()
           
protected  java.text.DateFormat getDateFormat()
           
protected  java.lang.String getDateTagName()
           
protected  java.lang.String getDoubleTagName()
           
protected  java.lang.String getIntTagName()
           
protected  java.lang.String getStringTagName()
           
protected  void marshalList(XmlPrinter out, int depth, java.util.List list)
           
protected  void marshalMap(XmlPrinter out, int depth, java.util.Map param)
           
protected  void marshalObject(XmlPrinter out, int depth, java.lang.Object param)
          Marshals an Object that is not one of the standard types in the mapping table discussed in the description of this class.
protected  void marshalValue(XmlPrinter out, java.lang.Boolean val)
           
protected  void marshalValue(XmlPrinter out, byte[] val)
           
protected  void marshalValue(XmlPrinter out, java.lang.Character val)
           
protected  void marshalValue(XmlPrinter out, java.util.Date val)
           
protected  void marshalValue(XmlPrinter out, int depth, java.lang.Object param)
           
protected  void marshalValue(XmlPrinter out, java.lang.Number val)
           
protected  void marshalValue(XmlPrinter out, java.lang.String val)
           
protected  java.text.DateFormat newDateFormat()
          Initialize a new DateFormat for use when formatting XML-RPC date values.
protected  XmlPrinter newXmlWriter(java.io.OutputStream out, java.nio.charset.Charset charSet)
          A factory method invoked to create a new instance of XmlPrinter.
 void setCompactXml(boolean compact)
          Configure the compactness of the marshalled form of this instance.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XmlRpcMarshaller

protected XmlRpcMarshaller(FieldNameEncoder fieldNameEncoder)
Initialize a new instance of this class.

This constructor calls newDateFormat() to initialize the underlying date formatter.

Parameters:
fieldNameEncoder - An implementation of FieldNameEncoder used when struct members are marshalled. May be null.
Method Detail

setCompactXml

public void setCompactXml(boolean compact)
Configure the compactness of the marshalled form of this instance.

The marshalled form of instances is compact by default.

Parameters:
compact - A flag indicating whether to produce compact XML (true) or more readable XML (true).

newXmlWriter

protected XmlPrinter newXmlWriter(java.io.OutputStream out,
                                  java.nio.charset.Charset charSet)
                           throws java.io.IOException
A factory method invoked to create a new instance of XmlPrinter.

Implementations are free to ignore the compact parameter. It is intended as hint to ease debugging. This implementation "pretty prints" the XML if compact is false, using indentation and line terminators to lay the document out in a more readable form. The result is likely to be a considerably larger XML document.

Parameters:
out - The OutputStream the returned instance should write to.
charSet - The character encoding that should be used when writing textual data to the underlying stream.
Returns:
A new instance of XmlPrinter that will print to the given stream.
Throws:
java.io.IOException

getDateFormat

protected java.text.DateFormat getDateFormat()

getIntTagName

protected java.lang.String getIntTagName()

getBooleanTagName

protected java.lang.String getBooleanTagName()

getStringTagName

protected java.lang.String getStringTagName()
Returns:
Implementations may return null if strings should be encoded without a type tag.

getDoubleTagName

protected java.lang.String getDoubleTagName()

getDateTagName

protected java.lang.String getDateTagName()

getBase64TagName

protected java.lang.String getBase64TagName()

newDateFormat

protected java.text.DateFormat newDateFormat()
Initialize a new DateFormat for use when formatting XML-RPC date values.

This method may be invoked multiple times and it must return an equivalent formatter on each invocation. Equivalent formatters always produce the same string literal when formatting a given Date instance.

Returns:
A new date

marshalValue

protected void marshalValue(XmlPrinter out,
                            int depth,
                            java.lang.Object param)
                     throws MarshallingException,
                            java.io.IOException
Throws:
MarshallingException
java.io.IOException

marshalValue

protected void marshalValue(XmlPrinter out,
                            java.lang.Boolean val)
                     throws MarshallingException,
                            java.io.IOException
Throws:
MarshallingException
java.io.IOException

marshalValue

protected void marshalValue(XmlPrinter out,
                            java.lang.Character val)
                     throws MarshallingException,
                            java.io.IOException
Throws:
MarshallingException
java.io.IOException

marshalValue

protected void marshalValue(XmlPrinter out,
                            java.lang.String val)
                     throws MarshallingException,
                            java.io.IOException
Throws:
MarshallingException
java.io.IOException

marshalValue

protected void marshalValue(XmlPrinter out,
                            java.lang.Number val)
                     throws MarshallingException,
                            java.io.IOException
Throws:
MarshallingException
java.io.IOException

marshalValue

protected void marshalValue(XmlPrinter out,
                            java.util.Date val)
                     throws MarshallingException,
                            java.io.IOException
Throws:
MarshallingException
java.io.IOException

marshalValue

protected void marshalValue(XmlPrinter out,
                            byte[] val)
                     throws MarshallingException,
                            java.io.IOException
Throws:
MarshallingException
java.io.IOException

marshalObject

protected void marshalObject(XmlPrinter out,
                             int depth,
                             java.lang.Object param)
                      throws MarshallingException,
                             java.io.IOException
Marshals an Object that is not one of the standard types in the mapping table discussed in the description of this class.

The object is not a simple type (Integer etc) and does not implement either the Map or List interface.

Parameters:
depth - Used for pretty printing the output. Implementations are free to ignore this parameter.
param - The object to marshal
Throws:
MarshallingException
java.io.IOException

marshalMap

protected void marshalMap(XmlPrinter out,
                          int depth,
                          java.util.Map param)
                   throws MarshallingException,
                          java.io.IOException
Throws:
MarshallingException
java.io.IOException

marshalList

protected void marshalList(XmlPrinter out,
                           int depth,
                           java.util.List list)
                    throws MarshallingException,
                           java.io.IOException
Throws:
MarshallingException
java.io.IOException

encodeFieldName

protected java.lang.String encodeFieldName(java.lang.String name)
Determine the name of an XML-RPC struct member from an Object field name.

The default implementation defers to the FieldNameEncoder this instance was initialized with.

Parameters:
name - The name of the Object field.
Returns:
The XML-RPC struct member name the associated value should be assigned to.