Class PrimitiveArray

  • All Implemented Interfaces:
    Converter

    class PrimitiveArray
    extends java.lang.Object
    implements Converter
    The PrimitiveArray object is used to convert a list of elements to an array of object entries. This in effect performs a serialization and deserialization of primitive elements for the array object. On serialization each primitive type must be checked against the array component type so that it is serialized in a form that can be deserialized dynamically.
    
        <array>
           <entry>example text one</entry>
           <entry>example text two</entry>
           <entry>example text three</entry>
        </array>
     
     
    For the above XML element list the element entry is contained within the array. Each entry element is deserialized as a from a parent XML element, which is specified in the annotation. For serialization the reverse is done, each element taken from the array is written into an element created from the parent element.
    See Also:
    Primitive, ElementArray
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private Type entry
      This is the type of object that will be held in the list.
      private ArrayFactory factory
      This factory is used to create an array for the contact.
      private java.lang.String parent
      This is the name that each array element is wrapped with.
      private Primitive root
      This performs the serialization of the primitive element.
      private Type type
      This represents the actual field or method for the array.
    • Constructor Summary

      Constructors 
      Constructor Description
      PrimitiveArray​(Context context, Type type, Type entry, java.lang.String parent)
      Constructor for the PrimitiveArray object.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private boolean isOverridden​(OutputNode node, java.lang.Object value)
      This is used to determine whether the specified value has been overridden by the strategy.
      java.lang.Object read​(InputNode node)
      This read method will read the XML element list from the provided node and deserialize its children as entry types.
      java.lang.Object read​(InputNode node, java.lang.Object list)
      This read method will read the XML element list from the provided node and deserialize its children as entry types.
      boolean validate​(InputNode node)
      This validate method will validate the XML element list 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 list 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 specified object to the given XML element as as array entries.
      private void write​(OutputNode node, java.lang.Object source, int index)
      This write method will write the specified object to the given XML element as as array entries.
      • Methods inherited from class java.lang.Object

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

      • factory

        private final ArrayFactory factory
        This factory is used to create an array for the contact.
      • root

        private final Primitive root
        This performs the serialization of the primitive element.
      • parent

        private final java.lang.String parent
        This is the name that each array element is wrapped with.
      • entry

        private final Type entry
        This is the type of object that will be held in the list.
      • type

        private final Type type
        This represents the actual field or method for the array.
    • Constructor Detail

      • PrimitiveArray

        public PrimitiveArray​(Context context,
                              Type type,
                              Type entry,
                              java.lang.String parent)
        Constructor for the PrimitiveArray object. This is given the array type for the contact that is to be converted. An array of the specified type is used to hold the deserialized elements and will be the same length as the number of elements.
        Parameters:
        context - this is the context object used for serialization
        type - this is the actual field type from the schema
        entry - the entry type to be stored within the array
        parent - this is the name to wrap the array element with
    • Method Detail

      • read

        public java.lang.Object read​(InputNode node)
                              throws java.lang.Exception
        This read method will read the XML element list from the provided node and deserialize its children as entry types. This will deserialize each entry type as a primitive value. In order to do this the parent string provided forms the element.
        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 list)
                              throws java.lang.Exception
        This read method will read the XML element list from the provided node and deserialize its children as entry types. This will deserialize each entry type as a primitive value. In order to do this the parent string provided forms the element.
        Specified by:
        read in interface Converter
        Parameters:
        node - this is the XML element that is to be deserialized
        list - this is the array to read the array values in to
        Returns:
        this returns the item to attach to the object contact
        Throws:
        java.lang.Exception - if a deserialized type cannot be instantiated
      • validate

        public boolean validate​(InputNode node)
                         throws java.lang.Exception
        This validate method will validate the XML element list from the provided node and validate its children as entry types. This will validate each entry type as a primitive value. In order to do this the parent string provided forms the element.
        Specified by:
        validate in interface Converter
        Parameters:
        node - this is the XML element that is to be validated
        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 list from the provided node and validate its children as entry types. This will validate each entry type as a primitive value. In order to do this the parent string provided forms the element.
        Parameters:
        node - this is the XML element that is to be validated
        type - this is the array type used to create the array
        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 specified object to the given XML element as as array entries. Each entry within the given array must be assignable to the array component type. This will deserialize each entry type as a primitive value. In order to do this the parent string provided forms the element.
        Specified by:
        write in interface Converter
        Parameters:
        source - this is the source object array to be serialized
        node - this is the XML element container to be populated
        Throws:
        java.lang.Exception - throw if the object cannot be serialized
      • write

        private void write​(OutputNode node,
                           java.lang.Object source,
                           int index)
                    throws java.lang.Exception
        This write method will write the specified object to the given XML element as as array entries. Each entry within the given array must be assignable to the array component type. This will deserialize each entry type as a primitive value. In order to do this the parent string provided forms the element.
        Parameters:
        source - this is the source object array to be serialized
        node - this is the XML element container to be populated
        index - this is the position in the array to set the item
        Throws:
        java.lang.Exception
      • isOverridden

        private boolean isOverridden​(OutputNode node,
                                     java.lang.Object value)
                              throws java.lang.Exception
        This is used to determine whether the specified value has been overridden by the strategy. If the item has been overridden then no more serialization is require for that value, this is effectively telling the serialization process to stop writing.
        Parameters:
        node - the node that a potential override is written to
        value - this is the object instance to be serialized
        Returns:
        returns true if the strategy overrides the object
        Throws:
        java.lang.Exception