[jdom-interest] API Inertia

Jason Hunter jhunter at acm.org
Mon Apr 30 19:37:06 PDT 2001


Brett McLaughlin wrote:
> 
> Traversing a tree, which is a 50 line example in DOM (weird
> structures and all) becomes a tremendous pain in JDOM; 

I believe the addition of a real tree traversal API in JDOM would go
farther to help with this than adding a Node interface containing two
methods and not changing anything else.  The Java way to walk a tree is
probably like this:

Iterator itr = doc.getContentIterator();
while (itr.hasNext()) {
  Object o = itr.next();
  // deal with o
}

Having a Node interface doesn't really help here because Iterator
returns Object.  Always will.  You could cast to Node but it'd be
useless until you downcast further.  So why not talk about adding the
above method (which is an idea in the TODO to investigate), rather than
talk about a Node interface with little value?

BTW, you could use a visitor pattern for walking too.

> writing the chapters on it. Additionally, with SOAP and things like that, I
> really am annoyed in having to get an "Object" back over the wire. I can't
> count on it being something that I can feed to, say, XMLOutputter. How nice
> would it be to pass a Node, or Item, or whatever, to the print() method of
> XMLOutputter? Pretty darn sweet. 

There's some value here.  But XMLOutputter would have to do an
instanceof search to determine what type of object it truly was and then
use different logic internally depending on the class, because Node
wouldn't have any helper methods to handle output.  That means you end
up with a print() method that accepts a general Node interface type but
in reality it can only *really* print a limited set of implementing
classes!  That's terrible style, a totally lying interface.

> Gets rid of all that serialized form crap, for one thing.

It's already gone.  :-)

>   Things like detach(). This would have never made it into the 
> original API, because we looked at it and said "Oh, here's how 
> you remove content: removeContent()." 

I actually discussed the idea before adding detach() months ago looking
for alternate ideas and *no one* said they didn't like detach().  It
really sucks to talk about ideas, hear nothing, implement them, and then
have everyone attack everything.

>   So I simply want to encourage everyone, myself included, to stop assuming
> that we are so close that big changes (like namespace handling and
> entities?!?) are bad. 

Umm, I'm confused what point you're making.  We're 110% changing the
Entity model as discussed in the report from the SD West BOF discussion
and listed in the TODO.  I don't think anyone's against drastic changes
just because they're drastic, but I am against changes that have serious
flaws, like Node.  I spent an entire afternoon working on making Node
work, and I realized every way I tried had dragons.  Now people are
throwing out many different approaches, and I'm reporting the problems I
found when I tried the very same thing that afternoon.

-jh-



More information about the jdom-interest mailing list