You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Peter Neumcke <pn...@virbus.de> on 2003/03/19 16:57:02 UTC

[JXPath] Custom Extension Functions

Hi Dimitri,
thanks for implementing the Relative Context - we switched to Version 1.1
and it works like a charm!

I've got two new questions concerning "Custom Extension Functions":

* registering
Registering extension functions with context objects works fine. 
In the API-Doc of ClassFunctions it is mentioned, that you can register
functions globally by calling 'new ClassFunctions(Integer.class, "int")'. In
the default implementation of JXPathContext the generic functions are
created with null as namespace, and this seems to prevent generic functions
from returning anything but null:
private static final PackageFunctions GENERIC_FUNCTIONS = new
PackageFunctions("", null);
Did I miss something?

* return values
I managed to write a function that returns an Integer for later use, e.g.
'[ws:myFunc()]. How would I return Nodes/Pointers/whatever for later
evaluation, e.g. '[count(ws:myFunc()/preceding-sibling::*)]? What type
should my function return?

Thanks for your help,

Peter
 

Re: [JXPath] Custom Extension Functions

Posted by Dmitri Plotnikov <dp...@yahoo.com>.
Peter,

I have fixed the problem with extension functions returning
collections.
You have two options: either return a collection (array, list, set etc)
or a NodeSet.  Check out the new class, BasicNodeSet, which makes it
very busy to build a NodeSet.

Thank you for bringing up this issue.

- Dmitri 

--- Peter Neumcke <pn...@virbus.de> wrote:
> Hi Dimitri,
> thanks for implementing the Relative Context - we switched to Version
> 1.1
> and it works like a charm!
> 
> I've got two new questions concerning "Custom Extension Functions":
> 
> * registering
> Registering extension functions with context objects works fine. 
> In the API-Doc of ClassFunctions it is mentioned, that you can
> register
> functions globally by calling 'new ClassFunctions(Integer.class,
> "int")'. In
> the default implementation of JXPathContext the generic functions are
> created with null as namespace, and this seems to prevent generic
> functions
> from returning anything but null:
> private static final PackageFunctions GENERIC_FUNCTIONS = new
> PackageFunctions("", null);
> Did I miss something?
> 
> * return values
> I managed to write a function that returns an Integer for later use,
> e.g.
> '[ws:myFunc()]. How would I return Nodes/Pointers/whatever for later
> evaluation, e.g. '[count(ws:myFunc()/preceding-sibling::*)]? What
> type
> should my function return?
> 
> Thanks for your help,
> 
> Peter
>  
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
> 


__________________________________________________
Do you Yahoo!?
Yahoo! Platinum - Watch CBS' NCAA March Madness, live on your desktop!
http://platinum.yahoo.com

Re: [JXPath] Custom Extension Functions

Posted by Dmitri Plotnikov <dp...@yahoo.com>.
Peter,

--- Peter Neumcke <pn...@virbus.de> wrote:
> Hi Dimitri,
> thanks for implementing the Relative Context - we switched to Version
> 1.1
> and it works like a charm!
I am glad to hear that.

> I've got two new questions concerning "Custom Extension Functions":
> 
> * registering
> Registering extension functions with context objects works fine. 
> In the API-Doc of ClassFunctions it is mentioned, that you can
> register
> functions globally by calling 'new ClassFunctions(Integer.class,
> "int")'. In
> the default implementation of JXPathContext the generic functions are
> created with null as namespace, and this seems to prevent generic
> functions
> from returning anything but null:
> private static final PackageFunctions GENERIC_FUNCTIONS = new
> PackageFunctions("", null);
> Did I miss something?
The prefix has nothing to do with the return value of a function.  Each
function is a static method and it can return anything it wants.

> * return values
> I managed to write a function that returns an Integer for later use,
> e.g.
> '[ws:myFunc()]. How would I return Nodes/Pointers/whatever for later
> evaluation, e.g. '[count(ws:myFunc()/preceding-sibling::*)]? What
> type
> should my function return?
I never tested this.  I am not sure it would actually work with either
pointers or actual nodes - oops... I'll look into this as soon as I can
and let you know.
 
> Thanks for your help,
> 
> Peter

Regards,

- Dmitri

__________________________________________________
Do you Yahoo!?
Yahoo! Platinum - Watch CBS' NCAA March Madness, live on your desktop!
http://platinum.yahoo.com