Java Mailing List Archive

Home » JDOM Projects »

[jdom-interest] suggested JDOM2 improvements

Thomas Scheffler


Replies: Find Java Web Hosting

Author LoginPost Reply

first I want to thank all on working on JDOM2. While going over the
Javadocs I noticed some issues and got some ideas I want to share.

When creating a XPath instance, the instance should be unmodifiable, e.g.

remove setNamespace() methods and use

XPathFactory.newInstance().compile(String xpath, Namespace... namespaces)

One thing that is left then is variables and XPath instances should be
threadsafe then. One way to achieve this would be to create a
XPathVariable class and use var-args on selectNodes:

xPath.selectNodes(NamespaceAware context, XPathVariable... variables)

Then you can improve the XPathFactory on using a weak cache that always
returns the same instance. This would not only allow to share a XPath
instance across multiple threads but also decrease memory consumption.


What I would take into consideration is allow generics in XPath, e.g.

XPath<Element> test=XPath.newInstance("/foo/bar", SOME_ELEMENT_HINT);
XPath<Attribute> test2=XPath.newInstance("/foo/@(protected));

Or if you do not want this, you can return <? extends NamespaceAware> by


One other thing I noticed is the practice of making JDOMConstants an
interface. Usually interface means something like

if (o instanceof (JDOMConstants)){

It would be "better" code to make JDOMConstants a final class with
private constructor and use "import static JDOMConstants.*" where you
need it. That would not result in such statements: "Element _is a_


And before starting another mail, please count my vote on moving
ContentList into Element.

I'm really looking forward to JDOM2 release.

regards Thomas

Thomas Scheffler
Friedrich-Schiller-Universität Jena
Thüringer Universitäts- und Landesbibliothek
Bibliotheksplatz 2
07743 Jena
Phone: ++49 3641 940027
FAX:  ++49 3641 940022
To control your jdom-interest membership:
©2008 - Jax Systems, LLC, U.S.A.