C# Class CycleStrategy, simplexml

The 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 serialized 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.
Inheritance: Strategy
Exibir arquivo Open project: ngallagher/simplexml Class Usage Examples

Public Methods

Method Description
CycleStrategy ( ) : SimpleFramework.Xml.Stream

Constructor for the 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.

CycleStrategy ( String mark, String refer ) : SimpleFramework.Xml.Stream

Constructor for the CycleStrategy object. This is used to create a strategy with the specified 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.

CycleStrategy ( String mark, String refer, String label ) : SimpleFramework.Xml.Stream

Constructor for the CycleStrategy object. This is used to create a strategy with the specified 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.

CycleStrategy ( String mark, String refer, String label, String length ) : SimpleFramework.Xml.Stream

Constructor for the CycleStrategy object. This is used to create a strategy with the specified 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.

Read ( Type type, NodeMap node, Dictionary, map ) : Value,

This method is used to read an object from the specified node. In order to get the root type the field and node map are specified. The field represents the annotated method or field within the deserialized object. The node map is used to get the attributes used to describe the objects identity, or in the case of an existing object it contains an object reference.

Write ( Type type, Object value, NodeMap node, Dictionary, map ) : bool

This is used to write the reference in to the XML element that is to be written. This will either insert an object identity if the object has not previously been written, or, if the object has already been written in a previous element, this will write the reference to that object. This allows all cycles within the graph to be serialized so that they can be fully deserialized.

Method Details

CycleStrategy() public method

Constructor for the 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 ( ) : SimpleFramework.Xml.Stream
return SimpleFramework.Xml.Stream

CycleStrategy() public method

Constructor for the CycleStrategy object. This is used to create a strategy with the specified 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.
public CycleStrategy ( String mark, String refer ) : SimpleFramework.Xml.Stream
mark String /// this is used to mark the identity of an object ///
refer String /// this is used to refer to an existing object ///
return SimpleFramework.Xml.Stream

CycleStrategy() public method

Constructor for the CycleStrategy object. This is used to create a strategy with the specified 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.
public CycleStrategy ( String mark, String refer, String label ) : SimpleFramework.Xml.Stream
mark String /// this is used to mark the identity of an object ///
refer String /// this is used to refer to an existing object ///
label String /// this is used to specify the class for the field ///
return SimpleFramework.Xml.Stream

CycleStrategy() public method

Constructor for the CycleStrategy object. This is used to create a strategy with the specified 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.
public CycleStrategy ( String mark, String refer, String label, String length ) : SimpleFramework.Xml.Stream
mark String /// this is used to mark the identity of an object ///
refer String /// this is used to refer to an existing object ///
label String /// this is used to specify the class for the field ///
length String /// this is the length attribute used for arrays ///
return SimpleFramework.Xml.Stream

Read() public method

This method is used to read an object from the specified node. In order to get the root type the field and node map are specified. The field represents the annotated method or field within the deserialized object. The node map is used to get the attributes used to describe the objects identity, or in the case of an existing object it contains an object reference.
public Read ( Type type, NodeMap node, Dictionary, map ) : Value,
type Type /// the method or field in the deserialized object ///
node NodeMap /// this is the XML element attributes to read ///
map Dictionary, /// this is the session map used for deserialization ///
return Value,

Write() public method

This is used to write the reference in to the XML element that is to be written. This will either insert an object identity if the object has not previously been written, or, if the object has already been written in a previous element, this will write the reference to that object. This allows all cycles within the graph to be serialized so that they can be fully deserialized.
public Write ( Type type, Object value, NodeMap node, Dictionary, map ) : bool
type Type /// the type of the field or method in the object ///
value Object /// this is the actual object that is to be written ///
node NodeMap /// this is the XML element attribute map to use ///
map Dictionary, /// this is the session map used for the serialization ///
return bool