[jdom-interest] suggested JDOM2 improvements

Thomas Scheffler thomas.scheffler at uni-jena.de
Tue Jan 17 00:10:00 PST 2012


Hi,

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/@bar", SOME_ATTRIBUTE_HINT);

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

----

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

if (o instanceof (JDOMConstants)){
	((JDOMConstance)o).doSomething();
}

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_ 
JDOMConstants".

----

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


More information about the jdom-interest mailing list