[jdom-interest] API Inertia

Joseph Bowbeer jozart at csi.com
Wed May 2 03:25:26 PDT 2001

PS - Here's an attempt to show a simple Visitor example:

For example, the XPath getValue method for Attribute, Element, etc.
could be implemented using a XPathValueVisitor.

This would require that every object in a document implement Visitable.

    interface Visitable {
        void accept(Visitor visitor);

The XPathValueVisitor computes the value appropriate for the particular
visitable instance:

    class XPathValueVisitor extends Visitor {
        Object value;
        void visitElement(Element element) {
            value = element.whatever();
        void visitAttribute(Attribute attribute) {
            value = attribute.whatever();
        // ...etc...

The XPath value would be retrieved as follows:

    Object getValue(Visitable node) {
        XPathValueVisitor visitor = new XPathValueVisitor();
        return visitor.value;

Joe Bowbeer

More information about the jdom-interest mailing list