Class CompositeMap

  • All Implemented Interfaces:
    Converter

    class CompositeMap
    extends java.lang.Object
    implements Converter
    The CompositeMap is used to serialize and deserialize maps to and from a source XML document. The structure of the map in the XML format is determined by the annotation. Keys can be either attributes or elements, and values can be inline. This can perform serialization and deserialization of the key and value objects whether the object types are primitive or composite.
     
        <map>
           <entry key='1'>           
              <value>one</value>
           </entry>
           <entry key='2'>
              <value>two</value>
           </entry>      
        </map>
        
     
    For the above XML element map the element entry is used to wrap the key and value such that they can be grouped. This element does not represent any real object. The names of each of the XML elements serialized and deserialized can be configured.
    See Also:
    Entry
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private Entry entry
      The entry object contains the details on how to write the map.
      private MapFactory factory
      The factory used to create suitable map object instances.
      private Converter key
      This is the name of the entry wrapping the key and value.
      private Style style
      This is the style used to style the names used for the XML.
      private Converter value
      This is the type that the value objects are instances of.
    • Constructor Summary

      Constructors 
      Constructor Description
      CompositeMap​(Context context, Entry entry, Type type)
      Constructor for the CompositeMap 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)
      This populate method will read the XML element map from the provided node and deserialize its children as entry types.
      java.lang.Object read​(InputNode node)
      This read method will read the XML element map from the provided node and deserialize its children as entry types.
      java.lang.Object read​(InputNode node, java.lang.Object result)
      This read method will read the XML element map from the provided node and deserialize its children as entry types.
      boolean validate​(InputNode node)
      This validate method will validate the XML element map from the provided node and validate its children as entry types.
      private boolean validate​(InputNode node, java.lang.Class type)
      This validate method will validate the XML element map from the provided node and validate its children as entry types.
      void write​(OutputNode node, java.lang.Object source)
      This write method will write the key value pairs within the provided map to the specified XML node.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • factory

        private final MapFactory factory
        The factory used to create suitable map object instances.
      • value

        private final Converter value
        This is the type that the value objects are instances of.
      • key

        private final Converter key
        This is the name of the entry wrapping the key and value.
      • style

        private final Style style
        This is the style used to style the names used for the XML.
      • entry

        private final Entry entry
        The entry object contains the details on how to write the map.
    • Constructor Detail

      • CompositeMap

        public CompositeMap​(Context context,
                            Entry entry,
                            Type type)
                     throws java.lang.Exception
        Constructor for the CompositeMap object. This will create a converter that is capable of writing map objects to and from XML. The resulting XML is configured by an annotation such that key values can attributes and values can be inline.
        Parameters:
        context - this is the root context for the serialization
        entry - this provides configuration for the resulting XML
        type - this is the map type that is to be converted
        Throws:
        java.lang.Exception
    • Method Detail

      • read

        public java.lang.Object read​(InputNode node)
                              throws java.lang.Exception
        This read 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 its Root annotation must be present and the name of the object element must match that root element name.
        Specified by:
        read in interface Converter
        Parameters:
        node - this is the XML element that is to be deserialized
        Returns:
        this returns the item to attach to the object contact
        Throws:
        java.lang.Exception - if a deserialized type cannot be instantiated
      • read

        public java.lang.Object read​(InputNode node,
                                     java.lang.Object result)
                              throws java.lang.Exception
        This read 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 its Root annotation must be present and the name of the object element must match that root element name.
        Specified by:
        read in interface Converter
        Parameters:
        node - this is the XML element that is to be deserialized
        result - 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
        This populate 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 its Root annotation must be present and the name of the object element must match that root element name.
        Parameters:
        node - this is the XML element that is to be deserialized
        result - 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
      • validate

        public boolean validate​(InputNode node)
                         throws java.lang.Exception
        This validate method will validate the XML element map from the provided node and validate 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 its Root annotation must be present and the name of the object element must match that root element name.
        Specified by:
        validate in interface Converter
        Parameters:
        node - this is the XML element that is to be validate
        Returns:
        true if the element matches the XML schema class given
        Throws:
        java.lang.Exception - if the class XML schema does not fully match
      • validate

        private boolean validate​(InputNode node,
                                 java.lang.Class type)
                          throws java.lang.Exception
        This validate method will validate the XML element map from the provided node and validate 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 its Root annotation must be present and the name of the object element must match that root element name.
        Parameters:
        node - this is the XML element that is to be validate
        type - this is the type to validate the input node against
        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
        This write method will write the key value pairs within the provided map to the specified XML node. This will write each entry type must contain a key and value so that the entry can be deserialized in to the map as a pair. If the key or value object is composite it is read as a root object so its Root annotation must be present.
        Specified by:
        write in interface Converter
        Parameters:
        node - this is the node the map is to be written to
        source - this is the source map that is to be written
        Throws:
        java.lang.Exception - throw if the object cannot be serialized