Hi there,

not sure whether "dev@openoffice.org" would be the "better" list for
this question, hence cc:'ing it, but reply-to is set to point to
"d...@api.openoffice.org". Please advise, if another e-mail-list would be
better.

rony wrote:
> Hi there,
>
> it seems that if using XDispatchHelper.executeDisptatch(...) from Java
> the argument list (fifth argument being an array of type PropertyValue)
> gets a Boolean entry appended (that is always set to true). Is that
> truly the case? (If so, where would that be documented?)
>
> Using OOo 3.0.0 (O300m9, build:9358) and the Java interface to OOo to
> invoke "executeDispatch()". Online documentation
> <http://api.openoffice.org/docs/common/ref/com/sun/star/frame/XDispatchHelper.html#executeDispatch>,
> looking up Parameter "Arguments".
>
> TIA,
>
> ---rony
>
>   
Maybe this was not enough information, so:

    * Using XDispatchHelpter.executeDispatch(...), allows one to supply
      five arguments, the last argument being an array of PropertyValues,
    * Using the OOo scripting framework, the method "invoke(Object[]
      aParams, short[][] aOutParamIndex, Object[][] aOutParams)" of the
      "com.sun.star.script.framework.provider.XXX.ScriptProviderForXXX" 
      class is invoked (where "XXX" stands for the scripting language
      this class will serve).
          o "aParams" will have always one argument more than supplied
            by "XDispatchHelpter.executeDispatch(...)", and that
            argument is of type Boolean (in my case always set to "true".

Here's an example Java code that employs
"XDispatchHelper.executeDispatch(...)":

----------------- cut here ----------------

// ---rgf, 2009-02-11, Java program to invoke "createApiInfo.rex" from Java

import com.sun.star.beans.PropertyValue;
import com.sun.star.frame.XComponentLoader;
import com.sun.star.frame.XDesktop;
import com.sun.star.frame.XDispatchHelper;
import com.sun.star.frame.XDispatchProvider;
import com.sun.star.lang.XMultiComponentFactory;
import com.sun.star.lang.XMultiServiceFactory;
import com.sun.star.uno.UnoRuntime;
import com.sun.star.uno.XComponentContext;
import com.sun.star.frame.DispatchResultEvent;

class TestCreateApiInfo {
    public static void main (String args[]) {
        // excerpted from "HardFormatting.java" from the OOo development package
        XDesktop              xDesktop = null;
        XMultiComponentFactory xMCF     = null;
        XMultiServiceFactory   xMSF     = null;

        try {
            XComponentContext xContext = null;

            // bootstrap the UNO runtime environment
            xContext = com.sun.star.comp.helper.Bootstrap.bootstrap();

            // get the service manager
            xMCF = xContext.getServiceManager();
            xMSF = (XMultiServiceFactory) 
UnoRuntime.queryInterface(XMultiServiceFactory.class, xMCF);

            if (xMSF!=null)
            {
                System.out.println("Connected to a running office ...");

                // get XDispatchProvider from XDesktop
                Object oDesktop = 
xMSF.createInstance("com.sun.star.frame.Desktop");
                xDesktop = (XDesktop) UnoRuntime.queryInterface(XDesktop.class, 
oDesktop);
                XDispatchProvider xDispatchProvider=(XDispatchProvider)
                        UnoRuntime.queryInterface(XDispatchProvider.class, 
xDesktop);


                Object sDispatchHelper= 
xMSF.createInstance("com.sun.star.frame.DispatchHelper");
                XDispatchHelper xDispatchHelper=(XDispatchHelper)
                        UnoRuntime.queryInterface(XDispatchHelper.class, 
sDispatchHelper);


                // define arguments
                PropertyValue propValue=new PropertyValue();
                propValue.Name="arg1";              // not used, but what the 
heck
                propValue.Value=sDispatchHelper;    // an UNO object (could be 
an UNO IDL string instead)

                PropertyValue parameters[]={propValue};

                // invoke the ooRexx script to document the UNO object/IDL
                String location="user"; // "user" or "share" or "application"
                String 
macroUrl="vnd.sun.star.script:wu_tools.createApiInfo.rex?language=ooRexx&location="
                    +location;

                // dispatch, supplying arguments
                DispatchResultEvent dre=(DispatchResultEvent)
                      xDispatchHelper.executeDispatch(
                            xDispatchProvider,  // XDispatchProvider
                            macroUrl,           // URL
                            "",                 // TargetFrameName
                            0,                  // SearchFlags
                            parameters);        // Arguments

                System.out.println("Returned from executing dispatch, 
Result=["+dre.Result+"], State=["+dre.State+"]");
            }
        }
        catch( Exception e) {
            e.printStackTrace(System.err);
            System.exit(1);
        }

        System.err.println("Successful run.");
        System.exit(0);
    }
}


----------------- cut here ----------------

In this case an ooRexx macro/script is invoked. ooRexx can handle
variable numbers of arguments and in this case there may be up to eight
arguments supplied, but one can omit all but the very first argument.
Now, if OOo supplies one argument too many, this interferes quite
heavily as from the perspective of the receiving (ooRexx) side one
cannot determine whether OOo injected an argument of its own or not.

Looking through the sources of the OOo scripting framework there seems
to be no statement there that appends that argument, so I assume it
happens either in executeDispatch(...) or somewhere on the way to the
scripting framework invocation.

I would really appreciate if anyone could shed some light on this!

---rony




Reply via email to