Built-in Visitor Pattern
JRDF nodes are implemented with a visitor pattern to provide an object oriented approach to node-type specific behaviour. Nodes implement the TypedNodeVisitable
interface and classes that use the pattern implement the TypedNodeVisitor
interface.
TypedNodeVisitable
Nodes implement the accept(TypedNodeVisitor visitor)
method to call visitor.visitXXX(this)
, where XXX
represents the node type. For example, visitBlankNode(this)
is called by a BlankNode.
TypedNodeVisitor
TypedNodeVisitors
implement three methods:
visitBlankNode(BlankNode blankNode)
visitLiteral(Literal literal)
visitURIReference(URIReference uriReference)
When a TypedNodeVisitor
calls accept(this)
on a TypedNodeVisitable(Node)
, the TypedNodeVisitable
calls the appropriate visitXXX()
method, where XXX
represents the Node type. The method names contain the node type to provide clarity for classes implementing the TypeNodeVisitor
interface.