Oh--it looks like in your original example you should have been using 
ClassFunctions instead of PackageFunctions.  That's how you get JXPath to 
interpolate the ExpressionContext parameter.  I've also done some stuff with 
writing a custom Functions implementation that returned a particular function 
on-the-fly based on the parameters... that was awhile back and there may have 
been a better way to do it, but at the time I couldn't find it.  Long story 
short, glad you've got the one way working, but there are also ways to use 
custom functions as predicates.

br,
Matt

--- On Tue, 4/21/09, Andrew Hughes <ahhug...@gmail.com> wrote:

> From: Andrew Hughes <ahhug...@gmail.com>
> Subject: Re: [JXPath] Custom Functions & the Current Pointer
> To: "Commons Users List" <user@commons.apache.org>
> Date: Tuesday, April 21, 2009, 8:08 PM
> Hi Matt,
> WooHoo, I got it working :) Kudos for JXPath :D
> (Again)....
> 
> Constructive suggestion: the JXPath doco talks a lot about
> the use of
> functions within predicates, and the programmatic use or
> $variables within
> custom functions. I was unable to find an example where a
> function used an
> expression->pointer->value as a parameter. This would
> be the most likely use
> JXPath functions in my opinion....
> 
> Example (for anyone who's reading this in some future
> context):
> 
> 
> The expression,
> '/World/Country/Australia'   returns an
> value/instance of
> "Australia.java". If you would like to get the current
> exchange rate for
> "Australia" then you would most likely want do this with
> the following xpath
> expression:
> 
> mynamespace:MyFunctions.getExchangeRate(/World/Country/Australia)
> 
> 
> A corresponding Java function is implemented to provide
> such
> function(ality):
> 
> package com.blah.whatever.project;
> public class MyFunctions {
>     public static double
> getExchangeRate(Australia australia) {
>         //pojo code goes in here...
>     }
> }
> 
> 
> And to complete this, the Java function needs to be set in
> the
> JXPathContext... (don't forget the package string
> terminating "."):
> 
> JXPathContext.setFunctions(new
> PackageFunctions("com.blah.whatever.project.",
> "mynamespace"));
> 
> 
> That's it.
> 
> 
> 
> 
> 
> 
> 
> On Tue, Apr 21, 2009 at 11:39 PM, Matt Benson <gudnabr...@yahoo.com>
> wrote:
> 
> >
> > Hi, Andrew.  Your example looks pretty good...
> what happens exactly when
> > you try it?
> >
> > -Matt
> >
> > --- On Mon, 4/20/09, Andrew Hughes <ahhug...@gmail.com>
> wrote:
> >
> > > From: Andrew Hughes <ahhug...@gmail.com>
> > > Subject: [JXPath] Custom Functions & the
> Current Pointer
> > > To: "Commons Users List" <user@commons.apache.org>
> > > Date: Monday, April 20, 2009, 11:31 PM
> > > Hi there, I think this is a really
> > > easy question... sorry for this...
> > > I have created my own function as below....
> > >
> > > package com.blah.function;
> > >
> > > public class Calculate {
> > >     public static
> Calculation
> > > doCalculation(ExpressionContext context, int
> > > x) {
> > >         //stuff
> goes in here...
> > >     }
> > >
> > > }
> > >
> > >
> > > I've  also registered it with the
> JXPathContext as
> > > below...
> > >
> > > jxPathContext.setFunctions(new
> > > PackageFunctions("com.blah.function.",
> > > "jxpath"));
> > >
> > >
> > > I see how this works programatically, but not in
> an
> > > expression. For example,
> > > if I want to find a node and then use that node
> in
> > > doCalculation... how?
> > >
> > > '/Something/I/CanFind' then I want to run
> > > 'doCalculation(6)' on the result
> > > of the previous query's result.
> > >
> > >
> > > I would have thought this would be something like
> the
> > > following but I am
> > > obviously wrong...
> > >
> > >
> jxpath:Calculate.doCalculation(/Something/I/CanFind,6);
> > >
> > >
> /Something/I/CanFind[jxpath:Calculate.doCalculation(6)];
> > >
> > >
> > > Once an "ExpressionContext" is involved it no
> longer
> > > works.
> > >
> > >
> > > Any help would be much appreciated :)
> > >
> >
> >
> >
> >
> >
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscr...@commons.apache.org
> > For additional commands, e-mail: user-h...@commons.apache.org
> >
> >
> 




---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@commons.apache.org
For additional commands, e-mail: user-h...@commons.apache.org

Reply via email to