Class WriteGraph

All Implemented Interfaces:
Serializable, Cloneable, Map<Object,String>

class WriteGraph extends IdentityHashMap<Object,String>
The WriteGraph object is used to build the graph that is used to represent the serialized object and its references. The graph is stored in an IdentityHashMap which will store the objects in such a way that this graph object can tell if it has already been written to the XML document. If an object has already been written to the XML document an reference attribute is added to the element representing the object and serialization of that object is complete, that is, no more elements are written.

The attribute values written by this are unique strings, which allows the deserialization process to identify object references easily. By default these references are incrementing integers however for deserialization they can be any unique string value.

  • Field Details

    • length

      private final String length
      This is used to specify the length of array instances.
    • label

      private final String label
      This is the label used to mark the type of an object.
    • mark

      private final String mark
      This is the attribute used to mark the identity of an object.
    • refer

      private final String refer
      This is the attribute used to refer to an existing instance.
  • Constructor Details

    • WriteGraph

      public WriteGraph(Contract contract)
      Constructor for the WriteGraph object. This is used to build the graph used for writing objects to the XML document. The specified strategy is used to acquire the names of the special attributes used during the serialization.
      Parameters:
      contract - this is the name scheme used by the strategy
  • Method Details

    • write

      public boolean write(Type type, Object value, NodeMap node)
      This is used to write the XML element attributes representing the serialized object instance. If the object has already been serialized to the XML document then a reference attribute is inserted and this returns true, if not, then this will write a unique identity marker attribute and return false.
      Parameters:
      type - this is the type of the object to be serialized
      value - this is the instance that is to be serialized
      node - this is the node that contains the attributes
      Returns:
      returns true if the element has been fully written
    • writeReference

      private boolean writeReference(Object value, NodeMap node)
      This is used to write the XML element attributes representing the serialized object instance. If the object has already been serialized to the XML document then a reference attribute is inserted and this returns true, if not, then this will write a unique identity marker attribute and return false.
      Parameters:
      value - this is the instance that is to be serialized
      node - this is the node that contains the attributes
      Returns:
      returns true if the element has been fully written
    • writeArray

      private Class writeArray(Class field, Object value, NodeMap node)
      This is used to add a length attribute to the element due to the fact that the serialized value is an array. The length of the array is acquired and inserted in to the attributes.
      Parameters:
      field - this is the field type for the array to set
      value - this is the actual value for the array to set
      node - this is the map of attributes for the element
      Returns:
      returns the array component type that is set