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

Patrick Dowler patrick.dowler at nrc.ca
Fri Mar 22 10:21:58 PST 2002


As some one who is using JDOM to read/write files with many primitive types
and who is converting them to/from the appropriate type, I'd have to say that
these methods are extraneous. 

Generally, one can confine these conversions to a few classes and then a
suitable overloaded method of the form 

         private String str( double d ) { ... }

makes the code look ok. It also means if you decide to switch from an implementation like

    return ++"d;

to

    return Double.toString( d );

to

    return NumberFormat.getInstance( locale ).format( d );  

you can do it in one place AND you get to decide/ which you need and change it if required.
It also makes sure users remian aware that XML is a text representation. Many people I
encounter forget that floating point values are not always represented properly as
strings... the term "blissfully unaware" comes to mind :-)

I don't think adding a lot of methods (and it is a lot!!) methods to the API is warranted.

On 21 March 2002 15:07, Alex Rosen wrote:
> 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.
>
> http://www.servlets.com/archive/servlet/ReadMsg?msgId=7909&listName=jdom-in
>t erest
>
> 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).
>
> Alex
>
> _______________________________________________
> To control your jdom-interest membership:
> http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourho
>st.com

-- 
Patrick Dowler
Canadian Astronomy Data Centre
National Research Council
Victoria, BC



More information about the jdom-interest mailing list