Package org.simpleframework.xml.core
Class CompositeArray
- java.lang.Object
-
- org.simpleframework.xml.core.CompositeArray
-
- All Implemented Interfaces:
Converter
class CompositeArray extends java.lang.Object implements Converter
TheCompositeArray
object is used to convert a list of elements to an array of object entries. This in effect performs a root serialization and deserialization of entry elements for the array object. On serialization each objects type must be checked against the array component type so that it is serialized in a form that can be deserialized dynamically.<array length="2"> <entry> <text>example text value</text> </entry> <entry> <text>some other example</text> </entry> </array>
For the above XML element list the elemententry
is contained within the array. Each entry element is deserialized as a root element and then inserted into the array. For serialization the reverse is done, each element taken from the array is written as a root element to the parent element to create the list. Entry objects do not need to be of the same type.- See Also:
Traverser
,ElementArray
-
-
Field Summary
Fields Modifier and Type Field Description private Type
entry
This is the entry type for elements within the array.private ArrayFactory
factory
This factory is used to create an array for the contact.private java.lang.String
parent
This is the name to wrap each entry that is represented.private Traverser
root
This performs the traversal used for object serialization.private Type
type
This represents the actual field or method for the array.
-
Constructor Summary
Constructors Constructor Description CompositeArray(Context context, Type type, Type entry, java.lang.String parent)
Constructor for theCompositeArray
object.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Object
read(InputNode node)
Thisread
method will read the XML element list from the provided node and deserialize its children as entry types.java.lang.Object
read(InputNode node, java.lang.Object list)
Thisread
method will read the XML element list from the provided node and deserialize its children as entry types.private void
read(InputNode node, java.lang.Object list, int index)
This is used to read the specified node from in to the list.boolean
validate(InputNode node)
Thisvalidate
method will validate the XML element list against the provided node and validate its children as entry types.private boolean
validate(InputNode node, java.lang.Class type)
Thisvalidate
method wll validate the XML element list against the provided node and validate its children as entry types.void
write(OutputNode node, java.lang.Object source)
Thiswrite
method will write the specified object to the given XML element as as array entries.
-
-
-
Field Detail
-
factory
private final ArrayFactory factory
This factory is used to create an array for the contact.
-
root
private final Traverser root
This performs the traversal used for object serialization.
-
parent
private final java.lang.String parent
This is the name to wrap each entry that is represented.
-
entry
private final Type entry
This is the entry type for elements within the array.
-
type
private final Type type
This represents the actual field or method for the array.
-
-
Constructor Detail
-
CompositeArray
public CompositeArray(Context context, Type type, Type entry, java.lang.String parent)
Constructor for theCompositeArray
object. This is given the array type for the contact that is to be converted. An array of the specified type is used to hold the deserialized elements and will be the same length as the number of elements.- Parameters:
context
- this is the context object used for serializationtype
- this is the field type for the array being usedentry
- this is the entry type for the array elementsparent
- this is the name to wrap the array element with
-
-
Method Detail
-
read
public java.lang.Object read(InputNode node) throws java.lang.Exception
Thisread
method will read the XML element list from the provided node and deserialize its children as entry types. This ensures each entry type is deserialized as a root type, that is, itsRoot
annotation must be present and the name of the entry element must match that root element name.
-
read
public java.lang.Object read(InputNode node, java.lang.Object list) throws java.lang.Exception
Thisread
method will read the XML element list from the provided node and deserialize its children as entry types. This ensures each entry type is deserialized as a root type, that is, itsRoot
annotation must be present and the name of the entry element must match that root element name.- Specified by:
read
in interfaceConverter
- Parameters:
node
- this is the XML element that is to be deserializedlist
- this is the array that is to be deserialized- Returns:
- this returns the item to attach to the object contact
- Throws:
java.lang.Exception
- if a deserialized type cannot be instantiated
-
read
private void read(InputNode node, java.lang.Object list, int index) throws java.lang.Exception
This is used to read the specified node from in to the list. If the node is null then this represents a null element value in the array. The node can be null only if there is a parent and that parent contains no child XML elements.- Parameters:
node
- this is the node to read the array value fromlist
- this is the list to add the array value in toindex
- this is the offset to set the value in the array- Throws:
java.lang.Exception
-
validate
public boolean validate(InputNode node) throws java.lang.Exception
Thisvalidate
method will validate the XML element list against the provided node and validate its children as entry types. This ensures each entry type is validated as a root type, that is, itsRoot
annotation must be present and the name of the entry element must match that root element name.
-
validate
private boolean validate(InputNode node, java.lang.Class type) throws java.lang.Exception
Thisvalidate
method wll validate the XML element list against the provided node and validate its children as entry types. This ensures each entry type is validated as a root type, that is, itsRoot
annotation must be present and the name of the entry element must match that root element name.- Parameters:
node
- this is the XML element that is to be validatedtype
- this is the array type used to create the array- Returns:
- true if the element matches the XML schema class given
- Throws:
java.lang.Exception
-
write
public void write(OutputNode node, java.lang.Object source) throws java.lang.Exception
Thiswrite
method will write the specified object to the given XML element as as array entries. Each entry within the given array must be assignable to the array component type. Each array entry is serialized as a root element, that is, itsRoot
annotation is used to extract the name.
-
-