Language

The Free and Open Productivity Suite
Released: Apache OpenOffice 4.1.13
UNO Java Runtime

com.sun.star.uno
Class UnoRuntime

java.lang.Object
  |
  +--com.sun.star.uno.UnoRuntime

public class UnoRuntime
extends java.lang.Object

The UnoRuntime class is the central class needed for implementing or using UNO components in Java.

The Methods queryInterface and isSame delegate calls to the implementing objects and are used instead of casts and identity comparisons.

The other methods are used for managing bridges, which enable a user to map objects out to or into java.

Since:
UDK1.0
See Also:
IEnvironment, IQueryInterface, IBridge

Field Summary
protected static com.sun.star.lib.util.WeakTable __bridges
           
protected static com.sun.star.lib.util.WeakTable __environments
           
static boolean DEBUG
           
 
Constructor Summary
UnoRuntime()
           
 
Method Summary
static boolean areSame(java.lang.Object object1, java.lang.Object object2)
          Tests if the given objects are interfaces of the same underlying object.
static java.lang.String generateOid(java.lang.Object object)
          Generates a worldwide unique object identifier (oid) for the given object.
static IBridge getBridge(IEnvironment from, IEnvironment to, java.lang.Object[] args)
          Gets a bridge from environment from to environment to.
static IBridge getBridgeByName(java.lang.String from, java.lang.Object from_context, java.lang.String to, java.lang.Object to_context, java.lang.Object[] args)
          Gets a bridge from environment from to environment to.
static IBridge[] getBridges()
          Gives an array of all active bridges.
static XCurrentContext getCurrentContext()
          Gets the current context of current thread or null if no context has been set for the current thread.
static IEnvironment getEnvironment(java.lang.String name, java.lang.Object context)
          retrieves an environment of type name with context context.
static IMapping getMapping(IEnvironment from, IEnvironment to)
          Gets the desired mapping from from to to.
static IMapping getMappingByName(java.lang.String from, java.lang.String to)
          Gets the desired mapping from from to to.
static java.lang.String getUniqueKey()
          returns a world wide unique string.
static java.lang.Object queryInterface(java.lang.Class zInterface, java.lang.Object object)
          queries the given object for the given java class (which must represent a UNO interface).
static java.lang.Object queryInterface(Type type, java.lang.Object object)
          queries the given object for the given type.
static boolean reset()
          Resets the UnoRuntime to its initial state.
static void setCurrentContext(XCurrentContext context)
          Sets the current context of current thread.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEBUG

public static final boolean DEBUG
See Also:
Constant Field Values

__environments

protected static com.sun.star.lib.util.WeakTable __environments

__bridges

protected static com.sun.star.lib.util.WeakTable __bridges
Constructor Detail

UnoRuntime

public UnoRuntime()
Method Detail

getUniqueKey

public static java.lang.String getUniqueKey()
returns a world wide unique string. It is guaranteed, that every invocation of this method generates a new id, which is unique within the VM. The quality of 'world wide unique' will depend on the actual implementation, you should look at the source to determine if it meets your requirements.

Returns:
a unique String

generateOid

public static java.lang.String generateOid(java.lang.Object object)
Generates a worldwide unique object identifier (oid) for the given object. It is guaranteed, that subsequent calls to the method with the same object will give the same id.

Parameters:
object - the object for which a Oid should be generated.
Returns:
the generated oid.

getCurrentContext

public static XCurrentContext getCurrentContext()
Gets the current context of current thread or null if no context has been set for the current thread. The current context is threadlocal, meaning that this method returns the current context, that was last set during this thread.

Returns:
current context of current thread or null if no context was set.

setCurrentContext

public static void setCurrentContext(XCurrentContext context)
Sets the current context of current thread. You have to manually call setCurrentContext( null ) before terminating the current thread. The current context is threadlocal, meaning that upper callstack layers can retrieve the current context, which has been set before. Every function, that sets the current context, should reset the context to the original value when exiting (e.g. within a finally block).

Parameters:
context - context to be set (if null, a previously set context will be removed)

queryInterface

public static java.lang.Object queryInterface(Type type,
                                              java.lang.Object object)
queries the given object for the given type.

It returns null in case the object doesn't support this interface, othewise a reference to the desired interface. If the given object already implements the desired interface, it is passed back immediatly. Otherwise it is checked if the given object implments the delegator interface IQueryInterface and the request is delegated to queryInterface of IQueryInterface.

Parameters:
type - the class of the desired interface.
object - the object to ask for it.
Returns:
the desired interface if available, otherwise null.
See Also:
IQueryInterface

queryInterface

public static java.lang.Object queryInterface(java.lang.Class zInterface,
                                              java.lang.Object object)
queries the given object for the given java class (which must represent a UNO interface).

It returns null in case the object doesn't support this interface, othewise a reference to the desired interface. If the given object already implements the desired interface, it is passed back immediatly. Otherwise it is checked if the given object implments the delegator interface IQueryInterface and the request is delegated to queryInterface of IQueryInterface.

Parameters:
zInterface - the class of the desired interface.
object - the object to ask for it.
Returns:
the desired interface if available, otherwise null.
See Also:
IQueryInterface

areSame

public static boolean areSame(java.lang.Object object1,
                              java.lang.Object object2)
Tests if the given objects are interfaces of the same underlying object.

For UNO objects, it is not suffient to check object identity with a simple ==, because there may be multiple proxies for the same object (in general implementing different interfaces.

Parameters:
object1 - an object representing an interface.
object2 - an object representing an interface.
Returns:
true, if the underlying object is the same, otherwise false.

getEnvironment

public static IEnvironment getEnvironment(java.lang.String name,
                                          java.lang.Object context)
                                   throws java.lang.Exception
retrieves an environment of type name with context context. Environments are hold weak at the UnoRuntime. If the desired environment already exists, this methods gives it back. If the desired environement does not exist, this method looks for it under com.sun.star.lib.uno.environments.<name>.<name>_environment.

Parameters:
name - the name of the environment.
context - the context of the environment.
java.lang.Exception
See Also:
IEnvironment

getBridge

public static IBridge getBridge(IEnvironment from,
                                IEnvironment to,
                                java.lang.Object[] args)
                         throws java.lang.Exception
Gets a bridge from environment from to environment to. Creates a new bridge, if the desired bridge does not exist yet and handles the arguments to the bridge.

If the desired bridge does not exist, is it searched in com.sun.star.lib.uno.bridges.<from>_<to>.< and the root classpath as from>_<to>_bridge.

Parameters:
from - the source environment.
to - the target environment.
args - the initial arguments for the bridge
java.lang.Exception
See Also:
IEnvironment, IBridge, getBridgeByName(java.lang.String, java.lang.Object, java.lang.String, java.lang.Object, java.lang.Object[])

getBridgeByName

public static IBridge getBridgeByName(java.lang.String from,
                                      java.lang.Object from_context,
                                      java.lang.String to,
                                      java.lang.Object to_context,
                                      java.lang.Object[] args)
                               throws java.lang.Exception
Gets a bridge from environment from to environment to. Creates a new bridge, if the desired bridge does not exist yet and handles the arguments to the bridge.

If the desired bridge does not exist, is it searched in com.sun.star.lib.uno.bridges.<from>_<to>.< and the root classpath as from>_<to>_bridge. The needed environments are retrieved through UnoRuntime#getEnvironment.

Parameters:
from - the name of the source environment.
from_context - the context for the source environment
to - the name of the target environment.
to_context - the context for the source environment
args - the initial arguments for the bridge
java.lang.Exception
See Also:
IEnvironment, IBridge, getBridge(com.sun.star.uno.IEnvironment, com.sun.star.uno.IEnvironment, java.lang.Object[]), getEnvironment(java.lang.String, java.lang.Object)

getBridges

public static IBridge[] getBridges()
Gives an array of all active bridges.

See Also:
IBridge

getMapping

public static IMapping getMapping(IEnvironment from,
                                  IEnvironment to)
                           throws java.lang.Exception
Gets the desired mapping from from to to.

Mappings are like bridges, except that with mappings one can only map in one direction. Mappings are here for api compatibility reasons the binary UNO runtime. Mappings are implemented as wrappers around bridges.

Parameters:
from - the source environment.
to - the target environment.
java.lang.Exception
See Also:
com.sun.star.uno.Mapping, getMapping(com.sun.star.uno.IEnvironment, com.sun.star.uno.IEnvironment), getEnvironment(java.lang.String, java.lang.Object), IEnvironment

getMappingByName

public static IMapping getMappingByName(java.lang.String from,
                                        java.lang.String to)
                                 throws java.lang.Exception
Gets the desired mapping from from to to. Retrieves the environments via UnoRuntime#getEnvironment.

Parameters:
from - the name of the source environment.
to - the name of the target environment.
java.lang.Exception
See Also:
com.sun.star.uno.Mapping, getMapping(com.sun.star.uno.IEnvironment, com.sun.star.uno.IEnvironment), getEnvironment(java.lang.String, java.lang.Object)

reset

public static boolean reset()
Resets the UnoRuntime to its initial state. Releases all references to bridges and environments.

See Also:
getBridge(com.sun.star.uno.IEnvironment, com.sun.star.uno.IEnvironment, java.lang.Object[]), getBridgeByName(java.lang.String, java.lang.Object, java.lang.String, java.lang.Object, java.lang.Object[]), getEnvironment(java.lang.String, java.lang.Object), getMapping(com.sun.star.uno.IEnvironment, com.sun.star.uno.IEnvironment), getMappingByName(java.lang.String, java.lang.String)

UNO Java Runtime

Apache Software Foundation

Copyright & License | Privacy | Contact Us | Donate | Thanks

Apache, OpenOffice, OpenOffice.org and the seagull logo are registered trademarks of The Apache Software Foundation. The Apache feather logo is a trademark of The Apache Software Foundation. Other names appearing on the site may be trademarks of their respective owners.