[jdom-interest] suggested JDOM2 improvements

BIHANIC Laurent laurent.bihanic at atos.net
Fri Jan 20 01:26:48 PST 2012

Hi Rolf,

Le 17/01/12 14:42, Rolf Lear a écrit :
> In the 'simple' XPath case (no extra namespaces, no Variables) XPath is
> still a 1-liner, which is hard to beat. In a complicated case I see more
> complexity trying to 'massage' your Namespaces and Variables in to some new
> type structures (the varargs) than the existing concept of adding
> Namespaces and setting variables.
> Also, keeping backward compatibility is a strong consideration.
> In reality I think I would like to see code examples of what you think it
> 'should' look like to get a better idea, but at the moment i am not
> convinced that it's actually broken enough to require fixing.

Well, as 99% of our XML use namespaces, using JDOM XPath is not a 1-liner.
And as the XPath API throws non-runtime exceptions, pre-compiling XPath
expressions (as we do for regex) requires using a class initializer to map
JDOMException to runtime exceptions.
The only case where we can't compile XPath expressions is when we want to use
variables. Which defeats the whole purpose of compiling XPath! Or we have to
use thread-local compiled XPaths.

So, I think it would be great to split the XPath API in two parts.

One for constructing compiled XPath expressions, including the namespaces,
using either a constructor/factory method with varargs, e.g. compile(String
expr, Namespace... namespace), or a builder/DSL. The result being an immutable
thread-safe XPath object. This part would only throw runtime exceptions,
IllegalArgumentException seeming sufficient.

A second for evaluating compiled XPaths on documents, taking optional variable
bindings as argument and throwing regular exceptions, e.g. find(context,
Map<String,Object> bindings)

If we go this way, we should leave the existing XPath class unchanged and
deprecate it and create a new separate class.



Ce message et les pièces jointes sont confidentiels et réservés à l'usage exclusif de ses destinataires. Il peut également être protégé par le secret professionnel. Si vous recevez ce message par erreur, merci d'en avertir immédiatement l'expéditeur et de le détruire. L'intégrité du message ne pouvant être assurée sur Internet, la responsabilité du groupe Atos ne pourra être engagée quant au contenu de ce message. Bien que les meilleurs efforts soient faits pour maintenir cette transmission exempte de tout virus, l'expéditeur ne donne aucune garantie à cet égard et sa responsabilité ne saurait être engagée pour tout dommage résultant d'un virus transmis.

This e-mail and the documents attached are confidential and intended solely for the addressee; it may also be privileged. If you receive this e-mail in error, please notify the sender immediately and destroy it. As its integrity cannot be secured on the Internet, the Atos group liability cannot be triggered for the message content. Although the sender endeavors to maintain a computer virus-free network, the sender does not warrant that this transmission is virus-free and will not be liable for any damages resulting from any virus transmitted.

More information about the jdom-interest mailing list