Quantcast

Implementing extension function with multiple arity

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Implementing extension function with multiple arity

cmarchand
Hello,

according to javadoc, if I want to implement two extension functions,
with the same QName, but with different arity, I must implement them in
the same class.


My function signatures are :

myFunction(xs:string, element())
myFunction(xs:string, xs:string, xs:string, xs:string, xs:string)

In this case, what getArgumentTypes() should return ?


Best,
Christophe


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help 
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Implementing extension function with multiple arity

Michael Kay

> On 27 Mar 2017, at 12:29, Christophe Marchand <[hidden email]> wrote:
>
> Hello,
>
> according to javadoc, if I want to implement two extension functions,
> with the same QName, but with different arity, I must implement them in
> the same class.
>
>
> My function signatures are :
>
> myFunction(xs:string, element())
> myFunction(xs:string, xs:string, xs:string, xs:string, xs:string)
>
> In this case, what getArgumentTypes() should return ?
>


A list of 5 entries, where the second is Sequence.SINGLE_ITEM. You will have to rely on the function logic itself to check that the supplied item is a string in the arity-5 case and an element in the arity-2 case; you will also have to check in the function logic that the number of arguments supplied is either 2 or 5, never 3 or 4.

Michael Kay
Saxonica
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help 
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Implementing extension function with multiple arity

cmarchand
Thanks Michael for your quick response. But I still have errors,
probably I do not define correctly the last 3 return types.

Defining this :
     public SequenceType[] getArgumentTypes() {
         return new SequenceType[] {
             SequenceType.SINGLE_STRING,
             SequenceType.SINGLE_ITEM};
     }

Calling efl-ext:basex-query('query', 'server', 'port', 'user',
'password'), I get this :
net.sf.saxon.s9api.SaxonApiException: Function efl-ext:basex-query must
have 2 arguments

Defining this :
     public SequenceType[] getArgumentTypes() {
         return new SequenceType[] {
             SequenceType.SINGLE_STRING,
             SequenceType.SINGLE_ITEM,
             SequenceType.OPTIONAL_STRING,
             SequenceType.OPTIONAL_STRING,
             SequenceType.OPTIONAL_STRING};
     }

Calling efl-ext:basex-query('query', $connect) where $connect is a
element(), I get this :
net.sf.saxon.s9api.SaxonApiException: Function efl-ext:basex-query must
have 5 arguments

If you could be more precise...

Best,
Christophe


Le 27/03/2017 à 15:57, Michael Kay a écrit :

>> On 27 Mar 2017, at 12:29, Christophe Marchand <[hidden email]> wrote:
>>
>> Hello,
>>
>> according to javadoc, if I want to implement two extension functions,
>> with the same QName, but with different arity, I must implement them in
>> the same class.
>>
>>
>> My function signatures are :
>>
>> myFunction(xs:string, element())
>> myFunction(xs:string, xs:string, xs:string, xs:string, xs:string)
>>
>> In this case, what getArgumentTypes() should return ?
>>
>
> A list of 5 entries, where the second is Sequence.SINGLE_ITEM. You will have to rely on the function logic itself to check that the supplied item is a string in the arity-5 case and an element in the arity-2 case; you will also have to check in the function logic that the number of arguments supplied is either 2 or 5, never 3 or 4.
>
> Michael Kay
> Saxonica
> ------------------------------------------------------------------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> _______________________________________________
> saxon-help mailing list archived at http://saxon.markmail.org/
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/saxon-help
>


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help 
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Implementing extension function with multiple arity

Michael Kay
Are you defining an instance of net.sf.saxon.lib.ExtensionFunctionDefinition, or is it net.sf.saxon.s9api.ExtensionFunction?

Michael Kay
Saxonica

> On 27 Mar 2017, at 15:59, Christophe Marchand <[hidden email]> wrote:
>
> Thanks Michael for your quick response. But I still have errors,
> probably I do not define correctly the last 3 return types.
>
> Defining this :
>     public SequenceType[] getArgumentTypes() {
>         return new SequenceType[] {
>             SequenceType.SINGLE_STRING,
>             SequenceType.SINGLE_ITEM};
>     }
>
> Calling efl-ext:basex-query('query', 'server', 'port', 'user',
> 'password'), I get this :
> net.sf.saxon.s9api.SaxonApiException: Function efl-ext:basex-query must
> have 2 arguments
>
> Defining this :
>     public SequenceType[] getArgumentTypes() {
>         return new SequenceType[] {
>             SequenceType.SINGLE_STRING,
>             SequenceType.SINGLE_ITEM,
>             SequenceType.OPTIONAL_STRING,
>             SequenceType.OPTIONAL_STRING,
>             SequenceType.OPTIONAL_STRING};
>     }
>
> Calling efl-ext:basex-query('query', $connect) where $connect is a
> element(), I get this :
> net.sf.saxon.s9api.SaxonApiException: Function efl-ext:basex-query must
> have 5 arguments
>
> If you could be more precise...
>
> Best,
> Christophe
>
>
> Le 27/03/2017 à 15:57, Michael Kay a écrit :
>>> On 27 Mar 2017, at 12:29, Christophe Marchand <[hidden email]> wrote:
>>>
>>> Hello,
>>>
>>> according to javadoc, if I want to implement two extension functions,
>>> with the same QName, but with different arity, I must implement them in
>>> the same class.
>>>
>>>
>>> My function signatures are :
>>>
>>> myFunction(xs:string, element())
>>> myFunction(xs:string, xs:string, xs:string, xs:string, xs:string)
>>>
>>> In this case, what getArgumentTypes() should return ?
>>>
>>
>> A list of 5 entries, where the second is Sequence.SINGLE_ITEM. You will have to rely on the function logic itself to check that the supplied item is a string in the arity-5 case and an element in the arity-2 case; you will also have to check in the function logic that the number of arguments supplied is either 2 or 5, never 3 or 4.
>>
>> Michael Kay
>> Saxonica
>> ------------------------------------------------------------------------------
>> Check out the vibrant tech community on one of the world's most
>> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
>> _______________________________________________
>> saxon-help mailing list archived at http://saxon.markmail.org/
>> [hidden email]
>> https://lists.sourceforge.net/lists/listinfo/saxon-help
>>
>
>
> ------------------------------------------------------------------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> _______________________________________________
> saxon-help mailing list archived at http://saxon.markmail.org/
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/saxon-help 


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help 
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Implementing extension function with multiple arity

cmarchand
public class BaseXQuery extends ExtensionFunctionDefinition


Le 27/03/2017 à 17:19, Michael Kay a écrit :

> Are you defining an instance of net.sf.saxon.lib.ExtensionFunctionDefinition, or is it net.sf.saxon.s9api.ExtensionFunction?
>
> Michael Kay
> Saxonica
>
>> On 27 Mar 2017, at 15:59, Christophe Marchand <[hidden email]> wrote:
>>
>> Thanks Michael for your quick response. But I still have errors,
>> probably I do not define correctly the last 3 return types.
>>
>> Defining this :
>>      public SequenceType[] getArgumentTypes() {
>>          return new SequenceType[] {
>>              SequenceType.SINGLE_STRING,
>>              SequenceType.SINGLE_ITEM};
>>      }
>>
>> Calling efl-ext:basex-query('query', 'server', 'port', 'user',
>> 'password'), I get this :
>> net.sf.saxon.s9api.SaxonApiException: Function efl-ext:basex-query must
>> have 2 arguments
>>
>> Defining this :
>>      public SequenceType[] getArgumentTypes() {
>>          return new SequenceType[] {
>>              SequenceType.SINGLE_STRING,
>>              SequenceType.SINGLE_ITEM,
>>              SequenceType.OPTIONAL_STRING,
>>              SequenceType.OPTIONAL_STRING,
>>              SequenceType.OPTIONAL_STRING};
>>      }
>>
>> Calling efl-ext:basex-query('query', $connect) where $connect is a
>> element(), I get this :
>> net.sf.saxon.s9api.SaxonApiException: Function efl-ext:basex-query must
>> have 5 arguments
>>
>> If you could be more precise...
>>
>> Best,
>> Christophe
>>
>>
>> Le 27/03/2017 à 15:57, Michael Kay a écrit :
>>>> On 27 Mar 2017, at 12:29, Christophe Marchand <[hidden email]> wrote:
>>>>
>>>> Hello,
>>>>
>>>> according to javadoc, if I want to implement two extension functions,
>>>> with the same QName, but with different arity, I must implement them in
>>>> the same class.
>>>>
>>>>
>>>> My function signatures are :
>>>>
>>>> myFunction(xs:string, element())
>>>> myFunction(xs:string, xs:string, xs:string, xs:string, xs:string)
>>>>
>>>> In this case, what getArgumentTypes() should return ?
>>>>
>>> A list of 5 entries, where the second is Sequence.SINGLE_ITEM. You will have to rely on the function logic itself to check that the supplied item is a string in the arity-5 case and an element in the arity-2 case; you will also have to check in the function logic that the number of arguments supplied is either 2 or 5, never 3 or 4.
>>>
>>> Michael Kay
>>> Saxonica
>>> ------------------------------------------------------------------------------
>>> Check out the vibrant tech community on one of the world's most
>>> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
>>> _______________________________________________
>>> saxon-help mailing list archived at http://saxon.markmail.org/
>>> [hidden email]
>>> https://lists.sourceforge.net/lists/listinfo/saxon-help
>>>
>>
>> ------------------------------------------------------------------------------
>> Check out the vibrant tech community on one of the world's most
>> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
>> _______________________________________________
>> saxon-help mailing list archived at http://saxon.markmail.org/
>> [hidden email]
>> https://lists.sourceforge.net/lists/listinfo/saxon-help
>
> ------------------------------------------------------------------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> _______________________________________________
> saxon-help mailing list archived at http://saxon.markmail.org/
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/saxon-help
>


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help 
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Implementing extension function with multiple arity

cmarchand
In reply to this post by Michael Kay
Overwriting getMinimumNumberOfParameters() seems to solve problem.

Thanks Michael !

And thanks to Florent who had contributed off-list.

Best regards,
Christophe


Le 27/03/2017 à 17:19, Michael Kay a écrit :

> Are you defining an instance of net.sf.saxon.lib.ExtensionFunctionDefinition, or is it net.sf.saxon.s9api.ExtensionFunction?
>
> Michael Kay
> Saxonica
>
>> On 27 Mar 2017, at 15:59, Christophe Marchand <[hidden email]> wrote:
>>
>> Thanks Michael for your quick response. But I still have errors,
>> probably I do not define correctly the last 3 return types.
>>
>> Defining this :
>>      public SequenceType[] getArgumentTypes() {
>>          return new SequenceType[] {
>>              SequenceType.SINGLE_STRING,
>>              SequenceType.SINGLE_ITEM};
>>      }
>>
>> Calling efl-ext:basex-query('query', 'server', 'port', 'user',
>> 'password'), I get this :
>> net.sf.saxon.s9api.SaxonApiException: Function efl-ext:basex-query must
>> have 2 arguments
>>
>> Defining this :
>>      public SequenceType[] getArgumentTypes() {
>>          return new SequenceType[] {
>>              SequenceType.SINGLE_STRING,
>>              SequenceType.SINGLE_ITEM,
>>              SequenceType.OPTIONAL_STRING,
>>              SequenceType.OPTIONAL_STRING,
>>              SequenceType.OPTIONAL_STRING};
>>      }
>>
>> Calling efl-ext:basex-query('query', $connect) where $connect is a
>> element(), I get this :
>> net.sf.saxon.s9api.SaxonApiException: Function efl-ext:basex-query must
>> have 5 arguments
>>
>> If you could be more precise...
>>
>> Best,
>> Christophe
>>
>>
>> Le 27/03/2017 à 15:57, Michael Kay a écrit :
>>>> On 27 Mar 2017, at 12:29, Christophe Marchand <[hidden email]> wrote:
>>>>
>>>> Hello,
>>>>
>>>> according to javadoc, if I want to implement two extension functions,
>>>> with the same QName, but with different arity, I must implement them in
>>>> the same class.
>>>>
>>>>
>>>> My function signatures are :
>>>>
>>>> myFunction(xs:string, element())
>>>> myFunction(xs:string, xs:string, xs:string, xs:string, xs:string)
>>>>
>>>> In this case, what getArgumentTypes() should return ?
>>>>
>>> A list of 5 entries, where the second is Sequence.SINGLE_ITEM. You will have to rely on the function logic itself to check that the supplied item is a string in the arity-5 case and an element in the arity-2 case; you will also have to check in the function logic that the number of arguments supplied is either 2 or 5, never 3 or 4.
>>>
>>> Michael Kay
>>> Saxonica
>>> ------------------------------------------------------------------------------
>>> Check out the vibrant tech community on one of the world's most
>>> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
>>> _______________________________________________
>>> saxon-help mailing list archived at http://saxon.markmail.org/
>>> [hidden email]
>>> https://lists.sourceforge.net/lists/listinfo/saxon-help
>>>
>>
>> ------------------------------------------------------------------------------
>> Check out the vibrant tech community on one of the world's most
>> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
>> _______________________________________________
>> saxon-help mailing list archived at http://saxon.markmail.org/
>> [hidden email]
>> https://lists.sourceforge.net/lists/listinfo/saxon-help
>
> ------------------------------------------------------------------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> _______________________________________________
> saxon-help mailing list archived at http://saxon.markmail.org/
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/saxon-help
>


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help 
Loading...