[jdom-interest] A utility Element subclass and a request for API extension

Alex Rosen arosen at silverstream.com
Thu Mar 21 15:07:14 PST 2002

I am certainly sympathetic to this desire. For some uses of JDOM it makes
the API a lot more pleasant to use. But it's not obvious to me if it's worth
the tradeoff. I looked at this a while ago in a slightly different context -
getters instead of setters, and on a helper class to reduce core API size.


It just gets unwieldy pretty quickly. You'd want to limit yourself to 3-5
datatypes; if you added setters you'd also want getters; and you'd want to
do it for both attributes and text content. That's 12-20 new methods on
Element. (Plus would you want them in constructors for Attribute and Text?
Maybe that's overkill.) The getters introduce even more complexity - what do
you do if the attribute/text doesn't exist, throw an exception or have some
sort of default? What if it's not formatted properly? For that matter, for
the setter, does the double value 12.34 become "12.34" or "12,34"? Does it
depend on the locale? Ugh.

I could stomach it if we limited ourselves to int and boolean, which I think
are the 80% case or more. We'd have to explain that for anything else, you
have to do it yourself (which isn't that hard).


More information about the jdom-interest mailing list