20080913, rgf

org.oorexx.uno
Class RgfReflectUNO

java.lang.Object
  extended byorg.oorexx.uno.RgfReflectUNO

public class RgfReflectUNO
extends java.lang.Object

This class allows reflecting UNO objects and types using the type descriptions and usually returns results as strings only (to facilitate interaction with scripting languages); originally devised for Open Object Rexx (cf. http://www.ooRexx.org).

------------------------ Apache Version 2.0 license -------------------------
    Copyright (C) 2006-2007 Rony G. Flatscher

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

        http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
 ----------------------------------------------------------------------------- 

Version:
1.0.1, 2007-07-07
Author:
Rony G. Flatscher

Field Summary
(package private) static boolean bDebug
          Controls issuing some debug messages, if set to true.
(package private) static com.sun.star.uno.XComponentContext context
           
(package private) static int GET_INTERFACES_AS_ARRAY
           
(package private) static int GET_INTERFACES_AS_STRING
           
(package private) static int GET_SERVICES_AS_ARRAY
           
(package private) static int GET_SERVICES_AS_STRING
           
(package private) static java.util.Hashtable ht
           
(package private) static java.util.Hashtable ht2j
           
(package private) static java.util.Hashtable ht2j_prop
           
(package private) static boolean isContextAvailable
           
(package private) static java.util.Hashtable pa
           
(package private) static int QUERY_INTERFACE_NAME
           
(package private) static int QUERY_INTERFACE_OBJECT_BY_NAME
          Analyzes all implemented services and processes found interfaces or services.
(package private) static int SERVICE_NUMBERING
           
(package private) static com.sun.star.reflection.XIdlReflection theCoreReflection
           
(package private) static com.sun.star.lang.XMultiComponentFactory theServiceManager
           
(package private) static com.sun.star.container.XHierarchicalNameAccess theTypeDescriptionManager
           
(package private) static int USE_VECTOR
           
static java.lang.String version
          Version string indicating version of this class (majorVersion*100+minorVersion concatenated with a dot and the sorted date of last change.
(package private) static com.sun.star.lang.XMultiComponentFactory xmcf
           
 
Method Summary
(package private) static java.lang.String check4reflection(java.lang.String name)
          2005-12-20: turns out that OOo 2.0 and 1.5 have the module name "com.sun.star.text.TextField.
(package private) static boolean compareRelaxed(java.lang.String endName, java.lang.String haystack)
          Compares two strings in a "relaxed" manner, i.e.
(package private) static java.lang.Object[] determineTypeClass(java.lang.Object o)
          Determines the XIdlClass/XTypeDescription and TypeClass of the supplied UNO object/UNOIDL string.
(package private) static void encode4InterfaceXIMTD(java.lang.StringBuffer sb, com.sun.star.reflection.XInterfaceMemberTypeDescription ximtd, char delimiter)
           
(package private) static java.lang.Object extendSearch(java.lang.Object o, java.lang.String needle, int kind)
           
static java.lang.Object findInterfaceWithMember(java.lang.Object o, java.lang.String needle, boolean bReturnString, int howMany, boolean bExtendSearch)
          Looks for the interface in a service object (o) containing a member (a method or attribute) of the given name.
(package private) static java.lang.Object fIWM_worker(java.lang.Object o, java.lang.String needle, java.lang.String interfaceName, boolean bReturnString, java.lang.StringBuffer sb, int countFound, int howMany)
           
static com.sun.star.uno.XComponentContext getContext()
          Returns the value of the current XComponentObject in use, or null, if not set yet.
static java.lang.String getDefinition(java.lang.Object o)
          Returns a blank delimited string containing the UNOIDL definitions of an UNO object (or a string denoting the fully qualified UNOIDL name).
static java.lang.String getInterfaceNamesViaReflection(java.lang.Object o)
          Returns a blank delimited String of the interface names that are defined in UNOIDL for the service object.
static java.lang.String getProperties(java.lang.Object o)
          Creates and returns a blank delimited string of property definitions available for the service object o.
static java.lang.String getServiceNamesViaReflection(java.lang.Object o)
          Returns a blank delimited String of service names that are defined in UNOIDL for the service object.
static java.lang.String getTypeName(java.lang.Object o)
          Returns string indicating the type of the supplied UNO object.
(package private) static java.lang.String getUnqualifiedName(java.lang.String s)
          Returns unqualified name (string after the last dot) from dotted string or string itself, if no dot in string.
(package private) static com.sun.star.reflection.XTypeDescription getXTypeDescription(com.sun.star.reflection.XIdlClass xic)
          Returns a XTypeDescription object representing the received XIdlClass object.
static java.lang.String getXTypeProviderTypeNames(java.lang.Object o)
          Returns a blank delimited string of names of the provided interface types.
(package private) static java.lang.String pp(java.lang.Object o)
          Convenience method, returns argument enclosed in angle brackets, allows null as well.
static java.lang.String queryInterfaceName(java.lang.Object o, java.lang.String name, boolean bExtendSearch)
          Looks up a (partially qualified) given interface name case-insensitively and returns the fully-qualified mixed case interface name.
static java.lang.Object queryInterfaceObjectByName(java.lang.Object o, java.lang.String name, boolean bExtendSearch)
          Looks up a (partially qualified) given interface name case-insensitively, carries out the appropriate UnoRuntime.queryInterface() and returns its result.
static java.lang.String queryServiceName(java.lang.Object o, java.lang.String name)
          Looks up a (partially qualified) given service name case-insensitively and returns the fully-qualified mixed case service name.
(package private) static void say(java.lang.String s)
          Convenience method, will print received string to System.err.
static com.sun.star.uno.XComponentContext setContext(com.sun.star.uno.XComponentContext ctxt)
          Sets the component context and gets singletons and type descriptions from it.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

version

public static java.lang.String version
Version string indicating version of this class (majorVersion*100+minorVersion concatenated with a dot and the sorted date of last change.


bDebug

static boolean bDebug
Controls issuing some debug messages, if set to true. Default value: false.


context

static com.sun.star.uno.XComponentContext context

isContextAvailable

static boolean isContextAvailable

xmcf

static com.sun.star.lang.XMultiComponentFactory xmcf

theCoreReflection

static com.sun.star.reflection.XIdlReflection theCoreReflection

theServiceManager

static com.sun.star.lang.XMultiComponentFactory theServiceManager

theTypeDescriptionManager

static com.sun.star.container.XHierarchicalNameAccess theTypeDescriptionManager

ht

static java.util.Hashtable ht

ht2j

static java.util.Hashtable ht2j

ht2j_prop

static java.util.Hashtable ht2j_prop

pa

static java.util.Hashtable pa

QUERY_INTERFACE_OBJECT_BY_NAME

static final int QUERY_INTERFACE_OBJECT_BY_NAME
Analyzes all implemented services and processes found interfaces or services.

See Also:
Constant Field Values

QUERY_INTERFACE_NAME

static final int QUERY_INTERFACE_NAME
See Also:
Constant Field Values

USE_VECTOR

static final int USE_VECTOR
See Also:
Constant Field Values

GET_INTERFACES_AS_STRING

static final int GET_INTERFACES_AS_STRING
See Also:
Constant Field Values

GET_INTERFACES_AS_ARRAY

static final int GET_INTERFACES_AS_ARRAY
See Also:
Constant Field Values

SERVICE_NUMBERING

static final int SERVICE_NUMBERING
See Also:
Constant Field Values

GET_SERVICES_AS_STRING

static final int GET_SERVICES_AS_STRING
See Also:
Constant Field Values

GET_SERVICES_AS_ARRAY

static final int GET_SERVICES_AS_ARRAY
See Also:
Constant Field Values
Method Detail

getContext

public static com.sun.star.uno.XComponentContext getContext()
Returns the value of the current XComponentObject in use, or null, if not set yet.

Returns:
The component context object that is used for this class or null, if not set.

setContext

public static com.sun.star.uno.XComponentContext setContext(com.sun.star.uno.XComponentContext ctxt)
Sets the component context and gets singletons and type descriptions from it. (Will invoke the private method "setUpPropertyAttributesHashTable()".)

Parameters:
ctxt - component context object to be used for this class, if null, then a default component context is created using "com.sun.star.comp.helper.Bootstrap.bootstrap()".
Returns:
The component context object that is used for this class.

determineTypeClass

static java.lang.Object[] determineTypeClass(java.lang.Object o)
Determines the XIdlClass/XTypeDescription and TypeClass of the supplied UNO object/UNOIDL string.

Parameters:
o - UNO object or String fully qualifying the module name
Returns:
Object array having object o's XIdlClass or XTypeDescription at index [0], object o's TypeClass at index [1], received "o" at index [2], free slot at index [3]

getTypeName

public static java.lang.String getTypeName(java.lang.Object o)
Returns string indicating the type of the supplied UNO object. All of the possible return values are documented at the end of getDefinition(Object o) ("…strings representing UNO-Types…").

Parameters:
o - UNO object or fully qualified string referring to an UNOIDL definition
Returns:
String spelling out the UNO type or empty string, if type cannot be determined

getDefinition

public static java.lang.String getDefinition(java.lang.Object o)
Returns a blank delimited string containing the UNOIDL definitions of an UNO object (or a string denoting the fully qualified UNOIDL name).
Here are the encodings for the different UNOIDL types:

TypeClass Encoding
UNO_CONSTANTS UNO_CONSTANTS|fully-qualified-name|datatypemember-name|value…

Remark: the following UNO "datatype"s are allowed for constants:
UNO_BOOLEAN (Java: boolean), UNO_BYTE (Java: byte), UNO_SHORT (Java: short), UNO_UNSIGNED_SHORT (Java: short), UNO_LONG (Java: int), UNO_UNSIGNED_LONG (Java: int), UNO_HYPER (Java: long), UNO_UNSIGNED_HYPER (Java: long), UNO_FLOAT (Java: float), UNO_DOUBLE (Java: double).
UNO_ENUM UNO_ENUM|fully-qualified-name|default-valuemember-name|value…

Remark: this is always of UNO type UNO_LONG (ie. a 32-bit integer, Java type: int)

UNO_EXCEPTION UNO_EXCEPTION|fully-qualified-namemember-name|fullDatatype
UNO_INTERFACE UNO_INTERFACE|fully-qualified-namemember-name|member-definition…

where "member-definition" is one of:

  • UNO_ATTRIBUTE|[READONLY]|fullDatatype…

  • UNO_METHOD|[ONEWAY]|return-value-fullDatatype|[argName:fullDatatype[,…]|[exception[,…]]
UNO_MODULE UNO_MODULE|fully-qualified-namefully-qualified-member-name|UNO-Type…
UNO_SERVICE UNO_SERVICE|fully-qualified-name|[implementationName] member-name|member-definition…

where "member-definition" is one of:

  • UNO_INTERFACE|[OPTIONAL]|defined_by_service

  • UNO_SERVICE|[OPTIONAL]|defined_by_service

  • UNO_PROPERTY|[modifier[,…]]|fullDatatype|defined_by_service

Remark: if a service object is reflected that implements more than one service definition, than the "fully-qualified-name" of that compound service is created by concatenating all service names with the plus sign (+). Each of these constituting service definitions (if available via reflection) is then used to create the entire definition of that "compound service" object in hand, documenting all defined interfaces, services and properties.

Remark ad "UNO_PROPERTY": the modifier values may be one or a (comma-delimited) combination of: "MAYBEVOID", "BOUND", "CONSTRAINED", "TRANSIENT", "READONLY", "MAYBEAMBIGUOUS", "MAYBEDEFAULT", "REMOVEABLE", "OPTIONAL".

UNO_SINGLETON UNO_SINGLETON|fully-qualified-name|[old-style-servicename]

Remark: old-style-servicename or empty string if an instance of an interface

UNO_STRUCT UNO_STRUCT|fully-qualified-namemember-name|fullDatatype…
UNO_TYPEDEF UNO_TYPEDEF|fully-qualified-namereferenced-type|UNO-Type


"fullDatatype" is encoded as follows:

fully-qualified-datatype-name:UNO-TypeClass:[referenced-type]:[UNO-TypeClass]

If a datatype is of type UNO_TYPEDEF, then its "referenced-type-name" is given together with its respective UNO-TypeClass.


The following strings representing UNO-Types ("TypeClasses") may be encountered:

"UNO_ANY", "UNO_ARRAY", "UNO_BOOLEAN", "UNO_BYTE", "UNO_CHAR", "UNO_CONSTANT", "UNO_CONSTANTS", "UNO_DOUBLE", "UNO_ENUM", "UNO_EXCEPTION", "UNO_FLOAT", "UNO_HYPER", "UNO_INTERFACE", "UNO_INTERFACE_ATTRIBUTE" "UNO_INTERFACE_METHOD", "UNO_LONG", "UNO_MODULE", "UNO_PROPERTY", "UNO_SEQUENCE", "UNO_SERVICE", "UNO_SHORT", "UNO_SINGLETON", "UNO_STRING", "UNO_STRUCT", "UNO_TYPE", "UNO_TYPEDEF", "UNO_UNION", "UNO_UNKNOWN", "UNO_UNSIGNED_HYPER", "UNO_UNSIGNED_LONG", "UNO_UNSIGNED_SHORT", "UNO_VOID".

Remark: The UNO "TypeClass" constant names use the respective names above, but without the lead-in string "UNO_" (this makes the type information from methods of this class unambiguous).


The UNO datatypes map to Java as follows:

UNO Datatype Java Datatype
UNO_ANY com.sun.star.uno.Any or java.lang.Object
UNO_VOID void
UNO_BOOLEAN boolean
UNO_BYTE (8-bit) byte
UNO_CHAR (16-bit) char
UNO_SHORT (16-bit) short
UNO_UNSIGNED_SHORT (16-bit) short
UNO_LONG (32-bit) int
UNO_UNSIGNED_LONG (32-bit) int
UNO_HYPER (64-bit) long
UNO_UNSIGNED_HYPER (64-bit) long
UNO_FLOAT float
UNO_DOUBLE double

Parameters:
o - UNO service object or string fully qualifying a service definition in an UNOIDL module
Returns:
string containing the UNOIDL definitions, each element delimited with a blank, each element's definition parts delimited with a vertical bar (|).

getXTypeDescription

static com.sun.star.reflection.XTypeDescription getXTypeDescription(com.sun.star.reflection.XIdlClass xic)
Returns a XTypeDescription object representing the received XIdlClass object.

Parameters:
xic - an XIdlClass object.
Returns:
a XTypeDescription object or null, if not found.

encode4InterfaceXIMTD

static void encode4InterfaceXIMTD(java.lang.StringBuffer sb,
                                  com.sun.star.reflection.XInterfaceMemberTypeDescription ximtd,
                                  char delimiter)

getXTypeProviderTypeNames

public static java.lang.String getXTypeProviderTypeNames(java.lang.Object o)
Returns a blank delimited string of names of the provided interface types. Cf. UNO's com.sun.star.lang.XTypeProvider interface which is applied to the service object o.

Parameters:
o - a service object which gets queried of its provided interface types using the XTypeProvider interface
Returns:
blank delimited string of interface names, empty string if none available

queryInterfaceObjectByName

public static java.lang.Object queryInterfaceObjectByName(java.lang.Object o,
                                                          java.lang.String name,
                                                          boolean bExtendSearch)
Looks up a (partially qualified) given interface name case-insensitively, carries out the appropriate UnoRuntime.queryInterface() and returns its result.

Parameters:
name - which may qualify the desired interface fully or partly, case does not matter either. If name denotes an existing Java class, that class is used to carry out the UnoRuntime.queryInterface(...). Otherwise an interface class is searched at runtime using XTypeProvider and possibly reflection.
o - is the object from which the interface should be queried from
bExtendSearch - true: if interface cannot be found in the XTypeProvider list, then extend search using full reflection; it could be the case that XTypeProvider does not provide all available interfaces! (as of OOo 2.0, 2005-12-20)
Returns:
the desired interface object, if successful, null else

getInterfaceNamesViaReflection

public static java.lang.String getInterfaceNamesViaReflection(java.lang.Object o)
Returns a blank delimited String of the interface names that are defined in UNOIDL for the service object.

Parameters:
o - service object to analyze
Returns:
a blank delimited string of service names (or empty string)

getServiceNamesViaReflection

public static java.lang.String getServiceNamesViaReflection(java.lang.Object o)
Returns a blank delimited String of service names that are defined in UNOIDL for the service object.

Parameters:
o - service object to analyze
Returns:
a blank delimited string of service names (or empty string)

extendSearch

static java.lang.Object extendSearch(java.lang.Object o,
                                     java.lang.String needle,
                                     int kind)

getProperties

public static java.lang.String getProperties(java.lang.Object o)
Creates and returns a blank delimited string of property definitions available for the service object o. To find out about all available interfaces in a service object at runtime use getXTypeProviderTypeNames(Object o), to find the interface in which a member (a method or an attribute) got defined at runtime use findInterfaceWithMember(Object o, String needle, boolean bReturnString, int howMany, boolean bExtendSearch).

Parameters:
o - a service object
Returns:
blank delimited string of property definitions in the form property-name|full-datatype-name:UNO-TypeClass:[referenced-type]:[UNTO-TypeClass].

findInterfaceWithMember

public static java.lang.Object findInterfaceWithMember(java.lang.Object o,
                                                       java.lang.String needle,
                                                       boolean bReturnString,
                                                       int howMany,
                                                       boolean bExtendSearch)
Looks for the interface in a service object (o) containing a member (a method or attribute) of the given name. This method uses the XTypeProvider interface to search the available interfaces at runtime. To find out about all properties of a service object at runtime use getProperties(Object o).

Parameters:
o - service object to analyze
needle - denotes the name to look for case-independently
bReturnString - if true then the string encoded INTERFACE information (cf. getDefinition(Object o)) is returned having the denoted member(s), otherwise the queried interface object is returned, which can be immediately addressed to invoke the member method or access the member attribute.
howMany - determines how many members matching needle should be searched and returned. Only relevant, if bReturnString is true. interfaces that contain the sought for member should be returned. A number less than 1 indicates to return all matching interface definitions (separated by a newline character 0x0A).
bExtendSearch - true: if interface cannot be found in the XTYpeProvider list, then extend search using full reflection; it could be the case that XTYpeProvider does not provide all available interfaces! (as of OOo 2.0, 2005-12-20)
Returns:
either a string (bReturnString==true, can be empty, if no definitions were found) or the desired interface object (bReturnString==false, can be null null) depending on the value of parameter

fIWM_worker

static java.lang.Object fIWM_worker(java.lang.Object o,
                                    java.lang.String needle,
                                    java.lang.String interfaceName,
                                    boolean bReturnString,
                                    java.lang.StringBuffer sb,
                                    int countFound,
                                    int howMany)

queryInterfaceName

public static java.lang.String queryInterfaceName(java.lang.Object o,
                                                  java.lang.String name,
                                                  boolean bExtendSearch)
Looks up a (partially qualified) given interface name case-insensitively and returns the fully-qualified mixed case interface name.

Parameters:
o - service object to analyze
name - denotes the name to look for case-independently
bExtendSearch - true: if interface cannot be found in the XTYpeProvider list, then extend search using full reflection; it could be the case that XTYpeProvider does not provide all available interfaces! (as of OOo 2.0, 2005-12-20)
Returns:
fully-qualified interface name or empty string, if not found.

queryServiceName

public static java.lang.String queryServiceName(java.lang.Object o,
                                                java.lang.String name)
Looks up a (partially qualified) given service name case-insensitively and returns the fully-qualified mixed case service name.

Parameters:
o - service object to analyze
name - denotes the name to look for case-independently
Returns:
fully-qualified service name or empty string, if not found.

compareRelaxed

static boolean compareRelaxed(java.lang.String endName,
                              java.lang.String haystack)
Compares two strings in a "relaxed" manner, i.e. tests case-insensitively, whether the second argument haystack ends with the first argument endName string.

Parameters:
endName - the string which should end haystack
haystack - the string to test endName against
Returns:
true, if haystack ends with the string endName (comparison carried out case-insensitively), false else

say

static void say(java.lang.String s)
Convenience method, will print received string to System.err.


pp

static java.lang.String pp(java.lang.Object o)
Convenience method, returns argument enclosed in angle brackets, allows null as well.


getUnqualifiedName

static java.lang.String getUnqualifiedName(java.lang.String s)
Returns unqualified name (string after the last dot) from dotted string or string itself, if no dot in string.

Parameters:
s - String to extract unqualified name
Returns:
returns unqualified name or s, if no dot in string

check4reflection

static java.lang.String check4reflection(java.lang.String name)
2005-12-20: turns out that OOo 2.0 and 1.5 have the module name "com.sun.star.text.TextField." spelled wrongly, ".TextField" should be spelled in lowercase: ".textfield.".


20080913, rgf