[jdom-interest] API Inertia

Trimmer, Todd todd.trimmer at trizetto.com
Wed May 2 13:09:10 PDT 2001


Ok, and how will we traverse from Node to Node ?

"We can put responsibility for traversal in any of three places: in the
object structure, in the visitor, or in a separator iterator object (see
Iterator (257))." -- GoF 339

1) Traversal isn't already consistent in JDOM.
2) Your example Visitable interface doesn't provide traversal.
3) "extends Visitor". Visitor who? Does he do traversal?
4) There is no XMLIterator in your example either.


Todd Trimmer


----- Original Message ----- 
rom: "Joseph Bowbeer" <jozart at csi.com>
To: <jdom-interest at jdom.org>
Date: Wed, 2 May 2001 03:25:26 -0700
Subject: [jdom-interest] API Inertia

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();
        node.accept(visitor);
        return visitor.value;
    }

--
Joe Bowbeer



More information about the jdom-interest mailing list