summaryrefslogtreecommitdiff
path: root/javaunohelper/com
diff options
context:
space:
mode:
authorJoachim Lingner <jl@openoffice.org>2002-04-17 10:19:56 +0000
committerJoachim Lingner <jl@openoffice.org>2002-04-17 10:19:56 +0000
commitfb474996bc46d4f0708b562050b305d12de5e80a (patch)
treec13100cb1e1d08ecbb8ed071dbafa857e82c51cd /javaunohelper/com
parent24084330d7b867e36b3e905667d2ca7803e461b4 (diff)
#97746#
Diffstat (limited to 'javaunohelper/com')
-rw-r--r--javaunohelper/com/sun/star/lib/uno/helper/WeakBase.java149
1 files changed, 82 insertions, 67 deletions
diff --git a/javaunohelper/com/sun/star/lib/uno/helper/WeakBase.java b/javaunohelper/com/sun/star/lib/uno/helper/WeakBase.java
index 1913748c291f..4c3c6a742f44 100644
--- a/javaunohelper/com/sun/star/lib/uno/helper/WeakBase.java
+++ b/javaunohelper/com/sun/star/lib/uno/helper/WeakBase.java
@@ -2,9 +2,9 @@
*
* $RCSfile: WeakBase.java,v $
*
- * $Revision: 1.1 $
+ * $Revision: 1.2 $
*
- * last change: $Author: jl $ $Date: 2002-04-11 13:39:51 $
+ * last change: $Author: jl $ $Date: 2002-04-17 11:19:56 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -67,98 +67,113 @@ import com.sun.star.uno.Type;
import java.lang.reflect.Field;
import java.util.Vector;
import com.sun.star.uno.UnoRuntime;
+import java.util.Map;
+import java.util.Hashtable;
/** This class can be used as the base class for UNO components. It implements the capability
* to be kept weak (com.sun.star.uno.XWeak) and it implements com.sun.star.lang.XTypeProvider
* which is necessary for using the component with StarBasic.
*/
-public class WeakBase implements XWeak, XTypeProvider {
+public class WeakBase implements XWeak, XTypeProvider
+{
private final boolean DEBUG= false;
- private final String UNO_INTERFACE_FIELD="UNOTYPEINFO";
- private final String UNO_INTERFACE_TYPE="[Lcom.sun.star.lib.uno.typeinfo.TypeInfo;";
// Contains all WeakAdapter which have been created in this class
// They have to be notified when this object dies
private WeakAdapter m_adapter;
- // for XTypeProvider.getImplementationId
- static byte[] _implementationId;
+ protected static Map _mapImplementationIds= new Hashtable();
+ protected static Map _mapTypes= new Hashtable();
- /** Method of XWeak. The returned XAdapter implementation can be used to keap
- * a weak reference to this object.
- * @return a com.sun.star.uno.XAdapter implementation.
- */
- synchronized public XAdapter queryAdapter() {
+ /** Method of XWeak. The returned XAdapter implementation can be used to keap
+ * a weak reference to this object.
+ * @return a com.sun.star.uno.XAdapter implementation.
+ */
+ synchronized public XAdapter queryAdapter()
+ {
if (m_adapter == null)
m_adapter= new WeakAdapter(this);
- return m_adapter;
- }
+ return m_adapter;
+ }
- /** Override of Object.finalize. When there are no references to this object anymore
- then the garbage collector calls this method. Thereby causing the adapter object
- to be notified. The adapter, in turn, notifies all listeners (com.sun.star.uno.XReference)
- */
- protected void finalize() throws java.lang.Throwable {
+ /** Override of Object.finalize. When there are no references to this object anymore
+ * then the garbage collector calls this method. Thereby causing the adapter object
+ * to be notified. The adapter, in turn, notifies all listeners (com.sun.star.uno.XReference)
+ */
+ protected void finalize() throws java.lang.Throwable
+ {
if (m_adapter != null)
m_adapter.referentDying();
super.finalize();
- }
+ }
- /** Method of XTypeProvider. It returns an array of Type objects which represent
- * all implemented UNO interfaces of this object.
- * @return Type objects of all implemented interfaces.
- */
- public Type[] getTypes() {
- Vector vec= new Vector();
- Class currentClass= getClass();
- do {
- Class interfaces[]= currentClass.getInterfaces();
- for(int i = 0; i < interfaces.length; ++ i) {
- // Test if it is a UNO interface, look for
- // public static final com.sun.star.lib.uno.typeinfo.TypeInfo UNOTYPEINFO[]
- try{
- Field unoField= interfaces[i].getField(UNO_INTERFACE_FIELD);
- if (unoField.getType().getName().equals(UNO_INTERFACE_TYPE)) {
+ /** Method of XTypeProvider. It returns an array of Type objects which represent
+ * all implemented UNO interfaces of this object.
+ * @return Type objects of all implemented interfaces.
+ */
+ public Type[] getTypes()
+ {
+ Type[] arTypes= (Type[]) _mapTypes.get( getClass());
+ if (arTypes == null)
+ {
+ Vector vec= new Vector();
+ Class currentClass= getClass();
+ do
+ {
+ Class interfaces[]= currentClass.getInterfaces();
+ for(int i = 0; i < interfaces.length; ++ i)
+ {
+ // Test if it is a UNO interface
+ if (com.sun.star.uno.XInterface.class.isAssignableFrom((interfaces[i])))
vec.add(new Type(interfaces[i]));
- }
- }catch (NoSuchFieldException nfe) {
}
- }
- // get the superclass the currentClass inherits from
- currentClass= currentClass.getSuperclass();
- } while (currentClass != null);
+ // get the superclass the currentClass inherits from
+ currentClass= currentClass.getSuperclass();
+ } while (currentClass != null);
- Type types[]= new Type[vec.size()];
- for( int i= 0; i < types.length; i++)
- types[i]= (Type) vec.elementAt(i);
+ Type types[]= new Type[vec.size()];
+ for( int i= 0; i < types.length; i++)
+ types[i]= (Type) vec.elementAt(i);
+ _mapTypes.put(getClass(), types);
+ arTypes= types;
+ }
+ return arTypes;
+ }
- return types;
- }
+ /** Method of XTypeProvider. It provides an identifier that represents the set of UNO
+ * interfaces implemented by this class. All instances of this class
+ * which run in the same Java Virtual Machine return the same array. (This only works as long
+ * the ClassLoader preserves the class even if no instance exist.)
+ *@return identifier as array of bytes
+ */
+ public byte[] getImplementationId()
+ {
+ byte[] id= null;
+ synchronized (_mapImplementationIds)
+ {
+ id= (byte[]) _mapImplementationIds.get(getClass());
- /** Method of XTypeProvider. It provides an identifier that represents the set of UNO
- * interfaces implemented by this class. All instances of this class
- * which run in the same Java Virtual Machine return the same array. (This only works as long
- * the ClassLoader preserves the class even if no instance exist.)
- *@return identifier as array of bytes
- */
- synchronized public byte[] getImplementationId() {
- if (_implementationId == null) {
- int hash = hashCode();
- String sName= getClass().getName();
- byte[] arName= sName.getBytes();
- int nNameLength= arName.length;
+ if (id == null)
+ {
+ int hash = hashCode();
+ String sName= getClass().getName();
+ byte[] arName= sName.getBytes();
+ int nNameLength= arName.length;
- _implementationId= new byte[ 4 + nNameLength];
- _implementationId[0] = (byte)(hash & 0xff);
- _implementationId[1] = (byte)((hash >>> 8) & 0xff);
- _implementationId[2] = (byte)((hash >>> 16) & 0xff);
- _implementationId[3] = (byte)((hash >>>24) & 0xff);
+ id= new byte[ 4 + nNameLength];
+ id[0]= (byte)(hash & 0xff);
+ id[1]= (byte)((hash >>> 8) & 0xff);
+ id[2]= (byte)((hash >>> 16) & 0xff);
+ id[3]= (byte)((hash >>>24) & 0xff);
- for (int i= 0; i < nNameLength; i++) {
- _implementationId[4 + i]= arName[i];
+ for (int i= 0; i < nNameLength; i++)
+ {
+ id[4 + i]= arName[i];
+ }
+ _mapImplementationIds.put(getClass(), id);
}
}
- return _implementationId;
- }
+ return id;
+ }
}