public class CycleStrategy extends java.lang.Object implements Strategy
CycleStrategy
represents a strategy that is used
to augment the deserialization and serialization process such that
cycles in an object graph can be supported. This adds additional
attributes to the serializaed XML elements so that during the
deserialization process an objects cycles can be created. Without
the use of a strategy such as this, cycles could cause an infinite
loop during the serialization process while traversing the graph.
<root id="1"> <object id="2"> <object id="3" name="name">Example</item> <object reference="2"/> </object> </root>In the above serialized XML there is a circular reference, where the XML element with id "2" contains a reference to itself. In most data binding frameworks this will cause an infinite loop, or in some cases will just fail to represent the references well. With this strategy you can ensure that cycles in complex object graphs will be maintained and can be serialized safely.
Constructor and Description |
---|
CycleStrategy()
Constructor for the
CycleStrategy object. |
CycleStrategy(java.lang.String mark,
java.lang.String refer)
Constructor for the
CycleStrategy object. |
CycleStrategy(java.lang.String mark,
java.lang.String refer,
java.lang.String label)
Constructor for the
CycleStrategy object. |
CycleStrategy(java.lang.String mark,
java.lang.String refer,
java.lang.String label,
java.lang.String length)
Constructor for the
CycleStrategy object. |
Modifier and Type | Method and Description |
---|---|
Type |
getElement(java.lang.Class field,
NodeMap node,
java.util.Map map)
This method is used to read an object from the specified node.
|
Type |
getRoot(java.lang.Class field,
NodeMap node,
java.util.Map map)
This method is used to read an object from the specified node.
|
boolean |
setElement(java.lang.Class field,
java.lang.Object value,
NodeMap node,
java.util.Map map)
This is used to set the reference in to the XML element that
is to be written.
|
boolean |
setRoot(java.lang.Class field,
java.lang.Object value,
NodeMap node,
java.util.Map map)
This is used to set the reference in to the XML element that
is to be written.
|
public CycleStrategy()
CycleStrategy
object. This is
used to create a strategy with default values. By default the
values used are "id" and "reference". These values will be
added to XML elements during the serialization process. And
will be used to deserialize the object cycles fully.public CycleStrategy(java.lang.String mark, java.lang.String refer)
CycleStrategy
object. This is
used to create a strategy with the sepcified attributes, which
will be added to serialized XML elements. These attributes
are used to serialize the objects in such a way the cycles in
the object graph can be deserialized and used fully.mark
- this is used to mark the identity of an objectrefer
- this is used to refer to an existing objectpublic CycleStrategy(java.lang.String mark, java.lang.String refer, java.lang.String label)
CycleStrategy
object. This is
used to create a strategy with the sepcified attributes, which
will be added to serialized XML elements. These attributes
are used to serialize the objects in such a way the cycles in
the object graph can be deserialized and used fully.mark
- this is used to mark the identity of an objectrefer
- this is used to refer to an existing objectlabel
- this is used to specify the class for the fieldpublic CycleStrategy(java.lang.String mark, java.lang.String refer, java.lang.String label, java.lang.String length)
CycleStrategy
object. This is
used to create a strategy with the sepcified attributes, which
will be added to serialized XML elements. These attributes
are used to serialize the objects in such a way the cycles in
the object graph can be deserialized and used fully.mark
- this is used to mark the identity of an objectrefer
- this is used to refer to an existing objectlabel
- this is used to specify the class for the fieldlength
- this is the length attribute used for arrayspublic Type getRoot(java.lang.Class field, NodeMap node, java.util.Map map) throws java.lang.Exception
getRoot
in interface Strategy
field
- the method or field in the deserialized objectnode
- this is the XML element attributes to readmap
- this is the session map used for deserializationjava.lang.Exception
- thrown if the class cannot be resolvedpublic Type getElement(java.lang.Class field, NodeMap node, java.util.Map map) throws java.lang.Exception
getElement
in interface Strategy
field
- the method or field in the deserialized objectnode
- this is the XML element attributes to readmap
- this is the session map used for deserializationjava.lang.Exception
- thrown if the class cannot be resolvedpublic boolean setRoot(java.lang.Class field, java.lang.Object value, NodeMap node, java.util.Map map)
setRoot
in interface Strategy
field
- the type of the field or method in the objectvalue
- this is the actual object that is to be writtennode
- tihs is the XML element attribute map to usemap
- this is the session map used for the serializationpublic boolean setElement(java.lang.Class field, java.lang.Object value, NodeMap node, java.util.Map map)
setElement
in interface Strategy
field
- the type of the field or method in the objectvalue
- this is the actual object that is to be writtennode
- tihs is the XML element attribute map to usemap
- this is the session map used for the serialization