Project

Profile

Help

user-defined java function and w3c.Document

Added by Anonymous over 19 years ago

Legacy ID: #2981234 Legacy Poster: Daniel Chaffiol (vonc)

Hi Michael, I just pass from saxon8.0 to saxon8.2, and it seems my static external java function does not work anymore if it takes for its unique argument a document (org.w3c.dom.Document). -TJ option does show that this user-defined java function is recognized. But it seems the function 'convertToJava(Class, Configuration, XPathContext)', of the class net.sf.saxon.value.SequenceValue, which is in charge of computerize the arguments to pass to the user-defined external java function (through ExtensionFunctionCall) does not check for DOM object anymore... It does not recognize the target class (which is 'org.w3c.dom.Document', and where the value is a TinyTreeDocument). That function ends up trying to "atomizing" the value (which gives an empty string through an UntypeAtomicValue!), and the saxon processor goes into an infinite loop: at net.sf.saxon.value.SequenceValue.convertToJava(SequenceValue.java:407) at net.sf.saxon.value.AtomicValue.convertToJava(AtomicValue.java:259) at net.sf.saxon.value.StringValue.convertToJava(StringValue.java:322) at net.sf.saxon.value.SequenceValue.convertToJava(SequenceValue.java:407) at net.sf.saxon.value.AtomicValue.convertToJava(AtomicValue.java:259) at net.sf.saxon.value.StringValue.convertToJava(StringValue.java:322) at net.sf.saxon.value.SequenceValue.convertToJava(SequenceValue.java:407) at net.sf.saxon.value.AtomicValue.convertToJava(AtomicValue.java:259) at net.sf.saxon.value.StringValue.convertToJava(StringValue.java:322) at net.sf.saxon.value.SequenceValue.convertToJava(SequenceValue.java:407) at net.sf.saxon.value.AtomicValue.convertToJava(AtomicValue.java:259) at net.sf.saxon.value.StringValue.convertToJava(StringValue.java:322) at net.sf.saxon.value.SequenceValue.convertToJava(SequenceValue.java:407) at net.sf.saxon.value.AtomicValue.convertToJava(AtomicValue.java:259) at net.sf.saxon.value.StringValue.convertToJava(StringValue.java:322) at net.sf.saxon.value.SequenceValue.convertToJava(SequenceValue.java:407) ... ... I suppose the fact to not take anymore a w3c Document is normal (even though it does not fallback gracefully). That must reflects the changes of http://saxonica.com/documentation/changes/intro81/extensibility-81.html, - Changes to Extension Function Calling Mechanism of 8.1 -, and http://saxonica.com/documentation/changes/intro/internal82.html) What is the alternative, the other option or choice ? How can I pass the document-node to my java function ? Am I forced to use a SequenceIterator, filled with all root nodes (comments plus one root element) of my document ? I kind of hope to avoid that... Thank you in advance. Best regards. Daniel


Replies (3)

Please register to reply

RE: user-defined java function and w3c.Docume - Added by Anonymous over 19 years ago

Legacy ID: #2985034 Legacy Poster: Michael Kay (mhkay)

I'm aware of the infinite recursion, and the problem is fixed in my code, though I don't seem to have logged the bug with a patch. There are going to be significant changes in the way DOM is supported in the next release - not necessarily for the better. DOM is a big support hassle for many reasons, for example differences between implementations and the many different options you can set. The final straw has been the inability to produce a DOM implementation that works under both JDK 1.4 and JDK 1.5, and since many users will still be on JDK 1.4 for a while, I've decided to support DOM only as an external model, in the same way as JDOM and XOM. However, calling extension functions that expect DOM Node arguments should still work. I think that if you declare the argument as a Node, it should be OK. Subclasses of Node are more difficult, one reason being that Saxon doesn't have subclasses of NodeInfo to represent the different kinds of node. However, I'll try at least to put support for Document back, which is probably the most important one. I think the only reason it got dropped is that it's not covered by any of my test cases. Michael Kay

RE: user-defined java function and w3c.Document - Added by Anonymous over 19 years ago

Legacy ID: #2985669 Legacy Poster: Daniel Chaffiol (vonc)

Hi Mickael, Thanks for the advice: replace Document by Node seems to work. What follows is a way to reproduce the problem. Even so 'Node' does the trick when I use saxon8.jar, it does not work if I use the same saxon8.2 compiled by me: V:\tst>"c:\Program Files\Java\jdk1.5.0\bin\java.exe" -cp .;c:\java\libs\saxonb8-2\cls net.sf.saxon.Transform -l -o res.xml test.xml externaljavafunction.xslt test:simpleCall() 'true' Error net.sf.saxon.xpath.DynamicError: Argument is of wrong type: argument type mismatch Transformation failed: Run-time errors were reported I suspect I do not compile correctly saxon (I am using jdk1.5, jdom1.0 and xom1.0 as my building libraries... did I miss anything ?) Rq: I do compile saxon because it does not have (correct me if I am wrong) any debug information in it (which seems reasonable, for performance issue). May be it could be better to provide the users with a saxon8d.jar (for debug) along with existing saxon8.jar 1/ Make a java external defined function in a v:\tst\TestExternalJavaFunction.java import org.w3c.dom.Document; public class TestExternalJavaFunction { static public boolean simpleCall() { return true; } static public boolean callWithDocumentNode(Document adoc) { return true; } } 2/ compile it V:\tst>"c:\Program Files\Java\jdk1.5.0\bin\javac.exe" -cp "c:\Program Files\Java\jdk1.5.0\jre\lib\rt.jar" TestExternalJavaFunction.java 3/ write a V:\tst\externaljavafunction.xslt <?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:test="http://www.any.org/java/TestExternalJavaFunction" xmlns:saxon="http://saxon.sf.net/" exclude-result-prefixes="xs saxon test" extension-element-prefixes="saxon"> <xsl:variable name="testxml" as="document-node()" select="document('test.xml')"/> <xsl:template match="/"> <xsl:message>test:simpleCall() '<xsl:value-of select="test:simpleCall()"/>'</xsl:message> <xsl:message>test:callWithDocumentNode() '<xsl:value-of select="test:callWithDocumentNode($testxml)"/>'</xsl:message> </xsl:template> </xsl:stylesheet> 4/ write a v:\tst\test.xml: <?xml version="1.0" encoding="ISO-8859-1"?> <test/> 5/ transform it V:\tst>"c:\Program Files\Java\jdk1.5.0\bin\java.exe" -cp .;c:\java\libs\saxonb8-2\saxon8.jar net.sf.saxon.Transform -l -o res.xml test.xml externaljavafunction.xslt with saxon 8.2, you get: at net.sf.saxon.value.SequenceValue.convertToJava(SequenceValue.java:407) at net.sf.saxon.value.AtomicValue.convertToJava(AtomicValue.java:259) at net.sf.saxon.value.StringValue.convertToJava(StringValue.java:322) at net.sf.saxon.value.SequenceValue.convertToJava(SequenceValue.java:407) at net.sf.saxon.value.AtomicValue.convertToJava(AtomicValue.java:259) at net.sf.saxon.value.StringValue.convertToJava(StringValue.java:322) at net.sf.saxon.value.SequenceValue.convertToJava(SequenceValue.java:407) at net.sf.saxon.value.AtomicValue.convertToJava(AtomicValue.java:259) at net.sf.saxon.value.StringValue.convertToJava(StringValue.java:322) at net.sf.saxon.value.SequenceValue.convertToJava(SequenceValue.java:407) at net.sf.saxon.value.AtomicValue.convertToJava(AtomicValue.java:259) at net.sf.saxon.value.StringValue.convertToJava(StringValue.java:322) ... With a Node as parameter, the same command works. with saxon8.0 and a Document as parameter, you get: test:simpleCall() 'true' test:callWithDocumentNode() 'true' and with compiled saxon8.2, you get (with Node as a parameter of the static function) V:\tst>"c:\Program Files\Java\jdk1.5.0\bin\java.exe" -cp .;c:\java\libs\saxonb8-2\cls net.sf.saxon.Transform -l -o res.xml test.xml externaljavafunction.xslt test:simpleCall() 'true' Error net.sf.saxon.xpath.DynamicError: Argument is of wrong type: argument type mismatch Transformation failed: Run-time errors were reported

RE: user-defined java function and w3c.Document - Added by Anonymous over 19 years ago

Legacy ID: #2988484 Legacy Poster: Daniel Chaffiol (vonc)

Oops, my fault. Again, with a Node as a parameter for my external java function, all works well. As for my problem of execution with my own compiled saxon, it was only because I was using a "modified" SequenceValue.java With the original SequenceValue.java, (especially with the original code for convertToJava), it works just fine. So thank you again for you answer, and please disregard any problem I have mentionned in my last.

    (1-3/3)

    Please register to reply