Reflection returns com.sun.star.uno.XInterface type for all objects

198 Views Asked by At

The getType method is supposed to return an object which represents the type of the item passed into the method:

var serviceManager = new ActiveXObject('com.sun.star.ServiceManager');
var desktop = serviceManager.createInstance("com.sun.star.frame.Desktop");
var document = desktop.loadComponentFromURL("private:factory/swriter", "_blank", 0, []);
var coreReflection = serviceManager.createInstance("com.sun.star.reflection.CoreReflection");

// should return a type representing the com.sun.star.frame.Desktop type
var classInfo = coreReflection.getType(desktop);

However, the classInfo always seems to contain the com.sun.star.uno.XInterface type:

// outputs com.sun.star.uno.XInterface
WScript.Echo(classInfo.getName());

Even if I pass in other objects, the output is the same:

classInfo = coreReflection.getType(document);
WScript.Echo(classInfo.getName());

How can I find out the actual type?

(Originally posted at ask.libreoffice)

1

There are 1 best solutions below

0
On

I believe you are looking for the "implementation name" rather than the "interface type name."

The following code adapted from XrayTool results in the message com.sun.star.comp.framework.Desktop (comp here can perhaps be ignored).

WScript.Echo(desktop.ImplementationName)

There is also a good approach which however is available only for Basic.

obj = createUnoService("com.sun.star.frame.Desktop")
MsgBox obj.DBG_Properties

This will produce a long message, starting out with Properties of object "com.sun.star.frame.Desktop".

Finally, don't forget about supportsService, although it may not be as relevant for your particular use case. When writing macros, the preferred way is to check whether a particular object supports a service rather than checking what type the object actually is.