org.apache.muse.core.serializer
Class ArraySerializer
java.lang.Object
org.apache.muse.core.serializer.ArraySerializer
- All Implemented Interfaces:
- Serializer
public class ArraySerializer
- extends Object
- implements Serializer
ArraySerializer is a wrapper class that transforms arrays of any
registered type into XML and back. It uses the Serializer for
a given type in order to process individual elements in an array and
provides a standard format for arrays over SOAP. Note that this is not
the only way to send arrays over SOAP - SOAP 1.1 and SOAP 1.2 both
define (incompatible) methods for serializing arrays. This class does
not prevent use of these formats, it simply defines a simple system that
allows Muse users to have their arrays transformed automatically.
- Author:
- Dan Jemiolo (danj)
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
ArraySerializer
public ArraySerializer(Class arrayClass,
Serializer classSerializer)
- Parameters:
arrayClass
- The Class that represents the type as an array. This
can be obtained for any type using MyType[].class
or by invoking the getClass() method on an array object.classSerializer
- The serializer for the non-array version of the Class. This
will be used to serialize the individual items in the arrays.
fromXML
public Object fromXML(Element xml)
throws SoapFault
- Deserializes the DOM Element into a POJO whose type this Serializer
is responsible for.
Arrays that are deserialized from XML will have one object
for each child element in a DOM tree:
<UserIDArray>
<!-- each child is an item in the array -->
<UserID>danj</UserID>
<UserID>snible</UserID>
<UserID>bsubram</UserID>
</UserIDArray>
- Specified by:
fromXML
in interface Serializer
- Parameters:
xml
- The XML representation of a Java object. If the type is
primitive or simple (not a primitive, but serialized to a
string), the value should be a DOM Text node inside the
given Element.
- Returns:
- A POJO constructed from the given XML. If the Element is
empty and the Serializer's type is a non-primitive,
the method will return null.
- Throws:
SoapFault
-
- If the XML is not a valid representation of the
Serializer's type.
getArrayClass
public Class getArrayClass()
getClassSerializer
public Serializer getClassSerializer()
getSerializableType
public Class getSerializableType()
- Specified by:
getSerializableType
in interface Serializer
toXML
public Element toXML(Object obj,
QName qname)
throws SoapFault
- Serializes the given object into a DOM Element, the value wrapped
inside a root element with the given name.
Arrays that are serialized to XML will be encapsulated with
elements shown below (element names are actual names):
<YourTypeName>
<YourTypeName>value #1</YourTypeName>
<YourTypeName>value #2</YourTypeName>
<YourTypeName>value #3</YourTypeName>
</YourTypeName>
- Specified by:
toXML
in interface Serializer
- Parameters:
obj
- The object to serialize into XML, or null.qname
- The name of the element which the XML representation will be
wrapped in.
- Returns:
- An Element whose name is the one given, and whose child Nodes
represent the object. If the object was null, an empty Element
is returned.
- Throws:
SoapFault
-
- If the object could not be serialized to XML.
Copyright © 2005-2011 Apache Web Services - Muse. All Rights Reserved.