commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dmitri Plotnikov <dmi...@apache.org>
Subject Re: [JXPath] Standard extension functions stop working after registering custom extension functions
Date Mon, 19 Sep 2005 17:59:09 GMT
Luis,

By calling setFunctions with a custom set of functions, you in fact
override the default behavior completely (which you should be able to
do).  To preserve the default behavior, do this:

  FunctionLibrary lib = new FunctionLibrary();
  lib.addFunctions(new ClassFunctions(MyFunctions.class, "myfunc"));
  lib.addFunctions(new PackageFunctions("", null));  // default
  jx_ctx.setFunctions(lib);


I hope this helps,

- Dmitri

--- Luis Neves <lneves@netcabo.pt> wrote:

> 
> Hello all,
> After registering custom extension functions I'm not able to call
> instance methods on 
> objects.
> 
> ********************************************************
> public class MyBean
> {
> 	public String echo(String input)
> 	{
> 		return input;
> 	}	
> }
> 
> ********************************************************
> public class MyFunctions
> {
> 	public long add(int a, int b)
> 	{
> 		return a + b;
> 	}
> }
> ********************************************************
> import org.apache.commons.jxpath.ClassFunctions;
> import org.apache.commons.jxpath.JXPathContext;
> 
> public class JxPathTests
> {
> 	public static void main(String[] args)
> 	{
> 		JXPathContext jx_ctx = JXPathContext.newContext(null);
> 		jx_ctx.getVariables().declareVariable("bean", new MyBean());		
> 		
> 		// This works
> 		System.out.println(jx_ctx.getValue("echo($bean, 'foobar')"));		
> 		
> 		// Lets register a "function" and see what happens
> 		jx_ctx.setFunctions(new ClassFunctions(MyFunctions.class,
> "myfunc"));		
> 		
> 		// It does not work anymore
> 		System.out.println(jx_ctx.getValue("echo($bean, 'foobar')"));
> 	}
> }
> 
> ********************************************************
> 
> Is this a bug? Am I misunderstanding something?
> 
> Thanks in advance.
> 
> Luis Neves
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
> 
> 


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


Mime
View raw message