Hi Rony,

Rony G. Flatscher wrote:
Hi Daniel,

I assume a copy-paste bug in your code:
the type description manager object does not implement XMultiComponentFactory, 
it implements e.g. com.sun.star.container.XHierarchicalNameAccess.
yes, you were right, thank you very much!

Still, while exploring that corner it seems that I am not too successful to

    * a) use "theTypeDescriptionManager.getByHierarchicalName(
      strClassName )"; e.g. receiving an exception
      "<com.sun.star.container.NoSuchElementException:
      com.sun.star.comp.helper.Bootstrap>", if using
      "com.sun.star.comp.helper.Bootstrap" as the class name.

com.sun.star.comp.helper.Bootstrap is an Java UNO helper class and is not available over the type description manager (tdmgr). The tdmgr supports only IDL types. And you should take into account that the normal type library of an office installation doesn't contain type info for old style service types.

    * b) using
      "XTypeDescriptionEnumerationAccess.createTypeDescriptionEnumeration()"
      yields always an empty "XTypeDescriptionEnumeration".

mmh, that is maybe a bug but i am not sure and have to take a closer look into the code.

Juergen



Don't know what I am doing wrong, though.

Maybe, if someone could take a look at the following Java code example (one can compile it and run it supplying the port number to connect to on the commandline):

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

import com.sun.star.beans.PropertyValue;
import com.sun.star.beans.XPropertySet;

import com.sun.star.bridge.XUnoUrlResolver;
import com.sun.star.comp.helper.Bootstrap;

import com.sun.star.container.XHierarchicalNameAccess;

import com.sun.star.frame.XComponentLoader;

import com.sun.star.lang.XMultiComponentFactory;
import com.sun.star.lang.XMultiServiceFactory;
// import com.sun.star.lang.XTypeProvider;

import com.sun.star.reflection.TypeDescriptionSearchDepth;
// import com.sun.star.reflection.XIdlClass;
// import com.sun.star.reflection.XIdlField2;
// import com.sun.star.reflection.XIdlField;
// import com.sun.star.reflection.XIdlMember;
// import com.sun.star.reflection.XIdlMethod;
import com.sun.star.reflection.XIdlReflection;

import com.sun.star.reflection.XInterfaceTypeDescription;
import com.sun.star.reflection.XTypeDescription;
import com.sun.star.reflection.XTypeDescriptionEnumeration;
import com.sun.star.reflection.XTypeDescriptionEnumerationAccess;

import com.sun.star.uno.Any;
import com.sun.star.uno.Type;
import com.sun.star.uno.TypeClass;
import com.sun.star.uno.UnoRuntime;
import com.sun.star.uno.XComponentContext;
import com.sun.star.uno.XCurrentContext;
import com.sun.star.uno.XInterface;
import com.sun.star.uno.XNamingService;


public class TestRgf
{
    static  String                 unoURL=null;
    static  XComponentContext      context=null;
    static  XUnoUrlResolver        xuur=null;
    static  XNamingService         xns=null;
    static  XMultiComponentFactory xmcf=null;
    static  XComponentContext      xcc=null;

    static XIdlReflection                    theCoreReflection=null;
    static XMultiComponentFactory            theServiceManager=null;
    public static XHierarchicalNameAccess    theTypeDescriptionManager=null;

    static void test ()
    {
        String strClass="com.sun.star.uno.Any", strTmp="";

        strClass="com.sun.star.comp.helper.Bootstrap";
         try
         {
                // creates exception 
"com.sun.star.container.NoSuchElementException", no
                // matter which class name gets supplied
             strTmp=theTypeDescriptionManager.getByHierarchicalName( strClass 
).toString();
         }
         catch (Exception e)
         {
             strTmp=e.toString();
         }
         say("test():\tclassName="+pp(strClass)+"\n\tstrTmp="+pp(strTmp));
    }


    static void testTypeDescriptionEnumeration()
    {
        XTypeDescriptionEnumerationAccess  enumerationAccess = 
(XTypeDescriptionEnumerationAccess)
            UnoRuntime.queryInterface(XTypeDescriptionEnumerationAccess.class, 
theTypeDescriptionManager);

        say("testTypeDescriptionEnumeration(): 
enumerationAccess:\n\t"+pp(enumerationAccess));

        try
        {
            TypeClass tc[] = {TypeClass.INTERFACE, TypeClass.SERVICE};
            XTypeDescriptionEnumeration tdEnum=null;
            String module="com.sun.star.reflection";

            tdEnum=enumerationAccess.createTypeDescriptionEnumeration(
                module,                         //  module to analyze
                tc,                             // types to enumerate
                TypeDescriptionSearchDepth.ONE  // ONE level deep only, 
INFINITE possible too
            );
            say("tdEnum="+pp(tdEnum));
            say("\ttdEnum.hasMoreElements()="+pp(""+tdEnum.hasMoreElements()));

            XTypeDescription xtd=null;
            while (tdEnum.hasMoreElements())
            {
                xtd=tdEnum.nextTypeDescription();
                say("\txtd=["+pp(xtd));     // show toString() result
            }
        }
        catch (Exception e)
        {
            say("exception occurred: "+pp(e));
            // e.printStackTrace();
        }
    }


    static void connect(String strPort)
    {
        try
        {
            
unoURL="uno:socket,host=localhost,port="+strPort+";urp;StarOffice.NamingService";
            say("unoURL:\t"+pp(unoURL));

            context=Bootstrap.createInitialComponentContext(null);
            say("context:\t"+pp(context));

            xuur=(XUnoUrlResolver) UnoRuntime.queryInterface(
                XUnoUrlResolver.class,
                context.getServiceManager().createInstanceWithContext(
                        "com.sun.star.bridge.UnoUrlResolver", context)
                );
            say("xuur:\t"+pp(xuur));

            xns=(XNamingService) UnoRuntime.queryInterface(
                XNamingService.class,
                xuur.resolve(unoURL)
                );
            say("xns:\t"+pp(xns));

            xmcf=(XMultiComponentFactory) UnoRuntime.queryInterface(
                XMultiComponentFactory.class,
                xns.getRegisteredObject("StarOffice.ServiceManager")
                );
            say("xmcf:\t"+pp(xmcf));

                // get the default context (should contain the singletons)
            xcc=(XComponentContext) UnoRuntime.queryInterface(
                    XComponentContext.class,
                    ((XPropertySet) UnoRuntime.queryInterface(
                        XPropertySet.class,
                        xmcf)).getPropertyValue("DefaultContext")
                );
            say("xcc:\t"+pp(xcc));
            say("");

                // get singletons
            theCoreReflection=(XIdlReflection) UnoRuntime.queryInterface(
                    XIdlReflection.class,
                    
xcc.getValueByName("/singletons/com.sun.star.reflection.theCoreReflection"));
            say("theCoreReflection:\t"+pp(theCoreReflection));

            theServiceManager=(XMultiComponentFactory) 
UnoRuntime.queryInterface(
                    XMultiComponentFactory.class,
                    
xcc.getValueByName("/singletons/com.sun.star.lang.theServiceManager"));
            say("theServiceManager:\t"+pp(theServiceManager));

            theTypeDescriptionManager=(XHierarchicalNameAccess) 
UnoRuntime.queryInterface(
                    XHierarchicalNameAccess.class,
                    
xcc.getValueByName("/singletons/com.sun.star.reflection.theTypeDescriptionManager"));
            say("theTypeDescriptionManager:\t"+pp(theTypeDescriptionManager));
        }
        catch (Exception e)
        {
            say("sch...");
            e.printStackTrace();
        }
     }


    public static void main(String[] arguments) throws Exception
    {
            // default to port "1234"
        connect( arguments.length==0 ? "1234" : arguments[0] );
        say("---   ---   ---");

        test();
        say("---   ---   ---");

        testTypeDescriptionEnumeration();
        say("---   ---   ---");
        System.exit(0);
    }

    public static void say (String s)
    {
        System.err.println(s);
    }

    public static String pp (Object o)
    {
        if (o==null) return "<null> <-- <-- <--";
        return "<"+o+">";
    }

}

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


The output on my machine:

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

F:\work\tmp\ooo\tst>javac TestRgf.java && java TestRgf 8100
unoURL: <uno:socket,host=localhost,port=8100;urp;StarOffice.NamingService>
context:        <[EMAIL PROTECTED]>
xuur:   <[EMAIL PROTECTED]>
xns:    
<[Proxy:3736006,413c3d0;msci[0];8331bd1159211daa868ae7518a58f,Type[com.sun.star.uno.XNamingService]]>
xmcf:   
<[Proxy:18734302,352a48;msci[0];8331bd1159211daa868ae7518a58f,Type[com.sun.star.lang.XMultiComponentFactory]]>
xcc:    
<[Proxy:23195919,3578c8;msci[0];8331bd1159211daa868ae7518a58f,Type[com.sun.star.uno.XComponentContext]]>

theCoreReflection:      
<[Proxy:21539363,413c2f0;msci[0];8331bd1159211daa868ae7518a58f,Type[com.sun.star.reflection.XIdlReflection]]>
theServiceManager:      
<[Proxy:18734302,352a48;msci[0];8331bd1159211daa868ae7518a58f,Type[com.sun.star.lang.XMultiComponentFactory]]>
theTypeDescriptionManager:      
<[Proxy:17977639,35a1e8;msci[0];8331bd1159211daa868ae7518a58f,Type[com.sun.star.container.XHierarchicalNameAccess]]>
---   ---   ---
test(): className=<com.sun.star.comp.helper.Bootstrap>
        strTmp=<com.sun.star.container.NoSuchElementException: 
com.sun.star.comp.helper.Bootstrap>
---   ---   ---
testTypeDescriptionEnumeration(): enumerationAccess:
        
<[Proxy:11935697,35a1e8;msci[0];8331bd1159211daa868ae7518a58f,Type[com.sun.star.reflection.XTypeDescriptionEnumerationAccess]]>
tdEnum=<[Proxy:29987161,3ccfa58;msci[0];8331bd1159211daa868ae7518a58f,Type[com.sun.star.reflection.XTypeDescriptionEnumeration]]>
        tdEnum.hasMoreElements()=<false>
---   ---   ---

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

Again, any help/hint highly appreciated!


---rony



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to