[jdom-interest] Subclassing Element vs Element Context

Dave Churchville dmc at clearlight.com
Sat Nov 4 16:16:00 PST 2000

Jehoiada Bernard wrote:
> For applications that navigate the document as a simple tree of Elements,
> how about simply being able to attach contextual information to an element?
> e.g., element.setContext(Object);  You could then color the tree with any
> information
> you wish without subclassing Element. This seems like a low impact change to
> the
> current design.

I somewhat agree with this, this is like Swing's "setUserObject()" on
TreeNodes.  That would be pretty useful and its not as controversial as
the other proposed enhancements to JDOM.

Its not *quite* as nice, though, as knowing the object you are dealing
with, since typical code would say:

Element myElement = rootElement.getChild("foo");
MyCustomObject o = (MyCustomObject) myElement.getUserObject();
o.setVisited( true);

instead of:

MyCustomElement e = (MyCustomElement) rootElement.getChild("foo");

But frankly, your approach does solve the problem, and it does so
without any significant impact that I can think of.


More information about the jdom-interest mailing list