public class VisitorStrategy extends Object implements Strategy
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.
Visitor
Constructor and Description |
---|
VisitorStrategy(Visitor visitor)
Constructor for the
VisitorStrategy object. |
VisitorStrategy(Visitor visitor,
Strategy strategy)
Constructor for the
VisitorStrategy object. |
Modifier and Type | Method and Description |
---|---|
Value |
read(Type type,
NodeMap<InputNode> node,
Map map)
This method will read with an internal strategy after it has
been intercepted by the visitor.
|
boolean |
write(Type type,
Object value,
NodeMap<OutputNode> node,
Map map)
This method will write with an internal strategy before it has
been intercepted by the visitor.
|
public VisitorStrategy(Visitor visitor)
VisitorStrategy
object. This
strategy requires a visitor implementation that can be used
to intercept the serialization and deserialization process.visitor
- this is the visitor used for interceptionpublic VisitorStrategy(Visitor visitor, Strategy strategy)
VisitorStrategy
object. This
strategy requires a visitor implementation that can be used
to intercept the serialization and deserialization process.visitor
- this is the visitor used for interceptionstrategy
- this is the strategy to be delegated topublic Value read(Type type, NodeMap<InputNode> node, Map map) throws Exception
read
in interface Strategy
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 informationException
- thrown if the class cannot be resolvedpublic boolean write(Type type, Object value, NodeMap<OutputNode> node, Map map) throws Exception
write
in interface Strategy
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 informationvalue
- this is the instance variable being serializedException
- thrown if the details cannot be set