[jdom-interest] Helper methods [eg]

Rosen, Alex arosen at silverstream.com
Wed Apr 18 18:28:00 PDT 2001

I would like to bring up the topic of adding helper methods to JDOM, so
mulitiple users don't have to write common routines themselves. I envision
these as static methods on one or more classes in a packaged named
org.jdom.helpers or org.jdom.util. Some possible examples include:

- Getters which would throw exceptions if the requested data is not available:
getRequiredAttribute(), getRequiredChild()...

- Getters and setters for datatypes, e.g. getIntAttributeValue(),
setIntAttributeValue(), getIntText(), setIntText(), getIntChildText()...

- Modification methods which preserve formatting - an addChild() method which
would add necessary indentation so the XML continued to look nice, and
removeChild() which removed the remaining whitespace so there wasn't a big
empty hole in the document.

- findChild(), which could find the child element with a specific attribute
value, for example.

Before getting bogged down on which methods to offer, the first question is: do
we want these helpers, and if so, should we try to provide a lot of helpers
that might be useful to some people, or only a few that will be the most useful
to the widest audience?

These helpers would make JDOM easier to use for all programmers. It would
prevent the same methods from having to be implemented over and over again by
different developers, each implementation which might have its own bugs. It
helps us keep the core API (Element, Document, etc.) to the minimum necessary,
by allowing us to add frequently-requested but non-essential methods somewhere
else. (For example, I think it would be great to move the getChildText() and
text-trimming methods here.)

Disadvantages: Hard to know when to stop adding helpers. There may be
significant differences of opinions on the desired behavior of some of the
methods. More API for users to learn (although not core API).

Any opinions?

Alex Rosen
SilverStream Software

More information about the jdom-interest mailing list