Class PrimitiveValue

  • All Implemented Interfaces:
    Converter

    class PrimitiveValue
    extends java.lang.Object
    implements Converter
    The PrimitiveValue is used to serialize a primitive value to and from a node. If a value name is provided in the annotation then this will serialize and deserialize that value with the given name, if the value is primitive and no name is specified then the value is written inline, that is without any enclosing XML element.
     
        <entry key="one">example one</entry>
        <entry key="two">example two</entry>
        <entry key="three">example three</entry>    
     
     
    Allowing the value to be written as either an XML element or an inline text value enables a more flexible means for representing the value. The only condition for having an inline value is that the key is specified as an attribute in the annotation.
    See Also:
    CompositeMap
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private Context context
      This is the context used to support the serialization process.
      private Entry entry
      The entry object contains the details on how to write the value.
      private PrimitiveFactory factory
      The primitive factory used to resolve the primitive to a string.
      private Primitive root
      The primitive converter used to read the value from the node.
      private Style style
      This is the style used to style the XML names for the value.
      private Type type
      Represents the primitive type the value is serialized to and from.
    • Constructor Summary

      Constructors 
      Constructor Description
      PrimitiveValue​(Context context, Entry entry, Type type)
      Constructor for the PrimitiveValue 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 method is used to read the value value from the node.
      java.lang.Object read​(InputNode node, java.lang.Object value)
      This method is used to read the value value from the node.
      private java.lang.Object readAttribute​(InputNode node, java.lang.String name)
      This method is used to read the text value from the node.
      private java.lang.Object readElement​(InputNode node, java.lang.String key)
      This method is used to read the element value from the node.
      boolean validate​(InputNode node)
      This method is used to validate the value from the node.
      private boolean validateAttribute​(InputNode node, java.lang.String key)
      This method is used to validate the value from the node.
      private boolean validateElement​(InputNode node, java.lang.String key)
      This method is used to validate the value from the node.
      void write​(OutputNode node, java.lang.Object item)
      This method is used to write the value to the specified node.
      private void writeAttribute​(OutputNode node, java.lang.Object item, java.lang.String key)
      This method is used to write the value to the specified node.
      private void writeElement​(OutputNode node, java.lang.Object item, java.lang.String key)
      This method is used to write the value to the specified node.
      • Methods inherited from class java.lang.Object

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

      • factory

        private final PrimitiveFactory factory
        The primitive factory used to resolve the primitive to a string.
      • context

        private final Context context
        This is the context used to support the serialization process.
      • root

        private final Primitive root
        The primitive converter used to read the value from the node.
      • style

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

        private final Entry entry
        The entry object contains the details on how to write the value.
      • type

        private final Type type
        Represents the primitive type the value is serialized to and from.
    • Constructor Detail

      • PrimitiveValue

        public PrimitiveValue​(Context context,
                              Entry entry,
                              Type type)
        Constructor for the PrimitiveValue object. This is used to create the value object which converts the map value to an instance of the value type. This can also resolve references.
        Parameters:
        context - this is the context object used for serialization
        entry - this is the entry object that describes entries
        type - this is the type that this converter deals with
    • Method Detail

      • read

        public java.lang.Object read​(InputNode node)
                              throws java.lang.Exception
        This method is used to read the value value from the node. The value read from the node is resolved using the template filter. If the value value can not be found according to the annotation attributes then an exception is thrown.
        Specified by:
        read in interface Converter
        Parameters:
        node - this is the node to read the value object from
        Returns:
        this returns the value deserialized from the node
        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 method is used to read the value value from the node. The value read from the node is resolved using the template filter. If the value value can not be found according to the annotation attributes then an exception is thrown.
        Specified by:
        read in interface Converter
        Parameters:
        node - this is the node to read the value object from
        value - this is the value to deserialize in to
        Returns:
        this returns the value deserialized from the node
        Throws:
        java.lang.Exception - if value is not null an exception is thrown
      • readElement

        private java.lang.Object readElement​(InputNode node,
                                             java.lang.String key)
                                      throws java.lang.Exception
        This method is used to read the element value from the node. The value read from the node is resolved using the template filter. If the value value can not be found according to the annotation attributes then null is assumed and returned.
        Parameters:
        node - this is the node to read the value object from
        key - this is the name of the value XML element
        Returns:
        this returns the value deserialized from the node
        Throws:
        java.lang.Exception
      • readAttribute

        private java.lang.Object readAttribute​(InputNode node,
                                               java.lang.String name)
                                        throws java.lang.Exception
        This method is used to read the text value from the node. The value read from the node is resolved using the template filter. If the value value can not be found according to the annotation attributes then null is assumed and returned.
        Parameters:
        node - this is the node to read the value object from
        name - this is the name of the value XML attribute, if any
        Returns:
        this returns the value deserialized from the node
        Throws:
        java.lang.Exception
      • validate

        public boolean validate​(InputNode node)
                         throws java.lang.Exception
        This method is used to validate the value from the node. The value read from the node is resolved using the template filter. If the value value can not be found according to the annotation attributes then null is assumed and the node is valid.
        Specified by:
        validate in interface Converter
        Parameters:
        node - this is the node to read the value object from
        Returns:
        this returns true if the primitive key is valid
        Throws:
        java.lang.Exception - if the class XML schema does not fully match
      • validateElement

        private boolean validateElement​(InputNode node,
                                        java.lang.String key)
                                 throws java.lang.Exception
        This method is used to validate the value from the node. The value read from the node is resolved using the template filter. If the value value can not be found according to the annotation attributes then null is assumed and the node is valid.
        Parameters:
        node - this is the node to read the value object from
        key - this is the name of the node to be validated
        Returns:
        this returns true if the primitive key is valid
        Throws:
        java.lang.Exception
      • validateAttribute

        private boolean validateAttribute​(InputNode node,
                                          java.lang.String key)
                                   throws java.lang.Exception
        This method is used to validate the value from the node. The value read from the node is resolved using the template filter. If the value value can not be found according to the annotation attributes then null is assumed and the node is valid.
        Parameters:
        node - this is the node to read the value object from
        key - this is the name of the node to be validated
        Returns:
        this returns true if the primitive key is valid
        Throws:
        java.lang.Exception
      • write

        public void write​(OutputNode node,
                          java.lang.Object item)
                   throws java.lang.Exception
        This method is used to write the value to the specified node. The value written to the node can be an attribute or an element depending on the annotation attribute values. This method will maintain references for serialized elements.
        Specified by:
        write in interface Converter
        Parameters:
        node - this is the node that the value is written to
        item - this is the item that is to be written
        Throws:
        java.lang.Exception - throw if the object cannot be serialized
      • writeElement

        private void writeElement​(OutputNode node,
                                  java.lang.Object item,
                                  java.lang.String key)
                           throws java.lang.Exception
        This method is used to write the value to the specified node. The value written to the node can be an attribute or an element depending on the annotation attribute values. This method will maintain references for serialized elements.
        Parameters:
        node - this is the node that the value is written to
        item - this is the item that is to be written
        key - this is the name of the element to be created
        Throws:
        java.lang.Exception
      • writeAttribute

        private void writeAttribute​(OutputNode node,
                                    java.lang.Object item,
                                    java.lang.String key)
                             throws java.lang.Exception
        This method is used to write the value to the specified node. The value written to the node can be an attribute or an element depending on the annotation attribute values. This method will maintain references for serialized elements.
        Parameters:
        node - this is the node that the value is written to
        item - this is the item that is to be written
        key - this is the name of the attribute to be created
        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