Class CompositeInlineList

  • All Implemented Interfaces:
    Converter, Repeater

    class CompositeInlineList
    extends java.lang.Object
    implements Repeater
    The CompositeInlineList object is used to convert an group of elements in to a collection of element entries. This is used when a containing element for a list is not required. It extracts the elements by matching elements to name of the type that the annotated field or method requires. This enables these element entries to exist as siblings to other objects within the object. One restriction is that the Root annotation for each of the types within the list must be the same.
     
        
        <entry attribute="one">
           <text>example text value</text>
        </entry>
        <entry attribute="two">
           <text>some other example</text>
        </entry>  
        <entry attribute="three">
           <text>yet another example</text>
        </entry>      
     
     
    For the above XML element list the element entry is contained within the list. Each entry element is thus deserialized as a root element and then inserted into the list. This enables lists to be composed from XML documents. For serialization the reverse is done, each element taken from the collection is written as a root element to the owning element to create the list. Entry objects do not need to be of the same type.
    See Also:
    Traverser, ElementList
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private Type entry
      This is the entry type for elements within the list.
      private CollectionFactory factory
      This factory is used to create a suitable collection list.
      private java.lang.String name
      This represents the name of the entry elements to write.
      private Traverser root
      This performs the traversal used for object serialization.
      private Type type
      This represents the actual method or field for the list.
    • Constructor Summary

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

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.Object read​(InputNode node)
      This read method wll read the XML element list from the provided node and deserialize its children as entry types.
      private java.lang.Object read​(InputNode node, java.lang.Class expect)
      This read method will read the XML element from the provided node.
      java.lang.Object read​(InputNode node, java.lang.Object value)
      This read method will read the XML element list from the provided node and deserialize its children as entry types.
      private java.lang.Object read​(InputNode node, java.util.Collection list)
      This read method wll read the XML element list from the provided node and deserialize its children as entry types.
      boolean validate​(InputNode node)
      This read method will read the XML element list from the provided node and deserialize 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 list entries.
      void write​(OutputNode node, java.util.Collection list)
      This write method will write the specified object to the given XML element as as list entries.
      • Methods inherited from class java.lang.Object

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

      • factory

        private final CollectionFactory factory
        This factory is used to create a suitable collection list.
      • root

        private final Traverser root
        This performs the traversal used for object serialization.
      • name

        private final java.lang.String name
        This represents the name of the entry elements to write.
      • entry

        private final Type entry
        This is the entry type for elements within the list.
      • type

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

      • CompositeInlineList

        public CompositeInlineList​(Context context,
                                   Type type,
                                   Type entry,
                                   java.lang.String name)
        Constructor for the CompositeInlineList object. This is given the list type and entry type to be used. The list type is the Collection implementation that is used to collect the deserialized entry objects from the XML source.
        Parameters:
        context - this is the context object used for serialization
        type - this is the collection type for the list used
        entry - the entry type to be stored within the list
        name - this is the name of the entries used for this list
    • Method Detail

      • read

        public java.lang.Object read​(InputNode node)
                              throws java.lang.Exception
        This read method wll read the XML element list from the provided node and deserialize its children as entry types. This will each entry type is deserialized as a root type, that is, its Root annotation must be present and the name of the entry 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 value)
                              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 each entry type is deserialized as a root type, that is, its Root annotation must be present and the name of the entry element must match that root element name.
        Specified by:
        read in interface Converter
        Specified by:
        read in interface Repeater
        Parameters:
        node - this is the XML element that is to be deserialized
        value - this is the value to read the objects in to
        Returns:
        this returns the item to attach to the object contact
        Throws:
        java.lang.Exception - if a deserialized type cannot be instantiated
      • read

        private java.lang.Object read​(InputNode node,
                                      java.util.Collection list)
                               throws java.lang.Exception
        This read method wll read the XML element list from the provided node and deserialize its children as entry types. This will each entry type is deserialized as a root type, that is, its Root annotation must be present and the name of the entry element must match that root element name.
        Parameters:
        node - this is the XML element that is to be deserialized
        list - this is the collection that is to be populated
        Returns:
        this returns the item to attach to the object contact
        Throws:
        java.lang.Exception
      • read

        private java.lang.Object read​(InputNode node,
                                      java.lang.Class expect)
                               throws java.lang.Exception
        This read method will read the XML element from the provided node. This checks to ensure that the deserialized type is the same as the entry type provided. If the types are not the same then an exception is thrown. This is done to ensure each node in the collection contain the same root annotation.
        Parameters:
        node - this is the XML element that is to be deserialized
        expect - this is the type expected of the deserialized type
        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 read method will read the XML element list from the provided node and deserialize its children as entry types. This will each entry type is deserialized as a root type, that is, its Root annotation must be present and the name of the entry element must match that root element name.
        Specified by:
        validate 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 the class XML schema does not fully match
      • 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 list entries. Each entry within the given collection must be assignable from the annotated type specified within the ElementList annotation. Each entry is serialized as a root element, that is, its Root annotation is used to extract the name.
        Specified by:
        write in interface Converter
        Parameters:
        source - this is the source collection 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

        public void write​(OutputNode node,
                          java.util.Collection list)
                   throws java.lang.Exception
        This write method will write the specified object to the given XML element as as list entries. Each entry within the given collection must be assignable from the annotated type specified within the ElementList annotation. Each entry is serialized as a root element, that is, its Root annotation is used to extract the name.
        Parameters:
        list - this is the source collection to be serialized
        node - this is the XML element container to be populated
        Throws:
        java.lang.Exception