Class CompositeMapUnion

java.lang.Object
org.simpleframework.xml.core.CompositeMapUnion
All Implemented Interfaces:
Converter, Repeater

class CompositeMapUnion extends Object implements Repeater
The CompositeMapUnion object is used to act as a mediator for multiple converters associated with a particular union group. This will basically determine which Converter should be delegated to based on either the XML element name being read or the type of the instance object being written. Selection of the converter is done by consulting the Group of labels representing the union declaration.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final Context
    This is the current context used for the serialization.
    private final LabelMap
    This contains the labels in the union group keyed by name.
    private final Group
    This contains the group of labels associated with the union.
    private final Expression
    This is the path expression used to represent this union.
    private final Style
    This is this style associated with the serialization context.
    private final Type
    This is the type field or method annotated as a union.
  • Constructor Summary

    Constructors
    Constructor
    Description
    CompositeMapUnion(Context context, Group group, Expression path, Type type)
    Constructor for the CompositeMapUnion object.
  • Method Summary

    Modifier and Type
    Method
    Description
    The read method uses the name of the XML element to select a converter to be used to read the instance.
    read(InputNode node, Object value)
    The read method uses the name of the XML element to select a converter to be used to read the instance.
    boolean
    The validate method is used to validate the XML element provided using an associated class schema.
    void
    write(OutputNode node, Object source)
    The write method uses the name of the XML element to select a converter to be used to write the instance.
    private void
    write(OutputNode node, Object key, Object item, Label label)
    The write method uses the name of the XML element to select a converter to be used to write the instance.
    private void
    write(OutputNode node, Map map)
    The write method uses the name of the XML element to select a converter to be used to write the instance.

    Methods inherited from class java.lang.Object

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

    • elements

      private final LabelMap elements
      This contains the labels in the union group keyed by name.
    • path

      private final Expression path
      This is the path expression used to represent this union.
    • context

      private final Context context
      This is the current context used for the serialization.
    • group

      private final Group group
      This contains the group of labels associated with the union.
    • style

      private final Style style
      This is this style associated with the serialization context.
    • type

      private final Type type
      This is the type field or method annotated as a union.
  • Constructor Details

    • CompositeMapUnion

      public CompositeMapUnion(Context context, Group group, Expression path, Type type) throws Exception
      Constructor for the CompositeMapUnion object. This is used to create a converter that delegates to other associated converters within the union group depending on the XML element name being read or the instance type that is being written.
      Parameters:
      context - this is the context used for the serialization
      group - this is the union group used for delegation
      path - this is the path expression representing this union
      type - this is the annotated field or method to be used
      Throws:
      Exception
  • Method Details

    • read

      public Object read(InputNode node) throws Exception
      The read method uses the name of the XML element to select a converter to be used to read the instance. Selection of the converter is done by looking up the associated label from the union group using the element name. Once the converter has been selected it is used to read the instance.
      Specified by:
      read in interface Converter
      Parameters:
      node - this is the XML element used to read the instance
      Returns:
      this is the instance that has been read by this
      Throws:
      Exception - if a deserialized type cannot be instantiated
    • read

      public Object read(InputNode node, Object value) throws Exception
      The read method uses the name of the XML element to select a converter to be used to read the instance. Selection of the converter is done by looking up the associated label from the union group using the element name. Once the converter has been selected it is used to read the instance.
      Specified by:
      read in interface Converter
      Specified by:
      read in interface Repeater
      Parameters:
      node - this is the XML element used to read the instance
      value - this is the value that is to be repeated
      Returns:
      this is the instance that has been read by this
      Throws:
      Exception - if a deserialized type cannot be instantiated
    • validate

      public boolean validate(InputNode node) throws Exception
      The validate method is used to validate the XML element provided using an associated class schema. The schema is selected using the name of the XML element to acquire the associated converter. Once the converter has been acquired it is delegated to and validated against it.
      Specified by:
      validate in interface Converter
      Parameters:
      node - this is the input XML element to be validated
      Returns:
      this returns true if the node validates
      Throws:
      Exception - if the class XML schema does not fully match
    • write

      public void write(OutputNode node, Object source) throws Exception
      The write method uses the name of the XML element to select a converter to be used to write the instance. Selection of the converter is done by looking up the associated label from the union group using the instance type. Once the converter has been selected it is used to write the instance.
      Specified by:
      write in interface Converter
      Parameters:
      node - this is the XML element used to write the instance
      source - this is the value that is to be written
      Throws:
      Exception - throw if the object cannot be serialized
    • write

      private void write(OutputNode node, Map map) throws Exception
      The write method uses the name of the XML element to select a converter to be used to write the instance. Selection of the converter is done by looking up the associated label from the union group using the instance type. Once the converter has been selected it is used to write the instance.
      Parameters:
      node - this is the XML element used to write the instance
      map - this is the value that is to be written
      Throws:
      Exception
    • write

      private void write(OutputNode node, Object key, Object item, Label label) throws Exception
      The write method uses the name of the XML element to select a converter to be used to write the instance. Selection of the converter is done by looking up the associated label from the union group using the instance type. Once the converter has been selected it is used to write the instance.
      Parameters:
      node - this is the XML element used to write the instance
      key - this is the key associated with the item to write
      item - this is the value associated with the item to write
      label - this is the label to used to acquire the converter
      Throws:
      Exception