Package org.simpleframework.xml.strategy
Interface Strategy
-
- All Known Implementing Classes:
AnnotationStrategy
,CycleStrategy
,RegistryStrategy
,TreeStrategy
,VisitorStrategy
public interface Strategy
TheStrategy
interface represents a strategy that can be used to resolve and load theClass
objects that compose a serializable object. A strategy implementation will make use of the provided attribute node map to extract details that can be used to determine what type of object must be used.<xml version="1.0"> <example class="some.example.Demo"> <integer>2</integer> </example>
The above example shows how the default strategy augments elements with "class" attributes that describe the type that should be used to instantiate a field when an object is deserialized. So looking at the above example the root element would be a "some.example.Demo".Custom
Strategy
implementations give the persister a chance to intercept the class loading and type resolution for XML documents. It also opens up the possibility for class versioning. To establish contextual information aMap
object can be used. The map object is a transient object that is created and used for the duration of a single operation of the persister.- Author:
- Niall Gallagher
- See Also:
Persister
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description Value
read(Type type, NodeMap<InputNode> node, java.util.Map map)
This is used to resolve and load a class for the given element.boolean
write(Type type, java.lang.Object value, NodeMap<OutputNode> node, java.util.Map map)
This is used to attach attribute values to the given node map during the serialization process.
-
-
-
Method Detail
-
read
Value read(Type type, NodeMap<InputNode> node, java.util.Map map) throws java.lang.Exception
This is used to resolve and load a class for the given element. The class should be of the same type or a subclass of the class specified. It can be resolved using the details within the provided XML node map, if the details used do not represent any serializable values they should be removed so as not to disrupt the deserialization process. For example the default strategy removes all "class" attributes from the given node map.- Parameters:
type
- this is the type of the root element expectednode
- this is the node map used to resolve an overridemap
- this is used to maintain contextual information- Returns:
- the value that should be used to describe the instance
- Throws:
java.lang.Exception
- thrown if the class cannot be resolved
-
write
boolean write(Type type, java.lang.Object value, NodeMap<OutputNode> node, java.util.Map map) throws java.lang.Exception
This is used to attach attribute values to the given node map during the serialization process. This method allows the strategy to augment the XML document so that it can be deserialized using a similar strategy. For example the default strategy adds a "class" attribute to the node map.- Parameters:
type
- this is the declared class for the field usedvalue
- this is the instance variable being serializednode
- this is the node map used to represent the valuemap
- this is used to maintain contextual information- Returns:
- this returns true if serialization is complete
- Throws:
java.lang.Exception
- thrown if the details cannot be set
-
-