Class UnoRuntime
- java.lang.Object
-
- com.sun.star.uno.UnoRuntime
-
public class UnoRuntime extends Object
The central class needed for implementing or using UNO components in Java.The methods
queryInterface
andareSame
delegate calls to the implementing objects and are used instead of casts,instanceof
,==
, andequals
.For historic reasons, this class is not
final
, and has apublic
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
Fields Modifier and Type Field Description static boolean
DEBUG
Deprecated.As of UDK 3.2.0, do not use this internal field.
-
Constructor Summary
Constructors Constructor Description UnoRuntime()
Deprecated.As of UDK 3.2.0, do not create instances of this class.
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static boolean
areSame(Object any1, Object any2)
Tests two UNOANY
values for equality.static Object
completeValue(Type type, Object value)
Complete a UNO value (make sure it is no invalidnull
value).static String
generateOid(Object object)
Generates a worldwide unique object identifier (OID) for the given Java object.static IBridge
getBridge(IEnvironment from, IEnvironment to, Object[] args)
Deprecated.As of UDK 3.2.0, this method is deprecated, without offering a replacement.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.static IBridge[]
getBridges()
Deprecated.As of UDK 3.2.0, this method is deprecated, without offering a replacement.static XCurrentContext
getCurrentContext()
Gets the current context of the current thread, ornull
if no context has been set for the current thread.static IEnvironment
getEnvironment(String name, Object context)
Deprecated.As of UDK 3.2.0, this method is deprecated, without offering a replacement.static IMapping
getMapping(IEnvironment from, IEnvironment to)
Deprecated.As of UDK 3.2.0, this method is deprecated, without offering a replacement.static IMapping
getMappingByName(String from, String to)
Deprecated.As of UDK 3.2.0, this method is deprecated, without offering a replacement.static String
getUniqueKey()
Generates a worldwide unique identifier string.static Object
queryInterface(Type type, Object object)
Queries the given UNO object for the given UNO interface type.static <T> T
queryInterface(Class<T> zInterface, Object object)
Queries the given UNO object for the given Java class (which must represent a UNO interface type).static boolean
reset()
Deprecated.As of UDK 3.2.0, this method is deprecated, without offering a replacement.static void
setCurrentContext(XCurrentContext context)
Sets the current context for the current thread.
-
-
-
Field Detail
-
DEBUG
@Deprecated public static final boolean DEBUG
Deprecated.As of UDK 3.2.0, do not use this internal field.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
UnoRuntime
@Deprecated public UnoRuntime()
Deprecated.As of UDK 3.2.0, do not create instances of this class. It is considered a historic mistake to have apublic
constructor for this class, which only hasstatic
members. Also, this class might be changed to becomefinal
in a future version.
-
-
Method Detail
-
getUniqueKey
public static String getUniqueKey()
Generates a worldwide 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 “worldwide 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 String generateOid(Object object)
Generates a worldwide 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 an OID shall be generated; must not benull
- Returns:
- the generated OID
- See Also:
IQueryInterface.getOid()
-
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 itselfnull
). 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 aType
object representing a UNO interface typeobject
- a reference to any Java object representing (a facet of) a UNO object; may benull
- Returns:
- a reference to the requested UNO interface type if available,
otherwise
null
- See Also:
IQueryInterface.queryInterface(com.sun.star.uno.Type)
-
queryInterface
public static <T> T queryInterface(Class<T> zInterface, Object object)
Queries the given UNO object for the given Java class (which must represent a UNO interface type).- Type Parameters:
T
- the requested UNO interface type.- Parameters:
zInterface
- a Java class representing a UNO interface typeobject
- a reference to any Java object representing (a facet of) a UNO object; may benull
- Returns:
- a reference to the requested UNO interface type if available,
otherwise
null
- See Also:
queryInterface(Type, Object)
-
areSame
public static boolean areSame(Object any1, Object any2)
Tests two UNOANY
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:
- If t is a primitive type, then both values must denote the same element of the set of values of t.
- If t is a structured type, then both values must recursively contain corresponding values that are equal.
- If t is an interface type, then the two values must be either both null references, or both references to the same UNO object.
- Parameters:
any1
- a Java value representing a UNOANY
value.any2
- a Java value representing a UNOANY
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 invalidnull
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 exceptANY
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, ornull
.- 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
-
getCurrentContext
public static XCurrentContext getCurrentContext()
Gets the current context of the current thread, ornull
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
-
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; ifnull
, any previously set context will be removed
-
getEnvironment
@Deprecated public static IEnvironment getEnvironment(String name, Object context) throws Exception
Deprecated.As of UDK 3.2.0, this method is deprecated, without offering a replacement.Retrieves an environment of typename
with contextcontext
.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 environmentcontext
- the context of the environment- Returns:
- an environment.
- Throws:
Exception
- if something goes awry.Exception
- See Also:
IEnvironment
-
getBridge
@Deprecated public static IBridge getBridge(IEnvironment from, IEnvironment to, Object[] args) throws Exception
Deprecated.As of UDK 3.2.0, this method is deprecated, without offering a replacement.Gets a bridge from environmentfrom
to environmentto
.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 asfrom_to_bridge
.- Parameters:
from
- the source environmentto
- the target environmentargs
- the initial arguments for the bridge- Returns:
- the requested bridge
- Throws:
Exception
- if something goes awry.Exception
- See Also:
getBridgeByName(java.lang.String, java.lang.Object, java.lang.String, java.lang.Object, java.lang.Object[])
,IBridge
,IEnvironment
-
getBridgeByName
@Deprecated public static IBridge getBridgeByName(String from, Object fromContext, String to, Object toContext, Object[] args) throws Exception
Deprecated.As of UDK 3.2.0, this method is deprecated, without offering a replacement.Gets a bridge from environmentfrom
to environmentto
.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 asfrom_to_bridge
. The used environments are retrieved throughgetEnvironment
.- Parameters:
from
- the name of the source environmentfromContext
- the context for the source environmentto
- the name of the target environmenttoContext
- the context for the target environmentargs
- the initial arguments for the bridge- Returns:
- the requested bridge
- Throws:
Exception
- if something goes awry.Exception
- See Also:
getBridge(com.sun.star.uno.IEnvironment, com.sun.star.uno.IEnvironment, java.lang.Object[])
,getEnvironment(java.lang.String, java.lang.Object)
,IBridge
,IEnvironment
-
getBridges
@Deprecated 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:
IBridge
-
getMapping
@Deprecated public static IMapping getMapping(IEnvironment from, IEnvironment to) throws Exception
Deprecated.As of UDK 3.2.0, this method is deprecated, without offering a replacement.Gets a mapping from environmentfrom
to environmentto
.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 environmentto
- the target environment- Returns:
- the requested mapping
- Throws:
Exception
- if something goes awry.Exception
- See Also:
IEnvironment
,IMapping
-
getMappingByName
@Deprecated public static IMapping getMappingByName(String from, String to) throws Exception
Deprecated.As of UDK 3.2.0, this method is deprecated, without offering a replacement.Gets a mapping from environmentfrom
to environmentto
.The used environments are retrieved through
getEnvironment
.- Parameters:
from
- the name of the source environmentto
- the name of the target environment- Returns:
- the requested mapping
- Throws:
Exception
- if something goes awry.Exception
- See Also:
getEnvironment(java.lang.String, java.lang.Object)
,getMapping(com.sun.star.uno.IEnvironment, com.sun.star.uno.IEnvironment)
,IMapping
-
reset
@Deprecated public static boolean reset()
Deprecated.As of UDK 3.2.0, this method is deprecated, without offering a replacement.Resets thisUnoRuntime
to its initial state.Releases all references to bridges and environments.
- Returns:
- true if another thread didn't re-insert some bridge or environment before the method returns. Why that information would be useful is anybody's guess.
-
-