Package org.simpleframework.xml.convert
Class RegistryStrategy
- java.lang.Object
-
- org.simpleframework.xml.convert.RegistryStrategy
-
- All Implemented Interfaces:
Strategy
public class RegistryStrategy extends java.lang.Object implements Strategy
TheRegistryStrategy
object is used to intercept the serialization process and delegate to custom converters. The custom converters are resolved from aRegistry
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 theCycleStrategy
, which handles cycles in the object graph. To specify the internal strategy to use it can be provided in the constructor.- Author:
- Niall Gallagher
- See Also:
Registry
-
-
Constructor Summary
Constructors Constructor Description RegistryStrategy(Registry registry)
Constructor for theRegistryStrategy
object.RegistryStrategy(Registry registry, Strategy strategy)
Constructor for theRegistryStrategy
object.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Value
read(Type type, NodeMap<InputNode> node, java.util.Map map)
This is used to read theValue
which will be used to represent the deserialized object.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.
-
-
-
Constructor Detail
-
RegistryStrategy
public RegistryStrategy(Registry registry)
Constructor for theRegistryStrategy
object. This is used to create a strategy that will intercept the normal serialization process by searching for bindings within the providedRegistry
instance.- Parameters:
registry
- this is the registry instance with bindings
-
RegistryStrategy
public RegistryStrategy(Registry registry, Strategy strategy)
Constructor for theRegistryStrategy
object. This is used to create a strategy that will intercept the normal serialization process by searching for bindings within the providedRegistry
instance.- Parameters:
registry
- this is the registry instance with bindingsstrategy
- 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 theValue
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 interfaceStrategy
- Parameters:
type
- this is the type that represents a method or fieldnode
- this is the node representing the XML elementmap
- 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
-
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 aRegistry
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 interfaceStrategy
- Parameters:
type
- this is the type that represents the field or methodvalue
- this is the object instance to be serializednode
- this is the XML element to be serialized tomap
- 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
-
-