Class-loading difficulties obtaining a Java class from XSLT...

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Class-loading difficulties obtaining a Java class from XSLT...

paul.bandler
I’m experiencing difficulties calling a java static method that expects a Class object as its first parameter. E.g. a method with a signature similar to:

class com.bla.bla.Xyz {
public static someStaticMethod(Class c, int i){//…}
}

I’ve tried using the Class.forName method from within XSLT to obtain the required class object:

<xsl:value-of select="xyz:someStaticMethod(class:forName('com.bla.bla.SomeClass'), 1)" xmlns:xyz="java:com.bla.bla.Xyz" xmlns:class="java:java.lang.Class"/>

But there’s a class-loading issue as I get a ClassNotFound exception:

12:11:26,508 INFO  [main] JAXPSAXProcessorInvoker  - Transforming...
net.sf.saxon.trans.XPathException: Exception in extension function java.lang.ClassNotFoundException: com/bla/bla/SomeClass
       at net.sf.saxon.functions.ExtensionFunctionCall.call(ExtensionFunctionCall.java:368)
       at net.sf.saxon.functions.ExtensionFunctionCall.iterate(ExtensionFunctionCall.java:224)


After some research on the list I thought I might need to force use of the Thread context class loader, so tried to call the Class.forName method that accepts the class-loader to use:

<xsl:value-of              select="xyz:someStaticMethod(class:forName('com.bla.bla.SomeClass',true,Thread:getContextClassLoader(Thread:currentThread()) ),1)" xmlns:Thread="java:java.lang.Thread" xmlns:xyz="java:com.bla.bla.Xyz" xmlns:class="java:java.lang.Class"  />

But I’m not succeeding – the following exception is complaining about the ‘second argument of class:forName’, but I think it’s actually referring to the third – i.e. that the attempt to find the Thread’s context class loader is returning an empty sequence maybe?

11:55:21,102 ERROR [main] JAXPSAXProcessorInvoker  - An empty sequence is not allowed as the second argument of class:forName(); SystemID: file:/C:/Users/bandlerp/git/SomeFilePathName.xsl; Line#: 49; Column#: -1
; SystemID: file:/C:/Users/bandlerp/git/SomeFilePathName.xsl; Line#: 49; Column#: -1
net.sf.saxon.trans.XPathException: An empty sequence is not allowed as the second argument of class:forName()
       at net.sf.saxon.expr.Expression.typeError(Expression.java:981)
       at net.sf.saxon.expr.CardinalityChecker.evaluateItem(CardinalityChecker.java:277)


I’m using SAXON-B, version 9.0.0.8.

Thanks in anticipation of any suggestions,

Paul Bandler



This e-mail (including any attachments) is private and confidential, may contain proprietary or privileged information and is intended for the named recipient(s) only. Unintended recipients are strictly prohibited from taking action on the basis of information in this e-mail and must contact the sender immediately, delete this e-mail (and all attachments) and destroy any hard copies. Nomura will not accept responsibility or liability for the accuracy or completeness of, or the presence of any virus or disabling code in, this e-mail. If verification is sought please request a hard copy. Any reference to the terms of executed transactions should be treated as preliminary only and subject to formal written confirmation by Nomura. Nomura reserves the right to retain, monitor and intercept e-mail communications through its networks (subject to and in accordance with applicable laws). No confidentiality or privilege is waived or lost by Nomura by any mistransmission of this e-mail. Any reference to "Nomura" is a reference to any entity in the Nomura Holdings, Inc. group. Please read our Electronic Communications Legal Notice which forms part of this e-mail: http://www.Nomura.com/email_disclaimer.htm

------------------------------------------------------------------------------
Announcing the Oxford Dictionaries API! The API offers world-renowned
dictionary content that is easy and intuitive to access. Sign up for an
account today to start using our lexical data to power your apps and
projects. Get started today and enter our developer competition.
http://sdm.link/oxford
_______________________________________________
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
|

Re: Class-loading difficulties obtaining a Java class from XSLT...

Michael Kay
I think you want "true()" rather than "true".

If you moved to a more recent Saxon version, it would have given you a warning about this common error. Though the error message is correct - you've supplied "true" as the second argument, and it evaluates to an empty sequence.

Michael Kay
Saxonica


> On 8 Mar 2017, at 13:28, [hidden email] wrote:
>
> I’m experiencing difficulties calling a java static method that expects a Class object as its first parameter. E.g. a method with a signature similar to:
>
> class com.bla.bla.Xyz {
> public static someStaticMethod(Class c, int i){//…}
> }
>
> I’ve tried using the Class.forName method from within XSLT to obtain the required class object:
>
> <xsl:value-of select="xyz:someStaticMethod(class:forName('com.bla.bla.SomeClass'), 1)" xmlns:xyz="java:com.bla.bla.Xyz" xmlns:class="java:java.lang.Class"/>
>
> But there’s a class-loading issue as I get a ClassNotFound exception:
>
> 12:11:26,508 INFO  [main] JAXPSAXProcessorInvoker  - Transforming...
> net.sf.saxon.trans.XPathException: Exception in extension function java.lang.ClassNotFoundException: com/bla/bla/SomeClass
>        at net.sf.saxon.functions.ExtensionFunctionCall.call(ExtensionFunctionCall.java:368)
>        at net.sf.saxon.functions.ExtensionFunctionCall.iterate(ExtensionFunctionCall.java:224)
> …
>
> After some research on the list I thought I might need to force use of the Thread context class loader, so tried to call the Class.forName method that accepts the class-loader to use:
>
> <xsl:value-of              select="xyz:someStaticMethod(class:forName('com.bla.bla.SomeClass',true,Thread:getContextClassLoader(Thread:currentThread()) ),1)" xmlns:Thread="java:java.lang.Thread" xmlns:xyz="java:com.bla.bla.Xyz" xmlns:class="java:java.lang.Class"  />
>
> But I’m not succeeding – the following exception is complaining about the ‘second argument of class:forName’, but I think it’s actually referring to the third – i.e. that the attempt to find the Thread’s context class loader is returning an empty sequence maybe?
>
> 11:55:21,102 ERROR [main] JAXPSAXProcessorInvoker  - An empty sequence is not allowed as the second argument of class:forName(); SystemID: file:/C:/Users/bandlerp/git/SomeFilePathName.xsl; Line#: 49; Column#: -1
> ; SystemID: file:/C:/Users/bandlerp/git/SomeFilePathName.xsl; Line#: 49; Column#: -1
> net.sf.saxon.trans.XPathException: An empty sequence is not allowed as the second argument of class:forName()
>        at net.sf.saxon.expr.Expression.typeError(Expression.java:981)
>        at net.sf.saxon.expr.CardinalityChecker.evaluateItem(CardinalityChecker.java:277)
> …
>
> I’m using SAXON-B, version 9.0.0.8.
>
> Thanks in anticipation of any suggestions,
>
> Paul Bandler
>
>
>
> This e-mail (including any attachments) is private and confidential, may contain proprietary or privileged information and is intended for the named recipient(s) only. Unintended recipients are strictly prohibited from taking action on the basis of information in this e-mail and must contact the sender immediately, delete this e-mail (and all attachments) and destroy any hard copies. Nomura will not accept responsibility or liability for the accuracy or completeness of, or the presence of any virus or disabling code in, this e-mail. If verification is sought please request a hard copy. Any reference to the terms of executed transactions should be treated as preliminary only and subject to formal written confirmation by Nomura. Nomura reserves the right to retain, monitor and intercept e-mail communications through its networks (subject to and in accordance with applicable laws). No confidentiality or privilege is waived or lost by Nomura by any mistransmission of this e-mail. Any reference to "Nomura" is a reference to any entity in the Nomura Holdings, Inc. group. Please read our Electronic Communications Legal Notice which forms part of this e-mail: http://www.Nomura.com/email_disclaimer.htm
>
> ------------------------------------------------------------------------------
> Announcing the Oxford Dictionaries API! The API offers world-renowned
> dictionary content that is easy and intuitive to access. Sign up for an
> account today to start using our lexical data to power your apps and
> projects. Get started today and enter our developer competition.
> http://sdm.link/oxford
> _______________________________________________
> saxon-help mailing list archived at http://saxon.markmail.org/
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/saxon-help


------------------------------------------------------------------------------
Announcing the Oxford Dictionaries API! The API offers world-renowned
dictionary content that is easy and intuitive to access. Sign up for an
account today to start using our lexical data to power your apps and
projects. Get started today and enter our developer competition.
http://sdm.link/oxford
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help