[jdom-interest] [eg] Traversal (was re: Need of GOF Visitor Pattern implemantation in JDOM? )

bob mcwhirter bob at werken.com
Sat May 12 08:21:09 PDT 2001


Well, if all we want is traversal, then add Document.iterator(..) or Element.iterator(...).

If you want to make it flexible:

	Iterator myIter = myDoc.iterator(Document.PRE_ORDER);

	Iterator myIter = myDoc.iterator(Document.POST_ORDER);

That'll give you the simple traversals you want, without the
weight (and benefits) provided by using a Visitor for convenient
double-dispatch.

	-bob


On Sat, 12 May 2001 philip.nelson at omniresources.com wrote:

> 
> > > But, now that you mention it, I still haven't figured out 
> > what the benefit
> > > of a
> > > visitor pattern is over what to me is the more straightforward way:
> <snip>
> 
> > I would do it like this.
> > 
> > Imagine org.jdom.Document
> > 
> >      public aceept(Visitor aVisitor)  {
> > 
> >         // ensurse call of adapter
> >         aVisitor.vist(this); 
> > 
> >        // visit attributs
> >        Iterator attributeIterator = this.getAttributes.iterator();
> >        while (attributeIterator.hasNext()) {
> > 
> >              ((Attribute)attributeIterator.next()).accept(aVisitor);
> > 
> >        }
> > 
> >        // vist elements
> >        // same as above applied to elements of document
> 
> While the idea of a Visitor generally appeals to me, I also think the real
> benefit comes when you do something as suggested above: the traversal is
> built into the jdom classes.  This is also the problem I have with it.
> Should I do a depth first or a breadth first traversal?  Should I have a way
> to stop traversing?  Should my traversal have a filter element?  Im sure
> there are more variations but the answer is always the same, maybe.  If you
> take the automatic traversal out and have the implementor of the visitor do
> it (assuming that's possible and easy) then I agree with Alex, I would
> rather traverse the document in a way that feels more natural.
> _______________________________________________
> To control your jdom-interest membership:
> http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhost.com
> 




More information about the jdom-interest mailing list