Project

Profile

Help

Saxon with ColdFusion - StaticQueryContext

Added by Anonymous over 19 years ago

Legacy ID: #3274003 Legacy Poster: jim collins (jimcollins)

Does anyone have any experience using Saxon with ColdFusion? Some sample code would be nice. Without access to the classpath on shared hosting, I'm having a classpath issue loading StaticQueryContext Normally we would use: <cfset SaxonStaticQuery = loader.LoadClass("net.sf.saxon.query.StaticQueryContext").newInstance()> using Spike's reflector code, but in this case it throws an error.. This works fine: <cfset SaxonConfig = loader.loadClass("net.sf.saxon.Configuration").newInstance() /> I know someone is going to ask "What's Spikes reflector code", so heres the code in the form of a CFC: <cffunction name="Load"> <cfargument name="class" required="true" /> <cfargument name="jar" required="true" /> <cfset var currentdirectory = "" /> <cfset var URLObject = "" /> <cfset var ArrayClass = "" /> <cfset var loader = "" /> <cfset currentDirectory = expandPath("./")> <!--- Turn any \ in the path into / so java doesnt spit the dummy ---> <cfset currentDirectory = replace(currentDirectory,"&quot;,"/","all")> <!--- Create an instance of java.net.URL for passing to the URLClassLoader ---> <cfset URLObject = createObject('java','java.net.URL')> <!--- Initialize the object with the jar file ---> <cfset URLObject.init("file:"&currentDirectory&jar)> <!--- Create a java Array and add our URLObject to it ---> <cfset URLArray = createObject("java","java.lang.reflect.Array").newInstance(URLObject.getClass(),1)> <cfset ArrayClass = createObject("java","java.lang.reflect.Array")> <cfset ArrayClass.set(URLArray,0,URLObject)> <!--- Create and the URLClassLoader and pass it the array containing our path ---> <cfset loader = createObject("java","java.net.URLClassLoader")> <cfset loader.init(URLArray)> <!--- Use our new class loader to load the Configurator class ---> <cfset OurObject = loader.loadClass(class).newInstance() /> <cfreturn OurObject /> </cffunction>


Replies (2)

RE: Saxon with ColdFusion - StaticQueryContex - Added by Anonymous over 19 years ago

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

What a horrible way to have to write your code. It's failing, presumably, because StaticQueryContext does not have a default (zero-argument) constructor (or rather, it has one, but it's private). The only public constructor requires a Configuration object as an argument. You can of course call non-default constructors using Java reflection, but it's no fun. Michael Kay

RE: Saxon with ColdFusion - StaticQueryContex - Added by Anonymous over 19 years ago

Legacy ID: #3283423 Legacy Poster: jim collins (jimcollins)

I can't even use reflection... <cfset constructor = loader.LoadClass("net.sf.saxon.query.StaticQueryContext").getConstructor(SaxConfigAry)/> throws an error ............

    (1-2/2)

    Please register to reply