Skip to main content
Participant
May 29, 2019
Answered

reference to java class

  • May 29, 2019
  • 1 reply
  • 617 views

I'm looking to convert libreoffice java example to cfm but j don't undestand how reference to "XComponentLoader.class" before create it

this row are ok

<cfset OOB = createObject("java","com.sun.star.comp.helper.Bootstrap")/>

<cfset xContext = OOB.bootstrap()>

<cfset xMCF = xContext.getServiceManager()>

<cfset desktop = xMCF.createInstanceWithContext("com.sun.star.frame.Desktop", xContext)>

<cfset UnoRuntime = createObject("java","com.sun.star.uno.UnoRuntime")/>

this is then row to convert

     XComponentLoader xCompLoader = UnoRuntime.queryInterface(XComponentLoader.class, xDesktop);

I try:

1)

<cfset xComponentLoader = UnoRuntime.queryInterface(XComponentLoader.class, desktop)>

2)

<cfset myloader = createObject("java","com.sun.star.frame.XComponentLoader")/>

<cfset xComponentLoader = UnoRuntime.queryInterface(myloader.class, desktop)>

3)

<cfobject type="Java" class="com.sun.star.frame.XComponentLoader.class" name="myloader" action="create">

<cfset xComponentLoader = UnoRuntime.queryInterface(myloader, desktop)>

but no one work

any ideas or j've to pass to cfx ?

    This topic has been closed for replies.
    Correct answer kazu98296633

    possibly

    <cfset cls = CreateObject("java", "java.lang.Class")>

    <cfset xCompLoaderClass = cls.forName("com.sun.star.frame.XComponentLoader")>

    or

    <cfset XCompLoader = CreateObject("java", "com.sun.star.frame.XComponentLoader")>

    <cfset xCompLoaderClass = XCompLoader.getClass()>

    then

    <cfset xCompLoader = UnoRuntime.queryInterface(xCompLoaderClass, desktop)>

    1 reply

    Community Expert
    May 29, 2019

    This is just a shot in the dark, I'm not testing this code sample. It looks like your variable names in your code examples don't match up with the ones in the Java code, though.

    Java code:

    XComponentLoader xCompLoader = UnoRuntime.queryInterface(XComponentLoader.class, xDesktop);

    CFML code:

    <cfset xCompLoader = createObject("java","com.sun.star.frame.XComponentLoader")>

    <cfset xCompLoader = UnoRuntime.queryInterface(XComponentLoader.class, desktop)>

    You might be able to string these together using method chaining:

    <cfset xCompLoader = createObject("java","com.sun.star.frame.XComponentLoader").UnoRuntime.queryInterface(XComponentLoader.class, desktop)>

    Dave Watts, Eidolon LLC

    Dave Watts, Eidolon LLC
    bagigioAuthor
    Participant
    May 29, 2019

    it still don't work, with

    <cfset xCompLoader = createObject("java","com.sun.star.frame.XComponentLoader")>

    <cfset xCompLoader = UnoRuntime.queryInterface(XComponentLoader.class, desktop)>

    return the error

    Element CLASS is undefined in XCOMPONENTLOADER.

    and with

    <cfset xCompLoader = createObject("java","com.sun.star.frame.XComponentLoader").UnoRuntime.queryInterface(XComponentLoader.class, desktop)>

    return the error

    Element UNORUNTIME is undefined in a Java object of type class coldfusion.runtime.StructBean. 

    kazu98296633Correct answer
    Participating Frequently
    May 30, 2019

    possibly

    <cfset cls = CreateObject("java", "java.lang.Class")>

    <cfset xCompLoaderClass = cls.forName("com.sun.star.frame.XComponentLoader")>

    or

    <cfset XCompLoader = CreateObject("java", "com.sun.star.frame.XComponentLoader")>

    <cfset xCompLoaderClass = XCompLoader.getClass()>

    then

    <cfset xCompLoader = UnoRuntime.queryInterface(xCompLoaderClass, desktop)>