[jdom-interest] JDOM JSR

James Strachan james_strachan at yahoo.co.uk
Thu May 17 08:36:19 PDT 2001


Hi Alex

> I think that dom4j is better if you have to subclass, while JDOM is better
if
> you don't.
>
> (I'm sure there are people (particularly the authors) who will disagree
with
> each of those statements.)
>
> I like to think of the java.io.File class as a very JDOM-like class.
There's a
> reason we say:
>
>   File parent = new File(filepath);
>   File child = new File(parent, "aaa.txt");
>
> rather than:
>
>   FileSystem fs = FileSystem.getDefaultFileSystem();
>   File parent = fs.getFile(filepath);
>   File child = fs.getFile(parent, "aaa.txt");

Good example Alex  (though a pedant would say File is a lightweight bean,
its not really a data structure like the Java Collections Framework or XML
document models and there's little implementation choices for a File).

Continuing your File analogy, if JDOM is like File then dom4j is more like
the URL class in the JDK. The URL can deal with both simple Files together
with more complex HTTP / HTTPS / FTP / JNDI protocols too in a polymorphic
manner, using interfaces and factories which are hidden to a certain extent
under a fairly simple URL API. Though the trade off is that the URL class is
a little more complex to use than the File but its much more flexible.
Sometimes URL can be faster to use too (e.g. Tomcat 4.0 uses jndi: URLs
rather than Files for performance). Also the URL allows advanced users to
create their own handlers if they wish which other users may use, though as
a user you may just use one of the existing URL implementations.

The idea being you may not conciously wish to subclass in dom4j, you just
might want to take advantage of alternate implementations that someone else
has written such as XML Schema aware Document implementations, high
performance "deferred" or "lazy" parsing XML trees or native DOM support for
more efficient integration purposes etc.

So the File v URL analogy is quite a good one I think. Both have strengths
and weaknesses. Like most things in IT, no one size fits all.

James


_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com




More information about the jdom-interest mailing list