com.sun.star.uno

Class UnoRuntime

public class UnoRuntime extends Object

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

The methods queryInterface and areSame delegate calls to the implementing objects and are used instead of casts, instanceof, ==, and equals.

For historic reasons, this class is not final, and has a public constructor. These artifacts are considered mistakes, which might be corrected in a future version of this class, so client code should not rely on them.

See Also: IBridge IEnvironment IQueryInterface

Field Summary
static booleanDEBUG
Constructor Summary
UnoRuntime()
Method Summary
static booleanareSame(Object any1, Object any2)
Tests two UNO ANY values for equality.
static ObjectcompleteValue(Type type, Object value)
Complete a UNO value (make sure it is no invalid null value).
static StringgenerateOid(Object object)
Generates a world wide unique object identifier (OID) for the given Java object.
static IBridgegetBridge(IEnvironment from, IEnvironment to, Object[] args)
Gets a bridge from environment from to environment to.
static IBridgegetBridgeByName(String from, Object fromContext, String to, Object toContext, Object[] args)
Gets a bridge from environment from to environment to.
static IBridge[]getBridges()
Returns an array of all active bridges.
static XCurrentContextgetCurrentContext()
Gets the current context of the current thread, or null if no context has been set for the current thread.
static IEnvironmentgetEnvironment(String name, Object context)
Retrieves an environment of type name with context context.
static IMappinggetMapping(IEnvironment from, IEnvironment to)
Gets a mapping from environment from to environment to.
static IMappinggetMappingByName(String from, String to)
Gets a mapping from environment from to environment to.
static StringgetUniqueKey()
Generates a world wide unique identifier string.
static ObjectqueryInterface(Type type, Object object)
Queries the given UNO object for the given UNO interface type.
static booleanreset()
Resets this UnoRuntime to its initial state.
static voidsetCurrentContext(XCurrentContext context)
Sets the current context for the current thread.

Field Detail

DEBUG

public static final boolean DEBUG

Deprecated: As of UDK 3.2.0, do not use this internal field.

Constructor Detail

UnoRuntime

public UnoRuntime()

Deprecated: As of UDK 3.2.0, do not create instances of this class. It is considered a historic mistake to have a public constructor for this class, which only has static members. Also, this class might be changed to become final in a future version.

Method Detail

areSame

public static boolean areSame(Object any1, Object any2)
Tests two UNO ANY values for equality.

Two UNO values are equal if and only if they are of the same UNO type t, and they meet the following condition, depending on t:

Parameters: any1 a Java value representing a UNO ANY value. any2 a Java value representing a UNO ANY value.

Returns: true if and only if the two arguments represent equal UNO values.

completeValue

public static final Object completeValue(Type type, Object value)
Complete a UNO value (make sure it is no invalid null value).

This is useful for members of parameterized type of instantiated polymorphic struct types, as null is a valid value there (and only there, for all types except ANY and interface types).

Parameters: type a non-void, non-exception UNO type. value a Java value representing a UNO value of the given UNO type, or null.

Returns: the given value, or the neutral value of the given type, if the given value was an invalid null value.

Since: UDK 3.2.3

generateOid

public static String generateOid(Object object)
Generates a world wide unique object identifier (OID) for the given Java object.

It is guaranteed that subsequent calls to this method with the same Java object will give the same ID.

This method is generally of little use for client code. It should be considered a mistake that this method is published at all.

Parameters: object any object for which a OID shall be generated; must not be null

Returns: the generated OID

See Also: IQueryInterface

getBridge

public static IBridge getBridge(IEnvironment from, IEnvironment to, Object[] args)

Deprecated: As of UDK 3.2.0, this method is deprecated, without offering a replacement.

Gets a bridge from environment from to environment to.

Creates a new bridge, if the requested bridge does not yet exist, and hands the arguments to the bridge.

If the requested bridge does not exist, it is searched for in package 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

Returns: the requested bridge

See Also: UnoRuntime IBridge

getBridgeByName

public static IBridge getBridgeByName(String from, Object fromContext, String to, Object toContext, Object[] args)

Deprecated: As of UDK 3.2.0, this method is deprecated, without offering a replacement.

Gets a bridge from environment from to environment to.

Creates a new bridge, if the requested bridge does not yet exist, and hands the arguments to the bridge.

If the requested bridge does not exist, it is searched for in package com.sun.star.lib.uno.bridges.from_to; and the root classpath as from_to_bridge. The used environments are retrieved through getEnvironment.

Parameters: from the name of the source environment fromContext the context for the source environment to the name of the target environment toContext the context for the target environment args the initial arguments for the bridge

Returns: the requested bridge

See Also: UnoRuntime UnoRuntime IBridge

getBridges

public static IBridge[] getBridges()

Deprecated: As of UDK 3.2.0, this method is deprecated, without offering a replacement.

Returns an array of all active bridges.

Returns: an array of IBridge objects

See Also:

getCurrentContext

public static XCurrentContext getCurrentContext()
Gets the current context of the current thread, or null if no context has been set for the current thread.

The current context is thread local, which means that this method returns the context that was last set for this thread.

Returns: the current context of the current thread, or null if no context has been set for the current thread

getEnvironment

public static IEnvironment getEnvironment(String name, Object context)

Deprecated: As of UDK 3.2.0, this method is deprecated, without offering a replacement.

Retrieves an environment of type name with context context.

Environments are held weakly by this class. If the requested environment already exists, this methods simply returns it. Otherwise, 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

See Also:

getMapping

public static IMapping getMapping(IEnvironment from, IEnvironment to)

Deprecated: As of UDK 3.2.0, this method is deprecated, without offering a replacement.

Gets a mapping from environment from to environment to.

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

Parameters: from the source environment to the target environment

Returns: the requested mapping

See Also: IEnvironment

getMappingByName

public static IMapping getMappingByName(String from, String to)

Deprecated: As of UDK 3.2.0, this method is deprecated, without offering a replacement.

Gets a mapping from environment from to environment to.

The used environments are retrieved through getEnvironment.

Parameters: from the name of the source environment to the name of the target environment

Returns: the requested mapping

See Also: UnoRuntime UnoRuntime

getUniqueKey

public static String getUniqueKey()
Generates a world wide unique identifier 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

queryInterface

public static Object queryInterface(Type type, Object object)
Queries the given UNO object for the given UNO interface type.

This method returns null in case the given UNO object does not support the given UNO interface type (or is itself null). Otherwise, a reference to a Java object implementing the Java interface type corresponding to the given UNO interface is returned. In the latter case, it is unspecified whether the returned Java object is the same as the given object, or is another facet of that UNO object.

Parameters: type the requested UNO interface type; must be a Type object representing a UNO interface type object a reference to any Java object representing (a facet of) a UNO object; may be null

Returns: a reference to the requested UNO interface type if available, otherwise null

See Also: IQueryInterface

reset

public static boolean reset()

Deprecated: As of UDK 3.2.0, this method is deprecated, without offering a replacement.

Resets this UnoRuntime to its initial state.

Releases all references to bridges and environments.

setCurrentContext

public static void setCurrentContext(XCurrentContext context)
Sets the current context for the current thread.

The current context is thread local. To support a stacking behaviour, every function that sets the current context should reset it to the original value when exiting (for example, within a finally block).

Parameters: context the context to be set; if null, any previously set context will be removed