Package org.simpleframework.xml.strategy
Class VisitorStrategy
java.lang.Object
org.simpleframework.xml.strategy.VisitorStrategy
- All Implemented Interfaces:
Strategy
The
VisitorStrategy
object is a simplification of a
strategy, which allows manipulation of the serialization process.
Typically implementing a Strategy
is impractical as
it requires the implementation to determine the type a node
represents. Instead it is often easier to visit each node that
is being serialized or deserialized and manipulate it so that
the resulting XML can be customized.
To perform customization in this way a Visitor
can
be implemented. This can be passed to this strategy which will
ensure the visitor is given each XML element as it is either
being serialized or deserialized. Such an inversion of control
allows the nodes to be manipulated with little effort. By
default this used TreeStrategy
object as a default
strategy to delegate to. However, any strategy can be used.
- See Also:
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionVisitorStrategy
(Visitor visitor) Constructor for theVisitorStrategy
object.VisitorStrategy
(Visitor visitor, Strategy strategy) Constructor for theVisitorStrategy
object. -
Method Summary
Modifier and TypeMethodDescriptionThis method will read with an internal strategy after it has been intercepted by the visitor.boolean
This method will write with an internal strategy before it has been intercepted by the visitor.
-
Field Details
-
strategy
This is the strategy that is delegated to by this strategy. -
visitor
This is the visitor that is used to intercept serialization.
-
-
Constructor Details
-
VisitorStrategy
Constructor for theVisitorStrategy
object. This strategy requires a visitor implementation that can be used to intercept the serialization and deserialization process.- Parameters:
visitor
- this is the visitor used for interception
-
VisitorStrategy
Constructor for theVisitorStrategy
object. This strategy requires a visitor implementation that can be used to intercept the serialization and deserialization process.- Parameters:
visitor
- this is the visitor used for interceptionstrategy
- this is the strategy to be delegated to
-
-
Method Details
-
read
This method will read with an internal strategy after it has been intercepted by the visitor. Interception of the XML node before it is delegated to the internal strategy allows the visitor to change some attributes or details before the node is interpreted by the strategy.- Specified by:
read
in interfaceStrategy
- 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:
Exception
- thrown if the class cannot be resolved
-
write
This method will write with an internal strategy before it has been intercepted by the visitor. Interception of the XML node before it is delegated to the internal strategy allows the visitor to change some attributes or details before the node is interpreted by the strategy.- Specified by:
write
in interfaceStrategy
- Parameters:
type
- this is the type of the root element expectedvalue
- this is the instance variable being serializednode
- 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:
Exception
- thrown if the details cannot be set
-