diff options
Diffstat (limited to 'ridljar/com/sun/star/uno')
-rw-r--r-- | ridljar/com/sun/star/uno/Any.java | 140 | ||||
-rw-r--r-- | ridljar/com/sun/star/uno/Enum.java | 61 | ||||
-rw-r--r-- | ridljar/com/sun/star/uno/IBridge.java | 99 | ||||
-rw-r--r-- | ridljar/com/sun/star/uno/IEnvironment.java | 152 | ||||
-rw-r--r-- | ridljar/com/sun/star/uno/IFieldDescription.java | 55 | ||||
-rw-r--r-- | ridljar/com/sun/star/uno/IMapping.java | 49 | ||||
-rw-r--r-- | ridljar/com/sun/star/uno/IMemberDescription.java | 75 | ||||
-rw-r--r-- | ridljar/com/sun/star/uno/IMethodDescription.java | 88 | ||||
-rw-r--r-- | ridljar/com/sun/star/uno/IQueryInterface.java | 69 | ||||
-rw-r--r-- | ridljar/com/sun/star/uno/ITypeDescription.java | 188 | ||||
-rw-r--r-- | ridljar/com/sun/star/uno/Type.java | 652 | ||||
-rw-r--r-- | ridljar/com/sun/star/uno/Union.java | 52 | ||||
-rw-r--r-- | ridljar/com/sun/star/uno/UnoRuntime.java | 696 |
13 files changed, 2376 insertions, 0 deletions
diff --git a/ridljar/com/sun/star/uno/Any.java b/ridljar/com/sun/star/uno/Any.java new file mode 100644 index 000000000000..d83d6a5951ea --- /dev/null +++ b/ridljar/com/sun/star/uno/Any.java @@ -0,0 +1,140 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + + +package com.sun.star.uno; + + +/** + * The UNO IDL type any is mapped to java type <code>java.lang.Object</code>. + * <p> + * In special cases it is necessary to have an explicit any to additionally transport + * an exact type. For instance if you want to pass an object reference via + * an interprocess connection using an any, you should use this class to add + * an explicit interface type, so the remote counterpart doesn't need to invoke + * a queryInterface). + * <p> + * @version $Revision: 1.11 $ $ $Date: 2008-04-11 11:11:43 $ + */ +public class Any { + /** + * The type of the any. + * <p> + * @see #getType + */ + protected Type _type; + + /** + * The data of the any. + * <p> + * @see #getObject + */ + protected Object _object; + + public static final Any VOID = new Any(new Type("void", TypeClass.VOID), + null); + // do not use Type.VOID here to avoid circular dependencies between + // static members of Any and Type + + /** + * Constructs a new any. + * <p> + * @param zInterface the type of the any. + * @param object the data of the any. + * @deprecated as of UDK 2.0 + */ + public Any(Class zInterface, Object object) { + this(new Type(zInterface), object); + } + + /** Constructs a new any with a given type and value + @param type the UNO type of the any. + @param object the value of the any. + */ + public Any(Type type, Object object) { + if (type.equals(Type.ANY)) { + throw new IllegalArgumentException("Any cannot contain Any"); + } + _type = type; + _object = object; + } + + /** + Complete a UNO <code>ANY</code> (make sure it is wrapped up as an + <code>Any</code> instance). + + @param any a Java value representing a UNO <code>ANY</code> value. + + @return a complete Java value (that is, an <code>Any</code> instance) + representing the same UNO <code>ANY</code> value as the given argument. + + @since UDK 3.2.3 + */ + public static final Any complete(Object any) { + return any instanceof Any + ? (Any) any + : new Any( + new Type(any == null ? XInterface.class : any.getClass()), any); + } + + /** + * Gets the type of the value within the any. + * <p> + * @return the type of the value within the any. + */ + public Type getType() { + return _type; + } + + /** + * Gets the value within the any. + * <p> + * @return gets the value within the any. + */ + public Object getObject() { + return _object; + } + + // @see java.lang.Object#equals + public boolean equals(Object obj) { + return obj instanceof Any && _type.equals(((Any) obj)._type) + && (_object == null + ? ((Any) obj)._object == null + : _object.equals(((Any) obj)._object)); + } + + // @see java.lang.Object#hashCode + public int hashCode() { + return _type.hashCode() * 13 + + (_object == null ? 0 : _object.hashCode()); + } + + // @see java.lang.Object#toString + public String toString() { + return "Any[" + _type + ", " + _object + "]"; + } +} diff --git a/ridljar/com/sun/star/uno/Enum.java b/ridljar/com/sun/star/uno/Enum.java new file mode 100644 index 000000000000..eb509096c503 --- /dev/null +++ b/ridljar/com/sun/star/uno/Enum.java @@ -0,0 +1,61 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +package com.sun.star.uno; + +/** + * The Enum class is the base class for all classes generated + * as java binding for the IDL type enum. + * Each java mapped enum class provides static member of this class + * which represents the enum values. + * You cannot create a object of this class or subclass direct, to + * avoid enum values with integer values outside the defined range. + * <p> + * @version $Revision: 1.5 $ $ $Date: 2008-04-11 11:11:59 $ + */ +public abstract class Enum { + private int m_value; + + /** + * Constructs a enum value. + * <p> + * @param value the integer value of this enum value. + */ + protected Enum(int value) { + m_value = value; + } + + /** + * Get the integer value of an enum value. + * <p> + * @return the integer value. + */ + public final int getValue() { + return m_value; + } +} + diff --git a/ridljar/com/sun/star/uno/IBridge.java b/ridljar/com/sun/star/uno/IBridge.java new file mode 100644 index 000000000000..f1150b661e1d --- /dev/null +++ b/ridljar/com/sun/star/uno/IBridge.java @@ -0,0 +1,99 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +package com.sun.star.uno; + +import java.io.IOException; + +/** + * This is abstract interface for bridges. + * + * <p>Bridges are able to map one object from one UNO environment to another and + * vice versa.<p> + * + * @see com.sun.star.uno.IBridge + * @see com.sun.star.uno.IQueryInterface + * @see com.sun.star.uno.UnoRuntime + * + * @deprecated As of UDK 3.2, this interface is deprecated, without offering a + * replacement. + */ +public interface IBridge { + /** + * Maps an object from the source environment to the destination + * environment. + * + * @param object the object to map + * @param type the type of the interface that shall be mapped + * @return the object in the destination environment + */ + Object mapInterfaceTo(Object object, Type type); + + /** + * Maps an object from the destination environment to the source + * environment. + * + * @param object the object to map + * @param type the type of the interface that shall be mapped + * @return the object in the source environment + */ + Object mapInterfaceFrom(Object object, Type type); + + /** + * Returns the source environment. + * + * @return the source environment of this bridge + */ + IEnvironment getSourceEnvironment(); + + /** + * Returns the destination environment. + * + * @return the destination environment of this bridge + */ + IEnvironment getTargetEnvironment(); + + /** + * Increases the life count. + */ + void acquire(); + + /** + * Decreases the life count. + * + * <p>If the life count drops to zero, the bridge disposes itself.</p> + */ + void release(); + + /** + * Disposes the bridge. + * + * <p>Sends involved threads an <code>InterruptedException</code>. Releases + * mapped objects.</p> + */ + void dispose() throws InterruptedException, IOException; +} diff --git a/ridljar/com/sun/star/uno/IEnvironment.java b/ridljar/com/sun/star/uno/IEnvironment.java new file mode 100644 index 000000000000..028aff0916d8 --- /dev/null +++ b/ridljar/com/sun/star/uno/IEnvironment.java @@ -0,0 +1,152 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +package com.sun.star.uno; + +/** + * The interface implemented by UNO environments. + * + * <p>With this interface, objects can be registered at and revoked from an + * environment.</p> + * + * @see com.sun.star.uno.IBridge + * @see com.sun.star.uno.IQueryInterface + * @see com.sun.star.uno.UnoRuntime + * + * @deprecated As of UDK 3.2, this interface is deprecated, without offering a + * replacement. + */ +public interface IEnvironment { + /** + * Gets the context of this environment. + * + * @return the context of this environment + */ + Object getContext(); + + /** + * Gets the name of this environment. + * + * @return the name of this environment + */ + String getName(); + + /** + * Registers one UNO interface facet of an object. + * + * <p>Such an object will typically be one of three things: + * <ul> + * <li>A local Java object, to be mapped out of this environment via a given + * bridge.</li> + * <li>A proxy object, mapped into this environment via some bridge + * <var>B1</var>, and now to be mapped out of this environment via a + * given bridge <var>B2</var>.</li> + * <li>A proxy object, created as a remote object is mapped into this + * environment via a given bridge.</li> + * </ul></p> + * + * <p>The object actually registered may differ from the specified + * <code>object</code> that is passed as an argument. This enables an + * environment to work in a multi-threaded scenario, where two threads can + * call <code>registerInterface</code> for the same combination of + * <code>oid</code> and <code>type</code> at the same time; the race + * condition is solved by letting one of the calls register its argument + * <code>object</code>, ignoring the argument <code>object</code> of the + * other call, and letting both calls return the same + * <code>object</code>.</p> + * + * <p>The registered object is held only weakly by the environment. After a + * call to <code>registerInterface</code>, a call to + * <code>getRegisteredInterface</code> only succeeds as long as the + * registered object is still strongly reachable, and the registered object + * has not been explicitly revoked by calling + * <code>revokeInterface</code>.</p> + * + * @param object the object to register; must be non-null + * @param oid in-out parameter containing the OID of <code>object</code>. + * This must be a non-null reference to an array of length at least one; + * the zeroth element is used to pass the argument in and out. If the + * zeroth element is null on input, the OID will be computed and passed + * out (that is, the zeroth element will never be null upon normal + * return). + * @param type the UNO interface type to register. This argument must be + * non-null, and must denote a UNO interface type. The given + * <code>object</code> should implement this <code>type</code>. + * @return the registered object (may differ from the <code>object</code> + * passed in); will never be null + */ + Object registerInterface(Object object, String[] oid, Type type); + + /** + * Explicitly revokes a UNO interface facet. + * + * <p>Calls to <code>registerInterface</code> and + * <code>revokeInterface</code> must be paired. A facet is only removed + * from the environment when it has been revoked as often as it has been + * registered. This may change in the future, so that a facet would be + * removed upon the first call to <code>revokeInterface</code> (and calls to + * <code>revokeInterface</code> would no longer be necessary if the calling + * code does not want to control the temporal extent of the + * registration).</p> + * + * <p>It is not an error if the specified facet is not registered at this + * environment (either because no corresponding object has ever been + * registered, or it has been explicitly revoked, or it is no longer + * strongly reachable). In such a case, this method simply does + * nothing.</p> + * + * @param oid the OID of the object to revoke; must be non-null + * @param type the UNO interface type of the object to revoke. This + * argument must be non-null, and must denote a UNO interface type. + */ + void revokeInterface(String oid, Type type); + + /** + * Retrieves a registered object, specified by OID and UNO interface type. + * + * @param oid the OID of the object to retrieve; must be non-null + * @param type the UNO interface type of the object to retrieve. This + * argument must be non-null, and must denote a UNO interface type. + * @return the registered object, or null if none is found + */ + Object getRegisteredInterface(String oid, Type type); + + /** + * Retrieves the OID for a registered object. + * + * @param object a registered object; must be non-null + * @return the OID of the <code>object</code>; will never be null + */ + String getRegisteredObjectIdentifier(Object object); + + /** + * Lists the registered objects to <code>System.out</code>. + * + * <p>This is for debug purposes.</p> + */ + void list(); +} diff --git a/ridljar/com/sun/star/uno/IFieldDescription.java b/ridljar/com/sun/star/uno/IFieldDescription.java new file mode 100644 index 000000000000..f68baca7f817 --- /dev/null +++ b/ridljar/com/sun/star/uno/IFieldDescription.java @@ -0,0 +1,55 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +package com.sun.star.uno; + + +import java.lang.reflect.Field; + +/** + * The <code>IFieldDescription</code> describes non + * method members. + * + * @deprecated This interface does not cover all the features supported by the + * corresponding (unpublished) implementation. But no client code should need + * to access this functionality, anyway. + */ +public interface IFieldDescription extends IMemberDescription { + /** + * Gives the name of this member. + * <p> + * @return the name + */ + ITypeDescription getTypeDescription(); + + /** + * Gives native java field of this member. + * <p> + * @return the java field + */ + Field getField(); +} diff --git a/ridljar/com/sun/star/uno/IMapping.java b/ridljar/com/sun/star/uno/IMapping.java new file mode 100644 index 000000000000..5bb39ac890f3 --- /dev/null +++ b/ridljar/com/sun/star/uno/IMapping.java @@ -0,0 +1,49 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +package com.sun.star.uno; + +/** + * With a mapping objets can be mapped from one environment to another. + * + * <p>This interface exists for compatibility with the binary UNO API.</p> + * + * @see com.sun.star.uno.IBridge + * + * @deprecated As of UDK 3.2, this interface is deprecated, without offering a + * replacement. + */ +public interface IMapping { + /** + * Maps an interface from one environment to another. + * + * @param object source object that is to be mapped + * @param type description of the interface that is to be mapped + * @return the object mapped to the destination environment + */ + Object mapInterface(Object object, Type type); +} diff --git a/ridljar/com/sun/star/uno/IMemberDescription.java b/ridljar/com/sun/star/uno/IMemberDescription.java new file mode 100644 index 000000000000..c65441f9cb96 --- /dev/null +++ b/ridljar/com/sun/star/uno/IMemberDescription.java @@ -0,0 +1,75 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +package com.sun.star.uno; + +/** + * The <code>IMemberDescription</code> is the base interface + * for for the special subset of typedescriptions, which describe + * members of IDL structs or interfeces. + * + * @deprecated This interface does not cover all the features supported by the + * corresponding (unpublished) implementation. But no client code should need + * to access this functionality, anyway. + */ +public interface IMemberDescription { + /** + * Gives the name of this member. + * <p> + * @return the name + */ + String getName(); + + /** + * Indicates if this member is unsigned. (Not useful for IMethodDescription). + * <p> + * @return the unsigned state + */ + boolean isUnsigned(); + + /** + * Indicates if this member is an any. + * <p> + * @return the any state + */ + boolean isAny(); + + /** + * Indicates if this member is an interface. + * <p> + * @return the interface state + */ + boolean isInterface(); + + /** + * Gives the relative index of this member in the declaring + * interface or struct (including superclasses). + * <p> + * @return the relative index of this member + */ + int getIndex(); +} diff --git a/ridljar/com/sun/star/uno/IMethodDescription.java b/ridljar/com/sun/star/uno/IMethodDescription.java new file mode 100644 index 000000000000..3e1664042bb9 --- /dev/null +++ b/ridljar/com/sun/star/uno/IMethodDescription.java @@ -0,0 +1,88 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +package com.sun.star.uno; + + +import java.lang.reflect.Method; + + +/** + * The <code>IMethodDescription</code> allows to examine a method + * in detail. It gives a view to java methods from a UNO point. + * + * @deprecated This interface does not cover all the features supported by the + * corresponding (unpublished) implementation. But no client code should need + * to access this functionality, anyway. + */ +public interface IMethodDescription extends IMemberDescription { + /** + * Indicates if this method is <code>oneWay</code>, + * respectivly if this method may become executed asynchronously. + * <p> + * @return true means may execute asynchronously . + */ + boolean isOneway(); + + /** + * Indicates if this method is const. + * <p> + * @return true means it is const. + */ + boolean isConst(); + + /** + * Gives any array of <code>ITypeDescription> of + * the [in] parameters. + * <p> + * @return the in parameters + */ + ITypeDescription[] getInSignature(); + + /** + * Gives any array of <code>ITypeDescription> of + * the [out] parameters. + * <p> + * @return the out parameters + */ + ITypeDescription[] getOutSignature(); + + /** + * Gives the <code>ITypeDescription</code> of + * the return type. + * <p> + * @return the return type <code>ITypeDescription</code> + */ + ITypeDescription getReturnSignature(); + + /** + * Gives native java method of this method. + * <p> + * @return the java methodd + */ + Method getMethod(); +} diff --git a/ridljar/com/sun/star/uno/IQueryInterface.java b/ridljar/com/sun/star/uno/IQueryInterface.java new file mode 100644 index 000000000000..cb9a79c8b9d4 --- /dev/null +++ b/ridljar/com/sun/star/uno/IQueryInterface.java @@ -0,0 +1,69 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +package com.sun.star.uno; + +/** + * This is the delegator interface for Java objects implementing interfaces of + * an underlying UNO object. + * + * <p>Calls are delegated through the <code>UnoRuntime</code> to this + * interface. Implement this interface in case you want to customize the + * behaviour of <code>UnoRuntime.queryInterface</code>.</p> + * + * @see com.sun.star.uno.UnoRuntime + */ +public interface IQueryInterface { + /** + * Returns the unique object identifier (OID) of the underlying UNO object. + * + * @return the OID of the underlying object + */ + String getOid(); + + /** + * Returns an object implementing the requested interface type. + * + * @param type the requested UNO interface type; must be a <code>Type</code> + * object representing a UNO interface type + * @return a reference to the requested UNO interface type if available, + * otherwise <code>null</code> + * @see com.sun.star.uno.UnoRuntime + */ + Object queryInterface(Type type); + + /** + * Tests if the given reference represents a facet of the underlying UNO + * object. + * + * @param object a reference to any Java object representing (a facet of) a + * UNO object; may be <code>null</code> + * @return <code>true</code> if and only if <code>object</code> is not + * <code>null</code> and represents the same UNO object as this object + */ + boolean isSame(Object object); +} diff --git a/ridljar/com/sun/star/uno/ITypeDescription.java b/ridljar/com/sun/star/uno/ITypeDescription.java new file mode 100644 index 000000000000..51a32c6f5484 --- /dev/null +++ b/ridljar/com/sun/star/uno/ITypeDescription.java @@ -0,0 +1,188 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +package com.sun.star.uno; + +/** + * The <code>ITypeDescription</code> allows to examine a type + * in detail (e.g. it is used for marshaling/unmarshaling). + * + * @deprecated This interface does not cover all the features supported by the + * corresponding (unpublished) implementation. But no client code should need + * to access this functionality, anyway. + */ +public interface ITypeDescription { + /** + * Gets the <code>ITypeDescription</code> of the + * super, if it exists. + * <p> + * @return the <code>ITypeDescription</code>. + */ + ITypeDescription getSuperType(); + + /** + * Gets the <code>IMethodDescription</code> for every + * method, if this type is an interface. Otherwise + * returns <code>null</code>. + * <p> + * @return the <code>IMethodDescription[]</code>. + */ + IMethodDescription []getMethodDescriptions(); + + /** + * Gets the <code>IMethodDescription</code> for the + * method with index methodId, if it exists, otherwise + * returns <code>null</code>. + * <p> + * @return the <code>IMethodDescription</code>. + */ + IMethodDescription getMethodDescription(int methodId); + + /** + * Gets the <code>IMethodDescription</code> for the + * method with the name <code>name</code>, if it exists, + * otherwise returns <code>null</code>. + * <p> + * @return the <code>IMethodDescription</code>. + */ + IMethodDescription getMethodDescription(String name); + + /** + * Gets the <code>IFieldDescription</code> for every + * field, if this type is an interface. Otherwise + * returns <code>null</code>. + * <p> + * @return the <code>IFieldDescription[]</code>. + */ + IFieldDescription []getFieldDescriptions(); + + /** + * Gets the <code>IFieldDescription</code> for the + * field with the name <code>name</code>, if it exists, + * otherwise returns <code>null</code>. + * <p> + * @return the <code>IFieldDescription</code>. + */ + IFieldDescription getFieldDescription(String name); + + /** + * Gets the IDL <code>TypeClass</code> of the type. + * <p> + * @return the <code>TypeClass</code>. + */ + TypeClass getTypeClass(); + + /** + * Gets the component <code>ITypeDescription</code> if + * this is an array type, otherwise returns <code>null</code>. + * <p> + * @return the <code>ITypeDescription</code> + */ + ITypeDescription getComponentType(); + + /** + * Gets the (UNO) type name. + * + * <p>The following table lists how UNO types map to type names:</p> + * <table> + * <thead> + * <tr><th>UNO type</th><th>type name</th></tr> + * </thead> + * <tbody> + * <tr><td>VOID</td><td><code>"void"</code></td></tr> + * <tr><td>BOOLEAN</td><td><code>"boolean"</code></td></tr> + * <tr><td>CHAR</td><td><code>"char"</code></td></tr> + * <tr><td>BYTE</td><td><code>"byte"</code></td></tr> + * <tr><td>SHORT</td><td><code>"short"</code></td></tr> + * <tr> + * <td>UNSIGNED SHORT</td><td><code>"unsigned short"</code></td> + * </tr> + * <tr><td>LONG</td><td><code>"long"</code></td></tr> + * <tr><td>UNSIGNED LONG</td><td><code>"unsigned long"</code></td></tr> + * <tr><td>HYPER</td><td></td><code>"hyper"</code></tr> + * <tr> + * <td>UNSIGNED HYPER</td><td></td><code>"unsigned hyper"</code> + * </tr> + * <tr><td>FLOAT</td><td></td><code>"float"</code></tr> + * <tr><td>DOUBLE</td><td></td><code>"double"</code></tr> + * <tr><td>STRING</td><td></td><code>"string"</code></tr> + * <tr><td>TYPE</td><td></td><code>"type"</code></tr> + * <tr><td>ANY</td><td></td><code>"any"</code></tr> + * <tr> + * <td>sequence type of base type <var>T</var></td> + * <td><code>"[]"</code> followed by type name for <var>T</var></td> + * </tr> + * <tr> + * <td>enum type named <var>N</var></td> + * <td><var>N</var> (see below)</td> + * </tr> + * <tr> + * <td>struct type named <var>N</var></td> + * <td><var>N</var> (see below)</td> + * </tr> + * <tr> + * <td>exception type named <var>N</var> + * </td><td><var>N</var> (see below)</td> + * </tr> + * <tr> + * <td>interface type named <var>N</var></td> + * <td><var>N</var> (see below)</td> + * </tr> + * <tbody> + * </table> + * <p>For a UNO type named <var>N</var>, consisting of a sequence of module + * names <var>M<sub>1</sub></var>, ..., <var>M<sub>n</sub></var> followed by + * a simple name <var>S</var>, the corresponding type name consists of the + * same sequence of module names and simple name, with <code>"."</code> + * seperating the individual elements.</p> + * + * @return the type name. + */ + String getTypeName(); + + /** + * Gets the (Java) array type name. + * + * <p>The array type name is defined to be the Java class name (as returned + * by <code>Class.forName</code>) of the Java array class that corresponds + * to the UNO sequence type with this type (the UNO type represented by this + * <code>ITypeDescription</code> instance) as base type. For an + * <code>ITypeDescription</code> instance representing the UNO type VOID, + * the array type name is defined to be + * <code>"[Ljava.lang.Void;"</code>.</p> + * + * @return the array type name. + */ + String getArrayTypeName(); + + /** + * Gets the corresponding java class for the type. + * <p> + * @return the corresponding java class. + */ + Class getZClass(); +} diff --git a/ridljar/com/sun/star/uno/Type.java b/ridljar/com/sun/star/uno/Type.java new file mode 100644 index 000000000000..b87674ccdf63 --- /dev/null +++ b/ridljar/com/sun/star/uno/Type.java @@ -0,0 +1,652 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +package com.sun.star.uno; + +import java.util.HashMap; + +/** + * Represents the UNO built-in type <code>TYPE</code>. + * + * <p>The UNO type is not directly mapped to <code>java.lang.Class</code> for at + * least two reasons. For one, some UNO types (like <code>UNSIGNED + * SHORT</code>) do not have a matching Java class. For another, it can be + * necessary to describe a type which is unknown to the Java runtime system + * (for example, for delaying the need of a class, so that it is possible to + * generate it on the fly.)</p> + * + * <p>A <code>Type</code> is uniquely determined by its type class (a + * <code>TypeClass</code>) and its type name (a <code>String</code>); these two + * will never be <code>null</code>. A <code>Type</code> may have an additional + * "z class" (a <code>java.lang.Class</code>), giving a Java class type that + * corresponds to the UNO type. Also, a <code>Type</code> can cache a type + * description (a <code>com.sun.star.uno.ITypeDescription</code>), which can be + * computed and set by <code>TypeDescription.getTypeDescription</code>. + */ +public class Type { + // The following private static members and static initializer must come + // first in the class definition, so that the class can be initialized + // sucessfully: + + private static final String TYPE_NAME_VOID = "void"; + private static final String TYPE_NAME_BOOLEAN = "boolean"; + private static final String TYPE_NAME_BYTE = "byte"; + private static final String TYPE_NAME_SHORT = "short"; + private static final String TYPE_NAME_UNSIGNED_SHORT = "unsigned short"; + private static final String TYPE_NAME_LONG = "long"; + private static final String TYPE_NAME_UNSIGNED_LONG = "unsigned long"; + private static final String TYPE_NAME_HYPER = "hyper"; + private static final String TYPE_NAME_UNSIGNED_HYPER = "unsigned hyper"; + private static final String TYPE_NAME_FLOAT = "float"; + private static final String TYPE_NAME_DOUBLE = "double"; + private static final String TYPE_NAME_CHAR = "char"; + private static final String TYPE_NAME_STRING = "string"; + private static final String TYPE_NAME_TYPE = "type"; + private static final String TYPE_NAME_ANY = "any"; + + // must be sorted same as TypeClass: + private static final String[] __typeClassToTypeName = new String[] { + TYPE_NAME_VOID, + TYPE_NAME_CHAR, + TYPE_NAME_BOOLEAN, + TYPE_NAME_BYTE, + TYPE_NAME_SHORT, + TYPE_NAME_UNSIGNED_SHORT, + TYPE_NAME_LONG, + TYPE_NAME_UNSIGNED_LONG, + TYPE_NAME_HYPER, + TYPE_NAME_UNSIGNED_HYPER, + TYPE_NAME_FLOAT, + TYPE_NAME_DOUBLE, + TYPE_NAME_STRING, + TYPE_NAME_TYPE, + TYPE_NAME_ANY + }; + + private static final HashMap __javaClassToTypeClass = new HashMap(); + static { + __javaClassToTypeClass.put( + void.class, new TypeClass[] { TypeClass.VOID, TypeClass.VOID }); + __javaClassToTypeClass.put( + Void.class, new TypeClass[] { TypeClass.VOID, TypeClass.VOID }); + __javaClassToTypeClass.put( + boolean.class, + new TypeClass[] { TypeClass.BOOLEAN, TypeClass.BOOLEAN }); + __javaClassToTypeClass.put( + Boolean.class, + new TypeClass[] { TypeClass.BOOLEAN, TypeClass.BOOLEAN }); + __javaClassToTypeClass.put( + byte.class, new TypeClass[] { TypeClass.BYTE, TypeClass.BYTE }); + __javaClassToTypeClass.put( + Byte.class, new TypeClass[] { TypeClass.BYTE, TypeClass.BYTE }); + __javaClassToTypeClass.put( + short.class, + new TypeClass[] { TypeClass.SHORT, TypeClass.UNSIGNED_SHORT }); + __javaClassToTypeClass.put( + Short.class, + new TypeClass[] { TypeClass.SHORT, TypeClass.UNSIGNED_SHORT }); + __javaClassToTypeClass.put( + int.class, + new TypeClass[] { TypeClass.LONG, TypeClass.UNSIGNED_LONG }); + __javaClassToTypeClass.put( + Integer.class, + new TypeClass[] { TypeClass.LONG, TypeClass.UNSIGNED_LONG }); + __javaClassToTypeClass.put( + long.class, + new TypeClass[] { TypeClass.HYPER, TypeClass.UNSIGNED_HYPER }); + __javaClassToTypeClass.put( + Long.class, + new TypeClass[] { TypeClass.HYPER, TypeClass.UNSIGNED_HYPER }); + __javaClassToTypeClass.put( + float.class, new TypeClass[] { TypeClass.FLOAT, TypeClass.FLOAT }); + __javaClassToTypeClass.put( + Float.class, new TypeClass[] { TypeClass.FLOAT, TypeClass.FLOAT }); + __javaClassToTypeClass.put( + double.class, + new TypeClass[] { TypeClass.DOUBLE, TypeClass.DOUBLE }); + __javaClassToTypeClass.put( + Double.class, + new TypeClass[] { TypeClass.DOUBLE, TypeClass.DOUBLE }); + __javaClassToTypeClass.put( + char.class, new TypeClass[] { TypeClass.CHAR, TypeClass.CHAR }); + __javaClassToTypeClass.put( + Character.class, + new TypeClass[] { TypeClass.CHAR, TypeClass.CHAR }); + __javaClassToTypeClass.put( + String.class, + new TypeClass[] { TypeClass.STRING, TypeClass.STRING }); + __javaClassToTypeClass.put( + Type.class, new TypeClass[] { TypeClass.TYPE, TypeClass.TYPE }); + __javaClassToTypeClass.put( + Any.class, new TypeClass[] { TypeClass.ANY, TypeClass.ANY }); + __javaClassToTypeClass.put( + Object.class, + new TypeClass[] { TypeClass.ANY, TypeClass.INTERFACE }); + } + + public static final Type VOID = new Type(void.class); + public static final Type CHAR = new Type(char.class); + public static final Type BOOLEAN = new Type(boolean.class); + public static final Type BYTE = new Type(byte.class); + public static final Type SHORT = new Type(short.class); + public static final Type UNSIGNED_SHORT = new Type( + TYPE_NAME_UNSIGNED_SHORT, TypeClass.UNSIGNED_SHORT); + public static final Type LONG = new Type(int.class); + public static final Type UNSIGNED_LONG = new Type( + TYPE_NAME_UNSIGNED_LONG, TypeClass.UNSIGNED_LONG); + public static final Type HYPER = new Type(long.class); + public static final Type UNSIGNED_HYPER = new Type( + TYPE_NAME_UNSIGNED_HYPER, TypeClass.UNSIGNED_HYPER); + public static final Type FLOAT = new Type(float.class); + public static final Type DOUBLE = new Type(double.class); + public static final Type STRING = new Type(String.class); + public static final Type TYPE = new Type(Type.class); + public static final Type ANY = new Type(Any.class); + + /** + * Constructs a new <code>Type</code> which defaults to <code>VOID</code>. + */ + public Type() { + init(null, void.class, false, false); + } + + /** + * Constructs a new <code>Type</code> with the given type class and type + * name. + * + * @param typeName the type name. Must not be <code>null</code>. + * @param typeClass the type class. Must not be <code>null</code>, and must + * match the <code>typeName</code> (for example, it is illegal to + * combine a <code>typeName</code> of <code>"void"</code> with a + * <code>typeClass</code> of <code>BOOLEAN</code>). + */ + public Type(String typeName, TypeClass typeClass) { + _typeClass = typeClass; + _typeName = typeName; + } + + /** + * Constructs a new <code>Type</code> from the given + * <code>java.lang.Class</code>. + * + * <p>This is equivalent to <code>Type(zClass, false)</code>.</p> + * + * @param zClass the Java class of this type. Must not be + * <code>null</code>. + */ + public Type(Class zClass) { + init(null, zClass, false, false); + } + + /** + * Constructs a new <code>Type</code> from the given + * <code>java.lang.Class</code>, handling ambiguous cases. + * + * <p>In certain cases, one Java class corresponds to two UNO types (e.g., + * the Java class <code>short[].class</code> corresponds to both a sequence + * of <codde>SHORT</code> and a sequence of <code>UNSIGNED SHORT</code> in + * UNO). In such ambiguous cases, the parameter <code>alternative</code> + * controls which UNO type is chosen:</p> + * <ul> + * <li>If the Java type is (an array type with element type) + * <code>short</code> or <code>java.lang.Short</code>: If + * <code>alternative</code> is <code>false</code>, the chosen UNO type is + * (a sequence type with element type) <code>SHORT</code>. If + * <code>alternative</code> is <code>true</code>, the chosen UNO type is + * (a sequence type with element type) <code>UNSIGNED SHORT</code>.</li> + * + * <li>If the Java type is (an array type with element type) + * <code>int</code> or <code>java.lang.Integer</code>: If + * <code>alternative</code> is <code>false</code>, the chosen UNO type is + * (a sequence type with element type) <code>LONG</code>. If + * <code>alternative</code> is <code>true</code>, the chosen UNO type is + * (a sequence type with element type) <code>UNSIGNED LONG</code>.</li> + * + * <li>If the Java type is (an array type with element type) + * <code>long</code> or <code>java.lang.Long</code>: If + * <code>alternative</code> is <code>false</code>, the chosen UNO type is + * (a sequence type with element type) <code>HYPER</code>. If + * <code>alternative</code> is <code>true</code>, the chosen UNO type is + * (a sequence type with element type) <code>UNSIGNED HYPER</code>.</li> + * + * <li>If the Java type is (an array type with element type) + * <code>java.lang.Object</code>: If <code>alternative</code> is + * <code>false</code>, the chosen UNO type is (a sequence type with + * element type) <code>ANY</code>. If <code>alternative</code> is + * <code>true</code>, the chosen UNO type is (a sequence type with element + * type) <code>com.sun.star.uno.XInterface</code>.</li> + * </ul> + * <p>In all other cases, the value of <code>alternative</code> is + * ignored.</p> + * + * <p>This constructor cannot be used to create <code>Type</code> instances + * that represent (sequences of) instantiated polymorphic struct types.</p> + * + * @param zClass the Java class of this type; must not be <code>null</code> + * @param alternative controls which UNO type to choose in case of + * ambiguities + * + * @since UDK 3.2.0 + */ + public Type(Class zClass, boolean alternative) { + init(null, zClass, alternative, false); + } + + /** + * Constructs a new <code>Type</code> from the given type description. + * + * @param typeDescription a type description. Must not be + * <code>null</code>. + */ + public Type(ITypeDescription typeDescription) { + _typeName = typeDescription.getTypeName(); + _typeClass = typeDescription.getTypeClass(); + _iTypeDescription = typeDescription; + } + + /** + * Constructs a new <code>Type</code> with the given type name. + * + * @param typeName the name of this type; must not be <code>null</code>. + */ + public Type(String typeName) { + if (typeName.startsWith("[]")) { + _typeName = typeName; + _typeClass = TypeClass.SEQUENCE; + return; + } + for (int i = 0; i < __typeClassToTypeName.length; ++i) { + if (__typeClassToTypeName[i].equals(typeName)) { + _typeName = typeName; + _typeClass = TypeClass.fromInt(i); + return; + } + } + int i = typeName.indexOf('<'); + try { + init( + typeName, + Class.forName(i < 0 ? typeName : typeName.substring(0, i)), + false, i >= 0); + } catch (ClassNotFoundException e) { + throw new RuntimeException(e.toString()); + } + } + + /** + * Constructs a new <code>Type</code> with the given type class. + * + * @param typeClass the type class of this type; must not be + * <code>null</code>. Only type classes for simple types are allowed + * here. + * + * @throws IllegalArgumentException if the given <code>typeClass</code> is + * not simple (for example, a struct or an interface type). This + * constructor could not find out the type name in such a case. + */ + public Type(TypeClass typeClass) { + if(__isTypeClassPrimitive(typeClass)) { + _typeClass = typeClass; + _typeName = __typeClassToTypeName[typeClass.getValue()]; + } + else + throw new IllegalArgumentException(typeClass + " is not primitive"); + } + + /** + * Gets the type class. + * + * @return the type class. Will never be <code>null</code>, but might be + * <code>UNKNOWN</code>. + */ + public TypeClass getTypeClass() { + return _typeClass; + } + + /** + * Gets the type name. + * + * @return the type name; will never be <code>null</code> + */ + public String getTypeName() { + return _typeName; + } + + /** + * Gets the Java class. + * + * @return the type name; may be <code>null</code> in extreme situations + * (inconsistent <code>TypeClass</code>, error loading a class) + */ + public Class getZClass() { + synchronized (this) { + if (_class == null) { + _class = determineClass(); + } + } + return _class; + } + + /** + * Gives the type description of this type. + * + * @return the type description; may be <code>null</code> + */ + public ITypeDescription getTypeDescription() { + return _iTypeDescription; + } + + /** + * Sets the type description for this type. + * + * @param typeDescription the type description + */ + public void setTypeDescription(ITypeDescription typeDescription) { + _iTypeDescription = typeDescription; + } + + /** + * Determines whether this UNO type is a supertype of another UNO type. + * + * UNO only defines the following supertype relations: + * (1) A struct type t1 is a supertype of a struct type t2, if either t1 + * and t2 are the same, or t1 is a direct or indirect parent of t2. + * (2) An exception type t1 is a supertype of an exception type t2, if + * either t1 and t2 are the same, or t1 is a direct or indirect parent + * of t2. + * (3) An interface type t1 is a supertype of an interface type t2, if + * either t1 and t2 are the same, or t1 is a direct or indirect parent + * of t2. + * + * Following the conventions of the Java UNO language binding, + * com.sun.star.uno.Exception is not considered a supertype of + * com.sun.star.uno.RuntimeException or any exception type derived from + * com.sun.star.uno.RuntimeException. + * + * @param type some Type + * @return true if this type is a supertype of the given type + * + * @since UDK 3.2.0 + */ + public boolean isSupertypeOf(Type type) { + if (_typeClass != type._typeClass) { + return false; + } + switch (_typeClass.getValue()) { + case TypeClass.SEQUENCE_value: + case TypeClass.ENUM_value: + return _typeName.equals(type._typeName); + + case TypeClass.STRUCT_value: + // This check exploits the fact that an instantiated polymorphic + // struct type may not be the direct base of a struct type: + if (_typeName.indexOf('<') >= 0 || type._typeName.indexOf('<') >= 0) + { + return _typeName.equals(type._typeName); + } + case TypeClass.EXCEPTION_value: + case TypeClass.INTERFACE_value: + Class c1 = getZClass(); + Class c2 = type.getZClass(); + return c1 != null && c2 != null && c1.isAssignableFrom(c2); + + default: + return true; + } + } + + // @see java.lang.Object#equals + public boolean equals(Object obj) { + return obj instanceof Type + && _typeClass == ((Type) obj)._typeClass + && _typeName.equals(((Type) obj)._typeName); + } + + // @see java.lang.Object#hashCode + public int hashCode() { + return _typeName.hashCode(); + } + + // @see java.lang.Object#toString + public String toString() { + return "Type[" + _typeName + "]"; + } + + private void init( + String name, Class zClass, boolean alternative, boolean arguments) + { + TypeClass[] tc = (TypeClass[]) __javaClassToTypeClass.get(zClass); + if (tc != null) { + // tc only contains primitive type classes, except for + // TypeClass.INTERFACE, which stands for XInterface (the alternative + // interpretation of java.lang.Object): + _typeClass = tc[alternative ? 1 : 0]; + _typeName = _typeClass == TypeClass.INTERFACE + ? XInterface.class.getName() + : __typeClassToTypeName[_typeClass.getValue()]; + // do not assign _class from zClass, as _class should always be + // normalized (e.g., boolean.class instead of + // java.lang.Boolean.class); getZClass will later calculate the + // correct class when needed + } else if (zClass.isArray()) { + Type t = new Type(zClass.getComponentType(), alternative); + _typeClass = t.getTypeClass() != TypeClass.UNKNOWN + ? TypeClass.SEQUENCE : TypeClass.UNKNOWN; + _typeName = "[]" + t.getTypeName(); + // do not assign _class from zClass, as _class should always be + // normalized (e.g., boolean[].class instead of + // java.lang.Boolean[].class); getZClass will later calculate the + // correct class when needed + } else if (Enum.class.isAssignableFrom(zClass)) { + _typeClass = zClass != Enum.class + ? TypeClass.ENUM : TypeClass.UNKNOWN; + _typeName = zClass.getName(); + _class = zClass; + } else if (Throwable.class.isAssignableFrom(zClass)) { + _typeClass + = com.sun.star.uno.Exception.class.isAssignableFrom(zClass) + || com.sun.star.uno.RuntimeException.class.isAssignableFrom( + zClass) + ? TypeClass.EXCEPTION : TypeClass.UNKNOWN; + _typeName = zClass.getName(); + _class = zClass; + } else if (zClass.isInterface()) { + _typeClass = XInterface.class.isAssignableFrom(zClass) + ? TypeClass.INTERFACE : TypeClass.UNKNOWN; + _typeName = zClass.getName(); + _class = zClass; + } else if (XInterface.class.isAssignableFrom(zClass)) { + // This case is needed by code that uses this constructor to + // calculate the UNO type corresponding to a Java object: + _typeClass = TypeClass.INTERFACE; + _typeName = XInterface.class.getName(); + _class = XInterface.class; + } else { + // assert zClass != Object.class && !zClass.isPrimitive(); + _typeClass = TypeClass.STRUCT; + _typeName = name == null ? zClass.getName() : name; + _class = zClass; + } + if (arguments && _typeClass != TypeClass.STRUCT) { + throw new IllegalArgumentException( + zClass + " cannot have type arguments"); + } + } + + private Class determineClass() { + switch (_typeClass.getValue()) { + case TypeClass.VOID_value: + return _typeName.equals(TYPE_NAME_VOID) ? void.class : null; + + case TypeClass.BOOLEAN_value: + return _typeName.equals(TYPE_NAME_BOOLEAN) ? boolean.class : null; + + case TypeClass.BYTE_value: + return _typeName.equals(TYPE_NAME_BYTE) ? byte.class : null; + + case TypeClass.SHORT_value: + return _typeName.equals(TYPE_NAME_SHORT) ? short.class : null; + + case TypeClass.UNSIGNED_SHORT_value: + return _typeName.equals(TYPE_NAME_UNSIGNED_SHORT) + ? short.class : null; + + case TypeClass.LONG_value: + return _typeName.equals(TYPE_NAME_LONG) ? int.class : null; + + case TypeClass.UNSIGNED_LONG_value: + return _typeName.equals(TYPE_NAME_UNSIGNED_LONG) ? int.class : null; + + case TypeClass.HYPER_value: + return _typeName.equals(TYPE_NAME_HYPER) ? long.class : null; + + case TypeClass.UNSIGNED_HYPER_value: + return _typeName.equals(TYPE_NAME_UNSIGNED_HYPER) + ? long.class : null; + + case TypeClass.FLOAT_value: + return _typeName.equals(TYPE_NAME_FLOAT) ? float.class : null; + + case TypeClass.DOUBLE_value: + return _typeName.equals(TYPE_NAME_DOUBLE) ? double.class : null; + + case TypeClass.CHAR_value: + return _typeName.equals(TYPE_NAME_CHAR) ? char.class : null; + + case TypeClass.STRING_value: + return _typeName.equals(TYPE_NAME_STRING) ? String.class : null; + + case TypeClass.TYPE_value: + return _typeName.equals(TYPE_NAME_TYPE) ? Type.class : null; + + case TypeClass.ANY_value: + return _typeName.equals(TYPE_NAME_ANY) ? Object.class : null; + + case TypeClass.SEQUENCE_value: + StringBuffer buf = new StringBuffer(); + int offset = 0; + for (; _typeName.startsWith("[]", offset); offset += "[]".length()) + { + buf.append('['); + } + if (buf.length() == 0) { + return null; + } + String base = _typeName.substring(offset); + if (base.equals(TYPE_NAME_VOID)) { + buf.append('V'); + } else if (base.equals(TYPE_NAME_BOOLEAN)) { + buf.append('Z'); + } else if (base.equals(TYPE_NAME_BYTE)) { + buf.append('B'); + } else if (base.equals(TYPE_NAME_SHORT) + || base.equals(TYPE_NAME_UNSIGNED_SHORT)) { + buf.append('S'); + } else if (base.equals(TYPE_NAME_LONG) + || base.equals(TYPE_NAME_UNSIGNED_LONG)) { + buf.append('I'); + } else if (base.equals(TYPE_NAME_HYPER) + || base.equals(TYPE_NAME_UNSIGNED_HYPER)) { + buf.append('J'); + } else if (base.equals(TYPE_NAME_FLOAT)) { + buf.append('F'); + } else if (base.equals(TYPE_NAME_DOUBLE)) { + buf.append('D'); + } else if (base.equals(TYPE_NAME_CHAR)) { + buf.append('C'); + } else if (base.equals(TYPE_NAME_STRING)) { + buf.append("Ljava.lang.String;"); + } else if (base.equals(TYPE_NAME_TYPE)) { + buf.append("Lcom.sun.star.uno.Type;"); + } else if (base.equals(TYPE_NAME_ANY)) { + buf.append("Ljava.lang.Object;"); + } else { + int args = base.indexOf('<'); + if (args >= 0) { + base = base.substring(0, args); + } + Class c; + try { + c = Class.forName(base); + } catch (ClassNotFoundException e) { + return null; + } + if (args < 0 && new Type(c).getTypeClass() == TypeClass.UNKNOWN) + { + return null; + } + buf.append('L'); + buf.append(base); + buf.append(';'); + } + try { + return Class.forName(buf.toString()); + } catch (ClassNotFoundException e) { + return null; + } + + case TypeClass.ENUM_value: + case TypeClass.EXCEPTION_value: + case TypeClass.INTERFACE_value: + { + Class c; + try { + c = Class.forName(_typeName); + } catch (ClassNotFoundException e) { + return null; + } + return new Type(c).equals(this) ? c : null; + } + + case TypeClass.STRUCT_value: + { + int args = _typeName.indexOf('<'); + Class c; + try { + c = Class.forName( + args < 0 ? _typeName : _typeName.substring(0, args)); + } catch (ClassNotFoundException e) { + return null; + } + return args >= 0 || new Type(c).equals(this) ? c : null; + } + + default: + return null; + } + } + + private static boolean __isTypeClassPrimitive(TypeClass typeClass) { + return typeClass.getValue() < __typeClassToTypeName.length; + } + + protected TypeClass _typeClass; // TODO should be final + protected String _typeName; // TODO should be final + + protected Class _class; + protected ITypeDescription _iTypeDescription; +} diff --git a/ridljar/com/sun/star/uno/Union.java b/ridljar/com/sun/star/uno/Union.java new file mode 100644 index 000000000000..5edb1988c820 --- /dev/null +++ b/ridljar/com/sun/star/uno/Union.java @@ -0,0 +1,52 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +package com.sun.star.uno; + +/** + * The Union class is the base class for all classes generated + * as java binding for the IDL type union. + * <p> + * Note: The idl type <code>union<code> is currently not fully + * integrated into the UNO framework, so don't use it. + * + * @version $Revision: 1.5 $ $ $Date: 2008-04-11 11:15:07 $ + */ +public class Union { + /** + * Get the value in the union. + * The representation of the value is an any. + * <p> + * @return the any value. + */ + public final Object getValue() { + return m_value; + } + + protected Object m_value; +} + diff --git a/ridljar/com/sun/star/uno/UnoRuntime.java b/ridljar/com/sun/star/uno/UnoRuntime.java new file mode 100644 index 000000000000..188ea54a74a6 --- /dev/null +++ b/ridljar/com/sun/star/uno/UnoRuntime.java @@ -0,0 +1,696 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +package com.sun.star.uno; + +import java.io.IOException; +import java.lang.reflect.Array; +import java.lang.reflect.Constructor; +import java.util.ArrayList; +import java.util.Iterator; +import com.sun.star.lib.uno.typedesc.TypeDescription; +import com.sun.star.lib.util.WeakMap; + +/** + * The central class needed for implementing or using UNO components in Java. + * + * <p>The methods <code>queryInterface</code> and <code>areSame</code> delegate + * calls to the implementing objects and are used instead of casts, + * <code>instanceof</code>, <code>==</code>, and <code>equals</code>.<p> + * + * <p>For historic reasons, this class is not <code>final</code>, and has a + * <code>public</code> 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.</p> + * + * @see com.sun.star.uno.IBridge + * @see com.sun.star.uno.IEnvironment + * @see com.sun.star.uno.IQueryInterface + */ +public class UnoRuntime { + /** + * @deprecated As of UDK 3.2.0, do not create instances of this class. + * It is considered a historic mistake to have a <code>public</code> + * constructor for this class, which only has <code>static</code> members. + * Also, this class might be changed to become <code>final</code> in a + * future version. + */ + public UnoRuntime() {} + + /** + * Generates a world wide unique identifier string. + * + * <p>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.</p> + * + * @return a unique <code>String</code> + */ + public static String getUniqueKey() { + synchronized (uniqueKeyLock) { + if (uniqueKeyCount == Long.MAX_VALUE) { + long time; + for (time = System.currentTimeMillis(); time == uniqueKeyTime;) + { + // Conservatively sleep for 100 millisecond to wait for + // System.currentTimeMillis() to change: + try { + Thread.sleep(100); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + } + } + uniqueKeyTime = time; + uniqueKeyCount = Long.MIN_VALUE; + } + return uniqueKeyHostPrefix + Long.toString(uniqueKeyTime, 16) + ":" + + Long.toString(uniqueKeyCount++, 16); + } + } + + /** + * Generates a world wide unique object identifier (OID) for the given + * Java object. + * + * <p>It is guaranteed that subsequent calls to this method with the same + * Java object will give the same ID.</p> + * + * <p>This method is generally of little use for client code. It should be + * considered a mistake that this method is published at all.</p> + * + * @param object any object for which a OID shall be generated; must not be + * <code>null</code> + * @return the generated OID + * @see com.sun.star.uno.IQueryInterface#getOid + */ + public static String generateOid(Object object) { + String oid = null; + if (object instanceof IQueryInterface) { + oid = ((IQueryInterface) object).getOid(); + } + return oid == null ? object.hashCode() + oidSuffix : oid; + } + + /** + * Queries the given UNO object for the given UNO interface type. + * + * <p>This method returns <code>null</code> in case the given UNO object + * does not support the given UNO interface type (or is itself + * <code>null</code>). 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.</p> + * + * @param type the requested UNO interface type; must be a <code>Type</code> + * object representing a UNO interface type + * @param object a reference to any Java object representing (a facet of) a + * UNO object; may be <code>null</code> + * @return a reference to the requested UNO interface type if available, + * otherwise <code>null</code> + * @see com.sun.star.uno.IQueryInterface#queryInterface + */ + public static Object queryInterface(Type type, Object object) { + // Gracefully handle those situations where the passed in UNO object is + // wrapped in an Any. Strictly speaking, such a situation constitutes a + // bug, but it is anticipated that such situations will arise quite + // often in practice (especially since UNO Anys containing an XInterface + // reference are not wrapped in a Java Any, but UNO Anys containing any + // other interface reference are wrapped in a Java Any, which can lead + // to confusion). + if (object instanceof Any) { + Any a = (Any) object; + if (a.getType().getTypeClass() == TypeClass.INTERFACE) { + object = a.getObject(); + } + } + if (object instanceof IQueryInterface) { + object = ((IQueryInterface) object).queryInterface(type); + if (object instanceof Any) { + Any a = (Any) object; + object = a.getType().getTypeClass() == TypeClass.INTERFACE + ? a.getObject() : null; + } + } + // Ensure that the object implements the requested interface type: + Class c = type.getZClass(); + if (c == null || !c.isInstance(object)) { + object = null; + } + return object; + } + + /** + * Queries the given UNO object for the given Java class (which must + * represent a UNO interface type). + * + * @param ifc a Java class representing a UNO interface type + * @param object a reference to any Java object representing (a facet of) a + * UNO object; may be <code>null</code> + * @return a reference to the requested UNO interface type if available, + * otherwise <code>null</code> + * @see #queryInterface(Type, Object) + */ + @SuppressWarnings("unchecked") + public static <T> T queryInterface(Class<T> zInterface, Object object) { + return (T) queryInterface(new Type(zInterface), object); + } + + /** + Tests two UNO <code>ANY</code> values for equality. + + <p>Two UNO values are <dfn>equal</dfn> if and only if they are of the + same UNO type <var>t</var>, and they meet the following condition, + depending on <var>t</var>:</p> + <ul> + <li>If <var>t</var> is a primitive type, then both values must denote + the same element of the set of values of <var>t</var>.</li> + + <li>If <var>t</var> is a structured type, then both values must + recursively contain corresponding values that are equal.</li> + + <li>If <var>t</var> is an interface type, then the two values must be + either both null references, or both references to the same UNO + object.</li> + </ul> + + @param any1 a Java value representing a UNO <code>ANY</code> value. + + @param any2 a Java value representing a UNO <code>ANY</code> value. + + @return <code>true</code> if and only if the two arguments represent + equal UNO values. + */ + public static boolean areSame(Object any1, Object any2) { + Any a1 = Any.complete(any1); + Any a2 = Any.complete(any2); + Type t = a1.getType(); + if (!a2.getType().equals(t)) { + return false; + } + Object v1 = a1.getObject(); + Object v2 = a2.getObject(); + switch (t.getTypeClass().getValue()) { + case TypeClass.VOID_value: + return true; + case TypeClass.BOOLEAN_value: + case TypeClass.BYTE_value: + case TypeClass.SHORT_value: + case TypeClass.UNSIGNED_SHORT_value: + case TypeClass.LONG_value: + case TypeClass.UNSIGNED_LONG_value: + case TypeClass.HYPER_value: + case TypeClass.UNSIGNED_HYPER_value: + case TypeClass.FLOAT_value: + case TypeClass.DOUBLE_value: + case TypeClass.CHAR_value: + case TypeClass.STRING_value: + case TypeClass.TYPE_value: + return v1.equals(v2); + case TypeClass.SEQUENCE_value: + int n = Array.getLength(v1); + if (n != Array.getLength(v2)) { + return false; + } + for (int i = 0; i < n; ++i) { + // Recursively using areSame on Java values that are (boxed) + // elements of Java arrays representing UNO sequence values, + // instead of on Java values that are representations of UNO ANY + // values, works by chance: + if (!areSame(Array.get(v1, i), Array.get(v2, i))) { + return false; + } + } + return true; + case TypeClass.ENUM_value: + return v1 == v2; + case TypeClass.STRUCT_value: + case TypeClass.EXCEPTION_value: + IFieldDescription[] fs; + try { + fs = TypeDescription.getTypeDescription(t). + getFieldDescriptions(); + } catch (ClassNotFoundException e) { + throw new java.lang.RuntimeException(e.toString()); + } + for (int i = 0; i< fs.length; ++i) { + Type ft = new Type(fs[i].getTypeDescription()); + try { + // Recursively using areSame on Java values that are (boxed) + // fields of Java classes representing UNO struct or + // exception values, instead of on Java values that are + // representations of UNO ANY values, works by chance: + if (!areSame( + completeValue(ft, fs[i].getField().get(v1)), + completeValue(ft, fs[i].getField().get(v2)))) + { + return false; + } + } catch (IllegalAccessException e) { + throw new java.lang.RuntimeException(e.toString()); + } + } + return true; + case TypeClass.INTERFACE_value: + return v1 == v2 + || (v1 instanceof IQueryInterface + && ((IQueryInterface) v1).isSame(v2)) + || (v2 instanceof IQueryInterface + && ((IQueryInterface) v2).isSame(v1)); + default: + throw new java.lang.RuntimeException( + "com.sun.star.uno.Any has bad com.sun.star.uno.TypeClass"); + } + } + + /** + Complete a UNO value (make sure it is no invalid <code>null</code> + value). + + <p>This is useful for members of parameterized type of instantiated + polymorphic struct types, as <code>null</code> is a valid value there + (and only there, for all types except <code>ANY</code> and interface + types).</p> + + @param type a non-void, non-exception UNO type. + + @param value a Java value representing a UNO value of the given UNO type, + or <code>null</code>. + + @return the given value, or the neutral value of the given type, if the + given value was an invalid <code>null</code> value. + + @since UDK 3.2.3 + */ + public static final Object completeValue(Type type, Object value) { + if (value != null) { + return value; + } + switch (type.getTypeClass().getValue()) { + case TypeClass.BOOLEAN_value: + return Boolean.FALSE; + case TypeClass.BYTE_value: + return new Byte((byte) 0); + case TypeClass.SHORT_value: + case TypeClass.UNSIGNED_SHORT_value: + return new Short((short) 0); + case TypeClass.LONG_value: + case TypeClass.UNSIGNED_LONG_value: + return new Integer(0); + case TypeClass.HYPER_value: + case TypeClass.UNSIGNED_HYPER_value: + return new Long(0L); + case TypeClass.FLOAT_value: + return new Float(0.0f); + case TypeClass.DOUBLE_value: + return new Double(0.0); + case TypeClass.CHAR_value: + return new Character('\u0000'); + case TypeClass.STRING_value: + return ""; + case TypeClass.TYPE_value: + return Type.VOID; + case TypeClass.ANY_value: + case TypeClass.INTERFACE_value: + return null; + case TypeClass.SEQUENCE_value: + return Array.newInstance(type.getZClass().getComponentType(), 0); + case TypeClass.STRUCT_value: + try { + return type.getZClass().getConstructor(null).newInstance(null); + } catch (java.lang.RuntimeException e) { + throw e; + } catch (java.lang.Exception e) { + throw new java.lang.RuntimeException(e.toString()); + } + case TypeClass.ENUM_value: + try { + return type.getZClass().getMethod("getDefault", null).invoke( + null, null); + } catch (java.lang.RuntimeException e) { + throw e; + } catch (java.lang.Exception e) { + throw new java.lang.RuntimeException(e.toString()); + } + default: + throw new IllegalArgumentException( + "com.sun.star.uno.UnoRuntime.completeValue called with bad" + + " com.sun.star.uno.Type"); + } + } + + /** + * Gets the current context of the current thread, or <code>null</code> if + * no context has been set for the current thread. + * + * <p>The current context is thread local, which means that this method + * returns the context that was last set for this thread.</p> + * + * @return the current context of the current thread, or <code>null</code> + * if no context has been set for the current thread + */ + public static XCurrentContext getCurrentContext() { + return (XCurrentContext) currentContext.get(); + } + + /** + * Sets the current context for the current thread. + * + * <p>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 <code>finally</code> + * block).</p> + * + * @param context the context to be set; if <code>null</code>, any + * previously set context will be removed + */ + public static void setCurrentContext(XCurrentContext context) { + // optimize this by using Java 1.5 ThreadLocal.remove if context == null + currentContext.set(context); + } + + /** + * Retrieves an environment of type <code>name</code> with context + * <code>context</code>. + * + * <p>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 + * <code>com.sun.star.lib.uno.environments.<var>name</var>.<!-- + * --><var>name</var>_environment</code>.</p> + * + * @param name the name of the environment + * @param context the context of the environment + * @see com.sun.star.uno.IEnvironment + * + * @deprecated As of UDK 3.2.0, this method is deprecated, without + * offering a replacement. + */ + public static IEnvironment getEnvironment(String name, Object context) + throws java.lang.Exception + { + synchronized (environments) { + IEnvironment env = (IEnvironment) WeakMap.getValue( + environments.get(name + context)); + if (env == null) { + Class c = Class.forName( + "com.sun.star.lib.uno.environments." + name + "." + name + + "_environment"); + Constructor ctor = c.getConstructor( + new Class[] { Object.class }); + env = (IEnvironment) ctor.newInstance(new Object[] { context }); + environments.put(name + context, env); + } + return env; + } + } + + /** + * Gets a bridge from environment <code>from</code> to environment + * <code>to</code>. + * + * <p>Creates a new bridge, if the requested bridge does not yet exist, and + * hands the arguments to the bridge.</p> + * + * <p>If the requested bridge does not exist, it is searched for in package + * <code>com.sun.star.lib.uno.bridges.<var>from</var>_<var>to</var>;</code> + * and the root classpath as + * <code><var>from</var>_<var>to</var>_bridge</code>.</p> + * + * @param from the source environment + * @param to the target environment + * @param args the initial arguments for the bridge + * @return the requested bridge + * @see #getBridgeByName + * @see com.sun.star.uno.IBridge + * @see com.sun.star.uno.IEnvironment + * + * @deprecated As of UDK 3.2.0, this method is deprecated, without + * offering a replacement. + */ + public static IBridge getBridge( + IEnvironment from, IEnvironment to, Object[] args) + throws java.lang.Exception + { + synchronized (bridges) { + String name = from.getName() + "_" + to.getName(); + String hashName = from.getName() + from.getContext() + "_" + + to.getName() + to.getContext(); + IBridge bridge = (IBridge) WeakMap.getValue(bridges.get(hashName)); + if(bridge == null) { + Class zClass = null; + String className = name + "_bridge"; + try { + zClass = Class.forName(className); + } catch (ClassNotFoundException e) { + className = "com.sun.star.lib.uno.bridges." + name + "." + + className; + zClass = Class.forName(className); + } + Class[] signature = { + IEnvironment.class, IEnvironment.class, args.getClass() }; + Constructor constructor = zClass.getConstructor(signature); + Object[] iargs = { from, to, args }; + bridge = (IBridge) constructor.newInstance(iargs); + bridges.put(hashName, bridge); + } + return bridge; + } + } + + /** + * Gets a bridge from environment <code>from</code> to environment + * <code>to</code>. + * + * <p>Creates a new bridge, if the requested bridge does not yet exist, and + * hands the arguments to the bridge.</p> + * + * <p>If the requested bridge does not exist, it is searched for in package + * <code>com.sun.star.lib.uno.bridges.<var>from</var>_<var>to</var>;</code> + * and the root classpath as + * <code><var>from</var>_<var>to</var>_bridge</code>. The used environments + * are retrieved through <code>getEnvironment</code>.</p> + * + * @param from the name of the source environment + * @param fromContext the context for the source environment + * @param to the name of the target environment + * @param toContext the context for the target environment + * @param args the initial arguments for the bridge + * @return the requested bridge + * @see #getBridge + * @see #getEnvironment + * @see com.sun.star.uno.IBridge + * @see com.sun.star.uno.IEnvironment + * + * @deprecated As of UDK 3.2.0, this method is deprecated, without + * offering a replacement. + */ + public static IBridge getBridgeByName( + String from, Object fromContext, String to, Object toContext, + Object[] args) throws java.lang.Exception + { + return getBridge( + getEnvironment(from, fromContext), getEnvironment(to, toContext), + args); + } + + /** + * Returns an array of all active bridges. + * + * @return an array of <code>IBridge</code> objects + * @see com.sun.star.uno.IBridge + * + * @deprecated As of UDK 3.2.0, this method is deprecated, without + * offering a replacement. + */ + public static IBridge[] getBridges() { + ArrayList l = new ArrayList(); + synchronized (bridges) { + for (Iterator i = bridges.values().iterator(); i.hasNext();) { + Object o = WeakMap.getValue(i.next()); + if (o != null) { + l.add(o); + } + } + } + return (IBridge[]) l.toArray(new IBridge[l.size()]); + } + + /** + * Gets a mapping from environment <code>from</code> to environment + * <code>to</code>. + * + * <p>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.</p> + * + * @param from the source environment + * @param to the target environment + * @return the requested mapping + * @see com.sun.star.uno.IEnvironment + * @see com.sun.star.uno.IMapping + * + * @deprecated As of UDK 3.2.0, this method is deprecated, without + * offering a replacement. + */ + public static IMapping getMapping(IEnvironment from, IEnvironment to) + throws java.lang.Exception + { + IBridge bridge; + try { + bridge = getBridge(from, to, null); + } + catch (ClassNotFoundException e) { + bridge = new BridgeTurner(getBridge(to, from, null)); + } + return new MappingWrapper(bridge); + } + + /** + * Gets a mapping from environment <code>from</code> to environment + * <code>to</code>. + * + * <p>The used environments are retrieved through + * <code>getEnvironment</code>.</p> + * + * @param from the name of the source environment + * @param to the name of the target environment + * @return the requested mapping + * @see #getEnvironment + * @see #getMapping + * @see com.sun.star.uno.IMapping + * + * @deprecated As of UDK 3.2.0, this method is deprecated, without + * offering a replacement. + */ + public static IMapping getMappingByName(String from, String to) + throws java.lang.Exception + { + return getMapping(getEnvironment(from, null), getEnvironment(to, null)); + } + + /** + * Resets this <code>UnoRuntime</code> to its initial state. + * + * <p>Releases all references to bridges and environments.</p> + * + * @deprecated As of UDK 3.2.0, this method is deprecated, without + * offering a replacement. + */ + static public boolean reset() { + synchronized (bridges) { + for (Iterator i = bridges.values().iterator(); i.hasNext();) { + IBridge b = (IBridge) WeakMap.getValue(i.next()); + if (b != null) { + // The following call to dispose was originally made to + // com.sun.star.lib.sandbox.Disposable.dispose, which cannot + // throw an InterruptedException or IOException: + try { + b.dispose(); + } catch (InterruptedException e) { + Thread.currentThread().interrupted(); + throw new RuntimeException( + "Unexpected exception in UnoRuntime.reset: " + e); + } catch (IOException e) { + throw new RuntimeException( + "Unexpected exception in UnoRuntime.reset: " + e); + } + } + } + bridges.clear(); + } + environments.clear(); + return bridges.isEmpty() && environments.isEmpty(); + } + + /** + * @deprecated As of UDK 3.2.0, do not use this internal field. + */ + static public final boolean DEBUG = false; + + private static final class BridgeTurner implements IBridge { + public BridgeTurner(IBridge bridge) { + this.bridge = bridge; + } + + public Object mapInterfaceTo(Object object, Type type) { + return bridge.mapInterfaceFrom(object, type); + } + + public Object mapInterfaceFrom(Object object, Type type) { + return bridge.mapInterfaceTo(object, type); + } + + public IEnvironment getSourceEnvironment() { + return bridge.getTargetEnvironment(); + } + + public IEnvironment getTargetEnvironment() { + return bridge.getSourceEnvironment(); + } + + public void acquire() { + bridge.acquire(); + } + + public void release() { + bridge.release(); + } + + public void dispose() throws InterruptedException, IOException { + bridge.dispose(); + } + + private final IBridge bridge; + } + + private static final class MappingWrapper implements IMapping { + public MappingWrapper(IBridge bridge) { + this.bridge = bridge; + } + + public Object mapInterface(Object object, Type type) { + return bridge.mapInterfaceTo(object, type); + } + + private final IBridge bridge; + } + + private static final String uniqueKeyHostPrefix + = Integer.toString(new Object().hashCode(), 16) + ":"; + private static final Object uniqueKeyLock = new Object(); + private static long uniqueKeyTime = System.currentTimeMillis(); + private static long uniqueKeyCount = Long.MIN_VALUE; + + private static final String oidSuffix = ";java[];" + getUniqueKey(); + + private static final ThreadLocal currentContext = new ThreadLocal(); + + private static final WeakMap environments = new WeakMap(); + private static final WeakMap bridges = new WeakMap(); +} |