Package org.simpleframework.xml.core
Class CompositeList
- java.lang.Object
-
- org.simpleframework.xml.core.CompositeList
-
- All Implemented Interfaces:
Converter
class CompositeList extends java.lang.Object implements Converter
TheCompositeList
object is used to convert an element list to a collection of element entries. This in effect performs a root serialization and deserialization of entry elements for the collection object. On serialization each objects type must be checked against the XML annotation entry so that it is serialized in a form that can be deserialized.<list> <entry attribute="value"> <text>example text value</text> </entry> <entry attribute="demo"> <text>some other example</text> </entry> </list>
For the above XML element list the elemententry
is contained within the list. Each entry element is thus deserialized as a root element and then inserted into the list. This enables lists to be composed from XML documents. For serialization the reverse is done, each element taken from the collection is written as a root element to the owning element to create the list. Entry objects do not need to be of the same type.- See Also:
Traverser
,ElementList
-
-
Field Summary
Fields Modifier and Type Field Description private Type
entry
This is the entry type for elements within the list.private CollectionFactory
factory
This factory is used to create a suitable collection list.private java.lang.String
name
This represents the name of the entry elements to write.private Traverser
root
This performs the traversal used for object serialization.private Type
type
This is the field or method that has been annotated.
-
Constructor Summary
Constructors Constructor Description CompositeList(Context context, Type type, Type entry, java.lang.String name)
Constructor for theCompositeList
object.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private java.lang.Object
populate(InputNode node, java.lang.Object result)
Thispopulate
method wll read the XML element list from the provided node and deserialize its children as entry types.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 result)
Thisread
method will read the XML element map from the provided node and deserialize its children as entry types.boolean
validate(InputNode node)
Thisvalidate
method will validate the XML element list from the provided node and deserialize its children as entry types.private boolean
validate(InputNode node, java.lang.Class type)
Thisvalidate
method will validate the XML element list from the provided node and deserialize 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 list entries.
-
-
-
Field Detail
-
factory
private final CollectionFactory factory
This factory is used to create a suitable collection list.
-
root
private final Traverser root
This performs the traversal used for object serialization.
-
name
private final java.lang.String name
This represents the name of the entry elements to write.
-
entry
private final Type entry
This is the entry type for elements within the list.
-
type
private final Type type
This is the field or method that has been annotated.
-
-
Constructor Detail
-
CompositeList
public CompositeList(Context context, Type type, Type entry, java.lang.String name)
Constructor for theCompositeList
object. This is given the list type and entry type to be used. The list type is theCollection
implementation that deserialized entry objects are inserted into.- Parameters:
context
- this is the context object used for serializationtype
- this is the collection type for the list usedentry
- the entry type to be stored within the list
-
-
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 will 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 result) throws java.lang.Exception
Thisread
method will read the XML element map from the provided node and deserialize its children as entry types. Each entry type must contain a key and value so that the entry can be inserted in to the map as a pair. If either the key or value is composite it is read as a root object, which means itsRoot
annotation must be present and the name of the object element must match that root element name.- Specified by:
read
in interfaceConverter
- Parameters:
node
- this is the XML element that is to be deserializedresult
- this is the map object that is to be populated- Returns:
- this returns the item to attach to the object contact
- Throws:
java.lang.Exception
- if a deserialized type cannot be instantiated
-
populate
private java.lang.Object populate(InputNode node, java.lang.Object result) throws java.lang.Exception
Thispopulate
method wll read the XML element list from the provided node and deserialize its children as entry types. This will 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.- Parameters:
node
- this is the XML element that is to be deserializedresult
- this is the collection that is to be populated- Returns:
- this returns the item to attach to the object contact
- Throws:
java.lang.Exception
-
validate
public boolean validate(InputNode node) throws java.lang.Exception
Thisvalidate
method will validate the XML element list from the provided node and deserialize its children as entry types. This takes each entry type and validates it 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 will validate the XML element list from the provided node and deserialize its children as entry types. This takes each entry type and validates it 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 type to validate against the input node- 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 list entries. Each entry within the given collection must be assignable from the annotated type specified within theElementList
annotation. Each entry is serialized as a root element, that is, itsRoot
annotation is used to extract the name.
-
-