commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Luis Neves <lne...@netcabo.pt>
Subject [JXPath] Standard extension functions stop working after registering custom extension functions
Date Sun, 18 Sep 2005 09:12:24 GMT

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


Mime
View raw message