Hi all, 

I just had a query as to what the recommended way of adding a custom
function to an XPath is. Reading through the JavaDocs and source code,
I'm guessing it is something like the following: 

  XPathFunctionContext ctx = new XPathFunctionContext(); 
  ctx.registerFunction(null, "custom", new CustomFunction()); 

  XPath xpath = new XPath("custom(//foo/bar)"); 
  xpath.setFunctionContext(ctx); 

This process isn't documented anywhere, and the above is not necessarily
a conclusion I would jump to - replacing the whole function context
feels kind of wierd - I feel as though I may be replacing another custom
context, wiping out it's set of custom functions. What if, for example,
a couple of the supported OMs added their own implementation of the
'id()' function, and created their own subclass of XPathFunctionContext
containing their IDFunction. The above code will remove the registered
'id()' function. Of course, if they read their JavaDocs, that fact would
probably have been noted. 

Anyway, I'm not suggesting a change, since I can see the reasons it is
this way, but could the current 'recommended practice' be put down
somewhere please? Also perhaps some documentation in
BaseXPath.createFunctionContext() that it by default returns the
singleton XPathFunctionContext. That would be a good hint to people like
myself who are trawling the JavaDocs and don't fully read the class
intro :)

Also, I was wondering what the benefit of having the singleton inside a
static inner class is. I've seen the pattern before, but I've never
understood the benefit of that over just having the singleton
XPathFunctionContext as a private static final in XPathFunctionContext
itself.

Thanks,

David


_______________________________________________
Jaxen-interest mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jaxen-interest

Reply via email to