Class RegistryStrategy

  • All Implemented Interfaces:
    Strategy

    public class RegistryStrategy
    extends java.lang.Object
    implements Strategy
    The RegistryStrategy object is used to intercept the serialization process and delegate to custom converters. The custom converters are resolved from a Registry object, which is provided to the constructor. If there is no binding for a particular object then serialization is delegated to an internal strategy. All converters resolved by this are instantiated once and cached internally for performance.

    By default the TreeStrategy is used to perform the normal serialization process should there be no class binding specifying a converter to use. However, any implementation can be used, including the CycleStrategy, which handles cycles in the object graph. To specify the internal strategy to use it can be provided in the constructor.

    See Also:
    Registry
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private Registry registry
      This is the registry that is used to resolve bindings.
      private Strategy strategy
      This is the strategy used if there is no bindings.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private boolean isReference​(Value value)
      This is used to determine if the Value provided represents a reference.
      private Converter lookup​(Type type, java.lang.Object value)
      This is used to acquire a Converter instance for the provided object instance.
      private Converter lookup​(Type type, Value value)
      This is used to acquire a Converter instance for the provided value object.
      Value read​(Type type, NodeMap<InputNode> node, java.util.Map map)
      This is used to read the Value which will be used to represent the deserialized object.
      private Value read​(Type type, NodeMap<InputNode> node, Value value)
      This is used to read the Value which will be used to represent the deserialized object.
      private boolean write​(Type type, java.lang.Object value, NodeMap<OutputNode> node)
      This is used to serialize a representation of the object value provided.
      boolean write​(Type type, java.lang.Object value, NodeMap<OutputNode> node, java.util.Map map)
      This is used to serialize a representation of the object value provided.
      • Methods inherited from class java.lang.Object

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

      • registry

        private final Registry registry
        This is the registry that is used to resolve bindings.
      • strategy

        private final Strategy strategy
        This is the strategy used if there is no bindings.
    • Constructor Detail

      • RegistryStrategy

        public RegistryStrategy​(Registry registry)
        Constructor for the RegistryStrategy object. This is used to create a strategy that will intercept the normal serialization process by searching for bindings within the provided Registry instance.
        Parameters:
        registry - this is the registry instance with bindings
      • RegistryStrategy

        public RegistryStrategy​(Registry registry,
                                Strategy strategy)
        Constructor for the RegistryStrategy object. This is used to create a strategy that will intercept the normal serialization process by searching for bindings within the provided Registry instance.
        Parameters:
        registry - this is the registry instance with bindings
        strategy - this is the strategy to delegate to
    • Method Detail

      • read

        public Value read​(Type type,
                          NodeMap<InputNode> node,
                          java.util.Map map)
                   throws java.lang.Exception
        This is used to read the Value which will be used to represent the deserialized object. If there is an binding present then the value will contain an object instance. If it does not then it is up to the internal strategy to determine what the returned value contains.
        Specified by:
        read in interface Strategy
        Parameters:
        type - this is the type that represents a method or field
        node - this is the node representing the XML element
        map - this is the session map that contain variables
        Returns:
        the value representing the deserialized value
        Throws:
        java.lang.Exception - thrown if the class cannot be resolved
      • read

        private Value read​(Type type,
                           NodeMap<InputNode> node,
                           Value value)
                    throws java.lang.Exception
        This is used to read the Value which will be used to represent the deserialized object. If there is an binding present then the value will contain an object instance. If it does not then it is up to the internal strategy to determine what the returned value contains.
        Parameters:
        type - this is the type that represents a method or field
        node - this is the node representing the XML element
        value - this is the value from the internal strategy
        Returns:
        the value representing the deserialized value
        Throws:
        java.lang.Exception
      • write

        public boolean write​(Type type,
                             java.lang.Object value,
                             NodeMap<OutputNode> node,
                             java.util.Map map)
                      throws java.lang.Exception
        This is used to serialize a representation of the object value provided. If there is a Registry binding present for the provided type then this will use the converter specified to serialize a representation of the object. If however there is no binding present then this will delegate to the internal strategy. This returns true if the serialization has completed.
        Specified by:
        write in interface Strategy
        Parameters:
        type - this is the type that represents the field or method
        value - this is the object instance to be serialized
        node - this is the XML element to be serialized to
        map - this is the session map used by the serializer
        Returns:
        this returns true if it was serialized, false otherwise
        Throws:
        java.lang.Exception - thrown if the details cannot be set
      • write

        private boolean write​(Type type,
                              java.lang.Object value,
                              NodeMap<OutputNode> node)
                       throws java.lang.Exception
        This is used to serialize a representation of the object value provided. If there is a Registry binding present for the provided type then this will use the converter specified to serialize a representation of the object. If however there is no binding present then this will delegate to the internal strategy. This returns true if the serialization has completed.
        Parameters:
        type - this is the type that represents the field or method
        value - this is the object instance to be serialized
        node - this is the XML element to be serialized to
        Returns:
        this returns true if it was serialized, false otherwise
        Throws:
        java.lang.Exception
      • lookup

        private Converter lookup​(Type type,
                                 Value value)
                          throws java.lang.Exception
        This is used to acquire a Converter instance for the provided value object. The value object is used to resolve the converter to use for the serialization process.
        Parameters:
        type - this is the type representing the field or method
        value - this is the value that is to be serialized
        Returns:
        this returns the converter instance that is matched
        Throws:
        java.lang.Exception
      • lookup

        private Converter lookup​(Type type,
                                 java.lang.Object value)
                          throws java.lang.Exception
        This is used to acquire a Converter instance for the provided object instance. The instance class is used to resolve the converter to use for the serialization process.
        Parameters:
        type - this is the type representing the field or method
        value - this is the value that is to be serialized
        Returns:
        this returns the converter instance that is matched
        Throws:
        java.lang.Exception
      • isReference

        private boolean isReference​(Value value)
        This is used to determine if the Value provided represents a reference. If it does represent a reference then this will return true, if it does not then this returns false.
        Parameters:
        value - this is the value instance to be evaluated
        Returns:
        this returns true if the value represents a reference