Class WriteGraph

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, java.util.Map<java.lang.Object,​java.lang.String>

    class WriteGraph
    extends java.util.IdentityHashMap<java.lang.Object,​java.lang.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.

    • Nested Class Summary

      • Nested classes/interfaces inherited from class java.util.AbstractMap

        java.util.AbstractMap.SimpleEntry<K extends java.lang.Object,​V extends java.lang.Object>, java.util.AbstractMap.SimpleImmutableEntry<K extends java.lang.Object,​V extends java.lang.Object>
      • Nested classes/interfaces inherited from interface java.util.Map

        java.util.Map.Entry<K extends java.lang.Object,​V extends java.lang.Object>
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.lang.String label
      This is the label used to mark the type of an object.
      private java.lang.String length
      This is used to specify the length of array instances.
      private java.lang.String mark
      This is the attribute used to mark the identity of an object.
      private java.lang.String refer
      This is the attribute used to refer to an existing instance.
    • Constructor Summary

      Constructors 
      Constructor Description
      WriteGraph​(Contract contract)
      Constructor for the WriteGraph object.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean write​(Type type, java.lang.Object value, NodeMap node)
      This is used to write the XML element attributes representing the serialized object instance.
      private java.lang.Class writeArray​(java.lang.Class field, java.lang.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.
      private boolean writeReference​(java.lang.Object value, NodeMap node)
      This is used to write the XML element attributes representing the serialized object instance.
      • Methods inherited from class java.util.IdentityHashMap

        clear, clone, containsKey, containsValue, entrySet, equals, forEach, get, hashCode, isEmpty, keySet, put, putAll, remove, replaceAll, size, values
      • Methods inherited from class java.util.AbstractMap

        toString
      • Methods inherited from class java.lang.Object

        finalize, getClass, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.util.Map

        compute, computeIfAbsent, computeIfPresent, getOrDefault, merge, putIfAbsent, remove, replace, replace
    • Field Detail

      • length

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

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

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

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

      • 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 Detail

      • write

        public boolean write​(Type type,
                             java.lang.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​(java.lang.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 java.lang.Class writeArray​(java.lang.Class field,
                                           java.lang.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