Class CompositeKey

java.lang.Object
org.simpleframework.xml.core.CompositeKey
All Implemented Interfaces:
Converter

class CompositeKey extends Object implements Converter
The CompositeKey object is used to convert an object to an from an XML element. This accepts only composite objects and will throw an exception if the ElementMap annotation is configured to have an attribute key. If a key name is given for the annotation then this will act as a parent element to the resulting XML element for the composite object.
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final Context
    This is the context used to support the serialization process.
    private final Entry
    This is the entry object used to provide configuration details.
    private final Traverser
    This is the traverser used to read and write the composite key.
    private final Style
    This is the style used to style the names used for the XML.
    private final Type
    This represents the type of object the key is written as.
  • Constructor Summary

    Constructors
    Constructor
    Description
    CompositeKey(Context context, Entry entry, Type type)
    Constructor for the CompositeKey object.
  • Method Summary

    Modifier and Type
    Method
    Description
    This method is used to read the key value from the node.
    read(InputNode node, Object value)
    This method is used to read the key value from the node.
    private Object
    read(InputNode node, String key)
    This method is used to read the key value from the node.
    boolean
    This method is used to read the key value from the node.
    private boolean
    This method is used to read the key value from the node.
    void
    write(OutputNode node, Object item)
    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 Details

    • context

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

      private final Traverser root
      This is the traverser used to read and write the composite key.
    • style

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

      private final Entry entry
      This is the entry object used to provide configuration details.
    • type

      private final Type type
      This represents the type of object the key is written as.
  • Constructor Details

    • CompositeKey

      public CompositeKey(Context context, Entry entry, Type type) throws Exception
      Constructor for the CompositeKey object. This will create an object capable of reading an writing composite keys from an XML element. This also allows a parent element to be created to wrap the key object if desired.
      Parameters:
      context - this is the root context for the serialization
      entry - this is the entry object used for configuration
      type - this is the type of object the key represents
      Throws:
      Exception
  • Method Details

    • read

      public Object read(InputNode node) throws Exception
      This method is used to read the key value from the node. The value read from the node is resolved using the template filter. If the key value can not be found according to the annotation attributes then null is assumed and returned.
      Specified by:
      read in interface Converter
      Parameters:
      node - this is the node to read the key value from
      Returns:
      this returns the value deserialized from the node
      Throws:
      Exception - if a deserialized type cannot be instantiated
    • read

      public Object read(InputNode node, Object value) throws Exception
      This method is used to read the key value from the node. The value read from the node is resolved using the template filter. If the key value can not be found according to the annotation attributes then null is assumed and returned.
      Specified by:
      read in interface Converter
      Parameters:
      node - this is the node to read the key value from
      value - this is the value to deserialize in to
      Returns:
      this returns the value deserialized from the node
      Throws:
      Exception - if value is not null an exception is thrown
    • read

      private Object read(InputNode node, String key) throws Exception
      This method is used to read the key value from the node. The value read from the node is resolved using the template filter. If the key 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 key value from
      key - this is the name of the key wrapper XML element
      Returns:
      this returns the value deserialized from the node
      Throws:
      Exception
    • validate

      public boolean validate(InputNode node) throws Exception
      This method is used to read the key value from the node. The value read from the node is resolved using the template filter. If the key 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 key value from
      Returns:
      this returns the value deserialized from the node
      Throws:
      Exception - if the class XML schema does not fully match
    • validate

      private boolean validate(InputNode node, String key) throws Exception
      This method is used to read the key value from the node. The value read from the node is resolved using the template filter. If the key 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 key value from
      key - this is the name of the key wrapper XML element
      Returns:
      this returns the value deserialized from the node
      Throws:
      Exception
    • write

      public void write(OutputNode node, Object item) throws Exception
      This method is used to write the value to the specified node. The value written to the node must be a composite object and if the element map annotation is configured to have a key attribute then this method will throw an exception.
      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:
      Exception - throw if the object cannot be serialized