Re: Why I always get "null" returned when calling functions?

Martin Klang <[email protected]> Mon, 26 Feb 2007 18:12:43 +0000
Newsgroups gmane.text.xml.o-xml
Message-ID <[email protected]>
Francisco,

You need to match the function name and signature, in the same way as  
when you call Class.getMethod(String, Class[]) in Java.

For example, if your function definition looks like this:
   <o:function name="plus">
     <o:param name="lhs" type="Node"/>
     <o:param name="rhs" type="Node"/>
     <o:do>
       <o:return select="$lhs + $rhs"/>
     </o:do>
   </o:function>

ie you've defined the function 'plus(Number, Number)', then you can  
look up the function like this:

Function func = program.getResolver().getFunction(new Name("plus"),  
new Type[]{NumberNode.TYPE, NumberNode.TYPE});

I have put together a couple of working examples that you can  
download from here:
http://mars.pingdynasty.com/CallObjectboxExamples.zip

You need to have the latest objectbox.jar on your classpath to  
compile and run the Java program.

best of luck, I look forward to hearing of your success!

/m


On 26 Feb 2007, at 16:16, Francisco wrote:

> Dear Martin,
>
> Sorry to bother you again. I have the difficulty in following your  
> example to call the functions. The problem is mainly on this line  
> -----
>
> Function func = program.getResolver().getFunction 
> (functionName,signature);
>
> I always get "null" as return, I don't know how to solve it. I  
> checked the API but couldn't find more details on how to pass the  
> arguments or signatures for designated functions? I tried to put  
> signatures inside. But still not succeed. Could you please kindly  
> give a further explaination on this? Thank you very much for your  
> help.
>
> Looking forward to your email.
>
> Kind regards,
> Francisco
>