Project

Profile

Help

Java Extension Functions - Overloaded methods

Added by Urmila Sridharan almost 6 years ago

Hi,

I am currently evaluating Saxon EE 9.8 version in-order to migrate from Xalan to Saxon.

What are the options to resolve overloaded method calls? I have tried few options found in various support forums and https://www.saxonica.com/html/documentation/extensibility/functions/converting-args/.

Any pointers will be helpful.


Error: There is more than one method matching the function call TestClient:call, and there is insufficient type information to determine which one should be used

Error details - There are several Java methods that match the function name equally well Finding best fit method for arguments Trying option 1: public org.w3c.dom.Node x.y.TestClient.call(boolean) Conversion preferences are [80, 80] Trying option 2: public org.w3c.dom.Node x.y.TestClient.call(java.lang.String) Conversion preferences are [80, 80] Trying option 3: public org.w3c.dom.Node x.y.TestClient.call(org.jdom2.Document) Conversion preferences are [80, 80] Trying option 4: public org.w3c.dom.Node x.y.TestClient.call(org.w3c.dom.Node) Conversion preferences are [80, 80] Number of candidate methods remaining: 4 There are several Java methods that match the function name equally well Static error in xsl:variable/@select on line 62 column 93 of test.xsl: XPST0017: There is more than one method matching the function call Client:call, and there is insufficient type information to determine which one should be used Errors were reported during stylesheet compilation


Replies (3)

Please register to reply

RE: Java Extension Functions - Overloaded methods - Added by Michael Kay almost 6 years ago

It would be good to see the actual function call, but from this information it looks as if Saxon knows nothing about the type of the argument supplied in the call. That's not uncommon for code originally written for XSLT 1.0, where typically there will be no "as" clauses on variables and parameters to allow the types of parameters to be inferred.

If the supplied argument is a variable reference then it's often enough to give it an explicit type, for example


in other cases a "treat as" clause can be useful:

select="test:call($x treat as xs:string)"/>

The key thing is that Saxon has to make a static (compile-time) decision which of the methods to call, and therefore the more type information you make available, the better.

RE: Java Extension Functions - Overloaded methods - Added by Urmila Sridharan almost 6 years ago

The actual function calls, pass a variable containing xml string or the input xml as is. Samples given below.

In most cases the expected method call to match is, public org.w3c.dom.Node x.y.TestClient.call(org.w3c.dom.Node)

There is no type information in the existing xsl however adding - as="element()" or "node()" type did not resolve the method call. How do we cast or explicitly specify type as dom.Node or jdom2.Document in this case?

  1. One of the method call argument is a xml generated at runtime <xsl:variable name="request" > <xsl:copy-of select="." /> </xsl:variable> <xsl:variable name="client" select="TestClient:new($processor, xs:string($url))" /> <xsl:variable name="response" select="TestClient:call($client, $request)" />

  2. request xml passed as is in some cases <xsl:template match="/request"> <xsl:apply-templates select="body"/> </xsl:template> <xsl:template match="body"> <xsl:variable name="response" select="TestClient:call($client, root)"/> <xsl:copy-of select="$response/root"/> </xsl:template>

or

<xsl:variable name="response" select="TestClient:call($client, .)" />

RE: Java Extension Functions - Overloaded methods - Added by Michael Kay almost 6 years ago

Sorry, it's difficult to answer because you've only posted some fragments of your code:you haven't shown what TestClient.new() and TestClient.call() actually do.

If your Java method expects a JDOM2 node, then the call is going to fail unless you pass something that is a JDOM2 node. If the input document is a JDOM2 document and you pass a node in the input document, that should be OK; but if you pass a node that the stylesheet has constructed, that won't be a JDOM2 node so it will always fail.

If your Java method expects a DOM node, the situation is slightly more flexible because Saxon is capable of creating a wrapper around its internal nodes to give them a DOM interface (DOM is defined in terms of interfaces, whereas JDOM2 uses concrete classes which makes this approach impossible.)

I think we need a repro: a complete executable stylesheet and a complete Java class, so that we can see exactly what you're doing and where it's going wrong.

    (1-3/3)

    Please register to reply