summaryrefslogtreecommitdiff
path: root/ridljar/com/sun/star/lib
diff options
context:
space:
mode:
Diffstat (limited to 'ridljar/com/sun/star/lib')
-rw-r--r--ridljar/com/sun/star/lib/uno/typedesc/FieldDescription.java76
-rw-r--r--ridljar/com/sun/star/lib/uno/typedesc/MemberDescriptionHelper.java64
-rw-r--r--ridljar/com/sun/star/lib/uno/typedesc/MethodDescription.java111
-rw-r--r--ridljar/com/sun/star/lib/uno/typedesc/TypeDescription.java721
-rw-r--r--ridljar/com/sun/star/lib/uno/typeinfo/AttributeTypeInfo.java95
-rw-r--r--ridljar/com/sun/star/lib/uno/typeinfo/ConstantTypeInfo.java40
-rw-r--r--ridljar/com/sun/star/lib/uno/typeinfo/MemberTypeInfo.java105
-rw-r--r--ridljar/com/sun/star/lib/uno/typeinfo/MethodTypeInfo.java98
-rw-r--r--ridljar/com/sun/star/lib/uno/typeinfo/ParameterTypeInfo.java114
-rw-r--r--ridljar/com/sun/star/lib/uno/typeinfo/TypeInfo.java85
-rw-r--r--ridljar/com/sun/star/lib/util/DisposeListener.java43
-rw-r--r--ridljar/com/sun/star/lib/util/DisposeNotifier.java53
-rw-r--r--ridljar/com/sun/star/lib/util/WeakMap.java311
13 files changed, 1916 insertions, 0 deletions
diff --git a/ridljar/com/sun/star/lib/uno/typedesc/FieldDescription.java b/ridljar/com/sun/star/lib/uno/typedesc/FieldDescription.java
new file mode 100644
index 000000000000..ec291f1a8470
--- /dev/null
+++ b/ridljar/com/sun/star/lib/uno/typedesc/FieldDescription.java
@@ -0,0 +1,76 @@
+/*************************************************************************
+ *
+ * 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.lib.uno.typedesc;
+
+import com.sun.star.uno.IFieldDescription;
+import com.sun.star.uno.ITypeDescription;
+import java.lang.reflect.Field;
+
+final class FieldDescription implements IFieldDescription {
+ public FieldDescription(
+ String name, int index, ITypeDescription typeDescription, Field field)
+ {
+ this.name = name;
+ this.index = index;
+ this.typeDescription = typeDescription;
+ this.field = field;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public boolean isUnsigned() {
+ return MemberDescriptionHelper.isUnsigned(typeDescription);
+ }
+
+ public boolean isAny() {
+ return MemberDescriptionHelper.isAny(typeDescription);
+ }
+
+ public boolean isInterface() {
+ return MemberDescriptionHelper.isInterface(typeDescription);
+ }
+
+ public int getIndex() {
+ return index;
+ }
+
+ public ITypeDescription getTypeDescription() {
+ return typeDescription;
+ }
+
+ public Field getField() {
+ return field;
+ }
+
+ private final String name;
+ private final int index;
+ private final ITypeDescription typeDescription;
+ private final Field field;
+}
diff --git a/ridljar/com/sun/star/lib/uno/typedesc/MemberDescriptionHelper.java b/ridljar/com/sun/star/lib/uno/typedesc/MemberDescriptionHelper.java
new file mode 100644
index 000000000000..0bc714374d64
--- /dev/null
+++ b/ridljar/com/sun/star/lib/uno/typedesc/MemberDescriptionHelper.java
@@ -0,0 +1,64 @@
+/*************************************************************************
+ *
+ * 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.lib.uno.typedesc;
+
+import com.sun.star.uno.ITypeDescription;
+import com.sun.star.uno.TypeClass;
+
+final class MemberDescriptionHelper {
+ public static boolean isUnsigned(ITypeDescription desc) {
+ switch (getElementTypeClass(desc).getValue()) {
+ case TypeClass.UNSIGNED_SHORT_value:
+ case TypeClass.UNSIGNED_LONG_value:
+ case TypeClass.UNSIGNED_HYPER_value:
+ return true;
+
+ default:
+ return false;
+ }
+ }
+
+ public static boolean isAny(ITypeDescription desc) {
+ return getElementTypeClass(desc) == TypeClass.ANY;
+ }
+
+ public static boolean isInterface(ITypeDescription desc) {
+ return getElementTypeClass(desc) == TypeClass.INTERFACE;
+ }
+
+ private static TypeClass getElementTypeClass(ITypeDescription desc) {
+ for (;; desc = desc.getComponentType()) {
+ TypeClass tc = desc.getTypeClass();
+ if (tc != TypeClass.SEQUENCE) {
+ return tc;
+ }
+ }
+ }
+
+ private MemberDescriptionHelper() {} // do not instantiate
+}
diff --git a/ridljar/com/sun/star/lib/uno/typedesc/MethodDescription.java b/ridljar/com/sun/star/lib/uno/typedesc/MethodDescription.java
new file mode 100644
index 000000000000..56792fc913aa
--- /dev/null
+++ b/ridljar/com/sun/star/lib/uno/typedesc/MethodDescription.java
@@ -0,0 +1,111 @@
+/*************************************************************************
+ *
+ * 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.lib.uno.typedesc;
+
+import com.sun.star.uno.IMethodDescription;
+import com.sun.star.uno.ITypeDescription;
+import java.lang.reflect.Method;
+
+public final class MethodDescription implements IMethodDescription {
+ MethodDescription(
+ String name, int index, boolean oneway, ITypeDescription[] inSignature,
+ ITypeDescription[] outSignature, ITypeDescription returnSignature,
+ Method method)
+ {
+ this.name = name;
+ this.index = index;
+ this.oneway = oneway;
+ this.inSignature = inSignature;
+ this.outSignature = outSignature;
+ this.returnSignature = returnSignature;
+ this.method = method;
+ }
+
+ MethodDescription(IMethodDescription other, int index) {
+ this(
+ other.getName(), index, other.isOneway(), other.getInSignature(),
+ other.getOutSignature(), other.getReturnSignature(),
+ other.getMethod());
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public boolean isUnsigned() {
+ return MemberDescriptionHelper.isUnsigned(returnSignature);
+ }
+
+ public boolean isAny() {
+ return MemberDescriptionHelper.isAny(returnSignature);
+ }
+
+ public boolean isInterface() {
+ return MemberDescriptionHelper.isInterface(returnSignature);
+ }
+
+ public int getIndex() {
+ return index;
+ }
+
+ public boolean isOneway() {
+ return oneway;
+ }
+
+ public boolean isConst() {
+ return false;
+ }
+
+ public ITypeDescription[] getInSignature() {
+ return inSignature;
+ }
+
+ public ITypeDescription[] getOutSignature() {
+ return outSignature;
+ }
+
+ public ITypeDescription getReturnSignature() {
+ return returnSignature;
+ }
+
+ public Method getMethod() {
+ return method;
+ }
+
+ public static final int ID_QUERY_INTERFACE = 0;
+ public static final int ID_ACQUIRE = 1;
+ public static final int ID_RELEASE = 2;
+
+ private final String name;
+ private final int index;
+ private final boolean oneway;
+ private final ITypeDescription[] inSignature;
+ private final ITypeDescription[] outSignature;
+ private final ITypeDescription returnSignature;
+ private final Method method;
+}
diff --git a/ridljar/com/sun/star/lib/uno/typedesc/TypeDescription.java b/ridljar/com/sun/star/lib/uno/typedesc/TypeDescription.java
new file mode 100644
index 000000000000..35113bed0d47
--- /dev/null
+++ b/ridljar/com/sun/star/lib/uno/typedesc/TypeDescription.java
@@ -0,0 +1,721 @@
+/*************************************************************************
+ *
+ * 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.lib.uno.typedesc;
+
+import com.sun.star.lib.uno.typeinfo.AttributeTypeInfo;
+import com.sun.star.lib.uno.typeinfo.MemberTypeInfo;
+import com.sun.star.lib.uno.typeinfo.MethodTypeInfo;
+import com.sun.star.lib.uno.typeinfo.ParameterTypeInfo;
+import com.sun.star.lib.uno.typeinfo.TypeInfo;
+import com.sun.star.uno.IFieldDescription;
+import com.sun.star.uno.IMethodDescription;
+import com.sun.star.uno.ITypeDescription;
+import com.sun.star.uno.Type;
+import com.sun.star.uno.TypeClass;
+import java.lang.ref.ReferenceQueue;
+import java.lang.ref.SoftReference;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.HashMap;
+
+/**
+ * Supplies information about UNO types.
+ *
+ * @since UDK2.0
+ */
+public final class TypeDescription implements ITypeDescription {
+ public static TypeDescription getTypeDescription(String typeName)
+ throws ClassNotFoundException
+ {
+ Type t = new Type(typeName);
+ if (t.getTypeClass() == TypeClass.UNKNOWN) {
+ if (typeName.startsWith("[]")) {
+ t = new Type(typeName, TypeClass.SEQUENCE);
+ } else {
+ t = new Type(Class.forName(typeName));
+ }
+ }
+ return get(t);
+ }
+
+ public static TypeDescription getTypeDescription(Class zClass) {
+ return getDefinitely(new Type(zClass));
+ }
+
+ public static TypeDescription getTypeDescription(Type type)
+ throws ClassNotFoundException
+ {
+ //TODO: synchronize on type?
+ TypeDescription desc = (TypeDescription) type.getTypeDescription();
+ if (desc == null) {
+ desc = getTypeDescription(type.getTypeName());
+ type.setTypeDescription(desc);
+ }
+ return desc;
+ }
+
+ public static TypeDescription getTypeDescription(TypeClass typeClass) {
+ switch (typeClass.getValue()) {
+ case TypeClass.VOID_value:
+ return getDefinitely(Type.VOID);
+
+ case TypeClass.BOOLEAN_value:
+ return getDefinitely(Type.BOOLEAN);
+
+ case TypeClass.BYTE_value:
+ return getDefinitely(Type.BYTE);
+
+ case TypeClass.SHORT_value:
+ return getDefinitely(Type.SHORT);
+
+ case TypeClass.UNSIGNED_SHORT_value:
+ return getDefinitely(Type.UNSIGNED_SHORT);
+
+ case TypeClass.LONG_value:
+ return getDefinitely(Type.LONG);
+
+ case TypeClass.UNSIGNED_LONG_value:
+ return getDefinitely(Type.UNSIGNED_LONG);
+
+ case TypeClass.HYPER_value:
+ return getDefinitely(Type.HYPER);
+
+ case TypeClass.UNSIGNED_HYPER_value:
+ return getDefinitely(Type.UNSIGNED_HYPER);
+
+ case TypeClass.FLOAT_value:
+ return getDefinitely(Type.FLOAT);
+
+ case TypeClass.DOUBLE_value:
+ return getDefinitely(Type.DOUBLE);
+
+ case TypeClass.CHAR_value:
+ return getDefinitely(Type.CHAR);
+
+ case TypeClass.STRING_value:
+ return getDefinitely(Type.STRING);
+
+ case TypeClass.TYPE_value:
+ return getDefinitely(Type.TYPE);
+
+ case TypeClass.ANY_value:
+ return getDefinitely(Type.ANY);
+
+ default:
+ return null;
+ }
+ }
+
+ public static boolean isTypeClassSimple(TypeClass typeClass) {
+ return getTypeDescription(typeClass) != null;
+ }
+
+ // @see ITypeDescription#getSuperType
+ public ITypeDescription getSuperType() {
+ // Arbitrarily take the first super type:
+ return superTypes == null || superTypes.length == 0
+ ? null : superTypes[0];
+ }
+
+ // @see ITypeDescription#getMethodDescriptions
+ public IMethodDescription[] getMethodDescriptions() {
+ initMethodDescriptions();
+ return methodDescriptions; //TODO: clone?
+ }
+
+ // @see ITypeDescription#getMethodDescription(int)
+ public IMethodDescription getMethodDescription(int methodId) {
+ initMethodDescriptions();
+ return methodId < 0
+ ? null
+ : methodId < superMethodDescriptions.length
+ ? superMethodDescriptions[methodId]
+ : (methodId - superMethodDescriptions.length
+ < methodDescriptions.length)
+ ? methodDescriptions[methodId - superMethodDescriptions.length]
+ : null;
+ }
+
+ // @see ITypeDescription#getMethodDescription(String)
+ public IMethodDescription getMethodDescription(String name) {
+ initMethodDescriptions();
+ for (int i = 0; i < superMethodDescriptions.length; ++i) {
+ if (superMethodDescriptions[i].getName().equals(name)) {
+ return superMethodDescriptions[i];
+ }
+ }
+ for (int i = 0; i < methodDescriptions.length; ++i) {
+ if (methodDescriptions[i].getName().equals(name)) {
+ return methodDescriptions[i];
+ }
+ }
+ return null;
+ }
+
+ // @see ITypeDescription#getFieldDescriptions
+ public IFieldDescription[] getFieldDescriptions() {
+ return fieldDescriptions; //TODO: clone?
+ }
+
+ // @see ITypeDescription#getFieldDescription
+ public IFieldDescription getFieldDescription(String name) {
+ for (int i = 0; i < fieldDescriptions.length; ++i) {
+ if (fieldDescriptions[i].getName().equals(name)) {
+ return fieldDescriptions[i];
+ }
+ }
+ return superTypes != null && superTypes.length == 1
+ ? superTypes[0].getFieldDescription(name) : null;
+ }
+
+ // @see ITypeDescription#getTypeClass
+ public TypeClass getTypeClass() {
+ return typeClass;
+ }
+
+ // @see ITypeDescription#getComponentType
+ public ITypeDescription getComponentType() {
+ return componentType;
+ }
+
+ // @see ITypeDescription#getTypeName
+ public String getTypeName() {
+ return typeName;
+ }
+
+ // @see ITypeDescription#getArrayTypeName
+ public String getArrayTypeName() {
+ return arrayTypeName;
+ }
+
+ // @see ITypeDescription#getZClass
+ public Class getZClass() {
+ return zClass;
+ }
+
+ public boolean hasTypeArguments() {
+ return hasTypeArguments;
+ }
+
+ // @see Object#toString
+ public String toString() {
+ return "[" + getClass().getName() + ": " + getTypeClass() + ", "
+ + getTypeName() + "]";
+ }
+
+ private static TypeDescription getDefinitely(Type type) {
+ try {
+ return get(type);
+ } catch (ClassNotFoundException e) {
+ throw new IllegalArgumentException("this cannot happen: " + e);
+ }
+ }
+
+ private static TypeDescription get(Type type) throws ClassNotFoundException
+ {
+ String typeName = type.getTypeName();
+ TypeDescription desc = cache.get(typeName);
+ if (desc == null) {
+ desc = create(type);
+ cache.put(desc);
+ }
+ return desc;
+ }
+
+ private static TypeDescription create(Type type)
+ throws ClassNotFoundException
+ {
+ TypeClass typeClass = type.getTypeClass();
+ String typeName = type.getTypeName();
+ Class zClass = type.getZClass();
+ if (zClass == null) {
+ throw new ClassNotFoundException("UNO type " + type);
+ }
+ switch (typeClass.getValue()) {
+ case TypeClass.VOID_value:
+ return new TypeDescription(
+ typeClass, typeName, "[Ljava.lang.Void;", zClass, null, null);
+
+ case TypeClass.BOOLEAN_value:
+ return new TypeDescription(
+ typeClass, typeName, "[Z", zClass, null, null);
+
+ case TypeClass.BYTE_value:
+ return new TypeDescription(
+ typeClass, typeName, "[B", zClass, null, null);
+
+ case TypeClass.SHORT_value:
+ case TypeClass.UNSIGNED_SHORT_value:
+ return new TypeDescription(
+ typeClass, typeName, "[S", zClass, null, null);
+
+ case TypeClass.LONG_value:
+ case TypeClass.UNSIGNED_LONG_value:
+ return new TypeDescription(
+ typeClass, typeName, "[I", zClass, null, null);
+
+ case TypeClass.HYPER_value:
+ case TypeClass.UNSIGNED_HYPER_value:
+ return new TypeDescription(
+ typeClass, typeName, "[J", zClass, null, null);
+
+ case TypeClass.FLOAT_value:
+ return new TypeDescription(
+ typeClass, typeName, "[F", zClass, null, null);
+
+ case TypeClass.DOUBLE_value:
+ return new TypeDescription(
+ typeClass, typeName, "[D", zClass, null, null);
+
+ case TypeClass.CHAR_value:
+ return new TypeDescription(
+ typeClass, typeName, "[C", zClass, null, null);
+
+ case TypeClass.STRING_value:
+ return new TypeDescription(
+ typeClass, typeName, "[Ljava.lang.String;", zClass, null, null);
+
+ case TypeClass.TYPE_value:
+ return new TypeDescription(
+ typeClass, typeName, "[Lcom.sun.star.uno.Type;", zClass, null,
+ null);
+
+ case TypeClass.ANY_value:
+ return new TypeDescription(
+ typeClass, typeName, "[Ljava.lang.Object;", zClass, null, null);
+
+ case TypeClass.SEQUENCE_value:
+ {
+ // assert typeName.startsWith("[]");
+ ITypeDescription componentType = getTypeDescription(
+ typeName.substring("[]".length()));
+ // assert zClass.getName().startsWith("[");
+ return new TypeDescription(
+ typeClass, typeName, "[" + zClass.getName(), zClass, null,
+ componentType);
+ }
+
+ case TypeClass.ENUM_value:
+ // assert !zClass.getName().startsWith("[");
+ return new TypeDescription(
+ typeClass, typeName, "[L" + zClass.getName() + ";", zClass,
+ null, null);
+
+ case TypeClass.STRUCT_value:
+ {
+ // This code exploits the fact that an instantiated polymorphic
+ // struct type may not be the direct base of a struct type:
+ Class superClass = zClass.getSuperclass();
+ TypeDescription[] superTypes = superClass != Object.class
+ ? new TypeDescription[] { get(new Type(superClass)) }
+ : null;
+ // assert !zClass.getName().startsWith("[");
+ return new TypeDescription(
+ typeClass, typeName, "[L" + zClass.getName() + ";", zClass,
+ superTypes, null);
+ }
+
+ case TypeClass.EXCEPTION_value:
+ {
+ TypeDescription[] superTypes
+ = typeName.equals("com.sun.star.uno.Exception")
+ || typeName.equals("com.sun.star.uno.RuntimeException")
+ ? null
+ : new TypeDescription[] {
+ get(new Type(zClass.getSuperclass())) };
+ // assert !zClass.getName().startsWith("[");
+ return new TypeDescription(
+ typeClass, typeName, "[L" + zClass.getName() + ";", zClass,
+ superTypes, null);
+ }
+
+ case TypeClass.INTERFACE_value:
+ {
+ List superTypes = new List();
+ Class[] interfaces = zClass.getInterfaces();
+ for (int i = 0; i < interfaces.length; ++i) {
+ Type t = new Type(interfaces[i]);
+ if (t.getTypeClass() == TypeClass.INTERFACE) {
+ TypeDescription desc = getDefinitely(t);
+ TypeDescription[] descs = desc.superTypes;
+ for (int j = 0; j < descs.length; ++j) {
+ superTypes.add(descs[j]);
+ }
+ superTypes.add(desc);
+ }
+ }
+ // assert !zClass.getName().startsWith("[");
+ return new TypeDescription(
+ typeClass, typeName, "[L" + zClass.getName() + ";", zClass,
+ superTypes.toArray(), null);
+ }
+
+ default:
+ throw new IllegalArgumentException("given type has bad type class");
+ }
+ }
+
+ private TypeDescription(
+ TypeClass typeClass, String typeName, String arrayTypeName,
+ Class zClass, TypeDescription[] superTypes,
+ ITypeDescription componentType)
+ {
+ this.typeClass = typeClass;
+ this.typeName = typeName;
+ this.arrayTypeName = arrayTypeName;
+ this.zClass = zClass;
+ this.superTypes = superTypes;
+ this.componentType = componentType;
+ TypeDescription[] args = calculateTypeArguments();
+ this.hasTypeArguments = args != null;
+ this.fieldDescriptions = calculateFieldDescriptions(args);
+ // methodDescriptions must be initialized lazily, to avoid problems with
+ // circular dependencies (a super-interface that has a sub-interface as
+ // method parameter type; an interface that has a struct as method
+ // parameter type, and the struct has the interface as member type)
+ }
+
+ private synchronized void initMethodDescriptions() {
+ if (methodDescriptions != null || typeClass != TypeClass.INTERFACE) {
+ return;
+ }
+ if (superTypes.length == 0) { // com.sun.star.uno.XInterface
+ superMethodDescriptions = new IMethodDescription[0];
+ methodDescriptions = new IMethodDescription[] {
+ new MethodDescription(
+ "queryInterface", MethodDescription.ID_QUERY_INTERFACE,
+ false, new ITypeDescription[] { getDefinitely(Type.TYPE) },
+ new ITypeDescription[] { null }, getDefinitely(Type.ANY),
+ null),
+ new MethodDescription(
+ "acquire", MethodDescription.ID_ACQUIRE, true,
+ new ITypeDescription[0], new ITypeDescription[0],
+ getDefinitely(Type.VOID), null),
+ new MethodDescription(
+ "release", MethodDescription.ID_RELEASE, true,
+ new ITypeDescription[0], new ITypeDescription[0],
+ getDefinitely(Type.VOID), null) };
+ } else {
+ int methodOffset = 0;
+ ArrayList superList = new ArrayList();
+ for (int i = 0; i < superTypes.length; ++i) {
+ IMethodDescription[] ds = superTypes[i].getMethodDescriptions();
+ for (int j = 0; j < ds.length; ++j) {
+ superList.add(new MethodDescription(ds[j], methodOffset++));
+ }
+ }
+ superMethodDescriptions = (IMethodDescription[]) superList.toArray(
+ new IMethodDescription[superList.size()]);
+ ArrayList directList = new ArrayList();
+ TypeInfo[] infos = getTypeInfo();
+ int infoCount = infos == null ? 0 : infos.length;
+ int index = 0;
+ Method[] methods = zClass.getDeclaredMethods();
+ for (int i = 0; i < infoCount;) {
+ if (infos[i] instanceof AttributeTypeInfo) {
+ AttributeTypeInfo info = (AttributeTypeInfo) infos[i++];
+ if (info.getIndex() != index) {
+ throw new IllegalArgumentException(
+ "Bad UNOTYPEINFO for " + zClass
+ + ": entries not ordererd");
+ }
+ String getterName = "get" + info.getName();
+ Method getter = findMethod(methods, getterName);
+ Type t = info.getUnoType();
+ ITypeDescription type = t == null
+ ? getTypeDescription(getter.getReturnType(), info)
+ : getDefinitely(t);
+ directList.add(
+ new MethodDescription(
+ getterName, index++ + methodOffset, false,
+ new ITypeDescription[0], new ITypeDescription[0],
+ type, getter));
+ if (!info.isReadOnly()) {
+ String setterName = "set" + info.getName();
+ Method setter = findMethod(methods, setterName);
+ directList.add(
+ new MethodDescription(
+ setterName, index++ + methodOffset, false,
+ new ITypeDescription[] { type },
+ new ITypeDescription[] { null },
+ getDefinitely(Type.VOID), setter));
+ }
+ } else {
+ MethodTypeInfo info = (MethodTypeInfo) infos[i++];
+ if (info.getIndex() != index) {
+ throw new IllegalArgumentException(
+ "Bad UNOTYPEINFO for " + zClass
+ + ": entries not ordererd");
+ }
+ Method method = findMethod(methods, info.getName());
+ Class[] params = method.getParameterTypes();
+ ITypeDescription[] in = new ITypeDescription[params.length];
+ ITypeDescription[] out
+ = new ITypeDescription[params.length];
+ for (int j = 0; j < params.length; ++j) {
+ ParameterTypeInfo p = null;
+ if (i < infoCount
+ && infos[i] instanceof ParameterTypeInfo
+ && ((ParameterTypeInfo) infos[i]).getIndex() == j)
+ {
+ p = (ParameterTypeInfo) infos[i++];
+ }
+ Type pt = p == null ? null : p.getUnoType();
+ ITypeDescription d = pt == null
+ ? getTypeDescription(params[j], p)
+ : getDefinitely(pt);
+ if (p == null || p.isIN()) {
+ in[j] = d;
+ }
+ if (p != null && p.isOUT()) {
+ out[j] = d;
+ }
+ }
+ Type t = info.getUnoType();
+ directList.add(
+ new MethodDescription(
+ info.getName(), index++ + methodOffset,
+ info.isOneway(), in, out,
+ (t == null
+ ? getTypeDescription(method.getReturnType(), info)
+ : getDefinitely(t)),
+ method));
+ }
+ }
+ methodDescriptions = (IMethodDescription[]) directList.toArray(
+ new IMethodDescription[directList.size()]);
+ }
+ }
+
+ private TypeDescription[] calculateTypeArguments() {
+ if (typeClass != TypeClass.STRUCT) {
+ return null;
+ }
+ int i = typeName.indexOf('<');
+ if (i < 0) {
+ return null;
+ }
+ java.util.List args = new java.util.ArrayList();
+ do {
+ ++i; // skip '<' or ','
+ int j = i;
+ loop:
+ for (int level = 0; j != typeName.length(); ++j) {
+ switch (typeName.charAt(j)) {
+ case ',':
+ if (level == 0) {
+ break loop;
+ }
+ break;
+
+ case '<':
+ ++level;
+ break;
+
+ case '>':
+ if (level == 0) {
+ break loop;
+ }
+ --level;
+ break;
+ }
+ }
+ if (j != typeName.length()) {
+ Type t = new Type(typeName.substring(i, j));
+ if (t.getZClass() == null) {
+ throw new IllegalArgumentException(
+ "UNO type name \"" + typeName
+ + "\" contains bad type argument \""
+ + typeName.substring(i, j) + "\"");
+ }
+ args.add(getDefinitely(t));
+ }
+ i = j;
+ } while (i != typeName.length() && typeName.charAt(i) != '>');
+ if (i != typeName.length() - 1 || typeName.charAt(i) != '>'
+ || args.isEmpty())
+ {
+ throw new IllegalArgumentException(
+ "UNO type name \"" + typeName + "\" is syntactically invalid");
+ }
+ return (TypeDescription[]) args.toArray(
+ new TypeDescription[args.size()]);
+ }
+
+ private IFieldDescription[] calculateFieldDescriptions(
+ TypeDescription[] typeArguments)
+ {
+ if (typeClass != TypeClass.STRUCT && typeClass != TypeClass.EXCEPTION) {
+ return null;
+ }
+ TypeInfo[] infos = getTypeInfo();
+ int infoCount = infos == null ? 0 : infos.length;
+ ITypeDescription superType = getSuperType();
+ IFieldDescription[] superDescs = superType == null
+ ? null : superType.getFieldDescriptions();
+ int superCount = superDescs == null ? 0 : superDescs.length;
+ IFieldDescription[] descs = new IFieldDescription[
+ superCount + infoCount];
+ if (superCount != 0) {
+ System.arraycopy(superDescs, 0, descs, 0, superCount);
+ }
+ for (int i = 0; i < infoCount; ++i) {
+ MemberTypeInfo info = (MemberTypeInfo) infos[i];
+ if (info.getIndex() != i) {
+ throw new IllegalArgumentException(
+ "Bad UNOTYPEINFO for " + zClass + ": entries not ordererd");
+ }
+ Field field;
+ try {
+ field = zClass.getDeclaredField(info.getName());
+ } catch (NoSuchFieldException e) {
+ throw new IllegalArgumentException(
+ "Bad UNOTYPEINFO for " + zClass + ": " + e);
+ }
+ Type t = info.getUnoType();
+ int index = info.getTypeParameterIndex();
+ descs[i + superCount] = new FieldDescription(
+ info.getName(), i + superCount,
+ (index >= 0
+ ? typeArguments[index]
+ : t == null
+ ? getTypeDescription(field.getType(), info)
+ : getDefinitely(t)),
+ field);
+ }
+ return descs;
+ }
+
+ private TypeInfo[] getTypeInfo() {
+ try {
+ return (TypeInfo[])
+ zClass.getDeclaredField("UNOTYPEINFO").get(null);
+ } catch (NoSuchFieldException e) {
+ return null;
+ } catch (IllegalAccessException e) {
+ throw new IllegalArgumentException(
+ "Bad UNOTYPEINFO for " + zClass + ": " + e);
+ }
+ }
+
+ private Method findMethod(Method[] methods, String name) {
+ for (int i = 0; i < methods.length; ++i) {
+ if (methods[i].getName().equals(name)) {
+ return methods[i];
+ }
+ }
+ throw new IllegalArgumentException(
+ "Bad UNOTYPEINFO for " + zClass + ": no method " + name);
+ }
+
+ private static ITypeDescription getTypeDescription(
+ Class zClass, TypeInfo typeInfo)
+ {
+ return getDefinitely(
+ new Type(
+ zClass,
+ typeInfo != null
+ && (typeInfo.isUnsigned() || typeInfo.isInterface())));
+ }
+
+ private static final class List {
+ public List() {}
+
+ public void add(TypeDescription desc) {
+ if (!list.contains(desc)) {
+ list.add(desc);
+ }
+ }
+
+ public boolean isEmpty() {
+ return list.isEmpty();
+ }
+
+ public TypeDescription[] toArray() {
+ return (TypeDescription[]) list.toArray(
+ new TypeDescription[list.size()]);
+ }
+
+ private final ArrayList list = new ArrayList();
+ }
+
+ private static final class Cache {
+ public Cache() {}
+
+ public TypeDescription get(String typeName) {
+ synchronized (map) {
+ cleanUp();
+ Entry e = (Entry) map.get(typeName);
+ return e == null ? null : (TypeDescription) e.get();
+ }
+ }
+
+ public void put(TypeDescription desc) {
+ synchronized (map) {
+ cleanUp();
+ map.put(desc.getTypeName(), new Entry(desc, queue));
+ }
+ }
+
+ private void cleanUp() {
+ for (;;) {
+ Entry e = (Entry) queue.poll();
+ if (e == null) {
+ break;
+ }
+ map.remove(e.typeName);
+ }
+ }
+
+ private static final class Entry extends SoftReference {
+ public Entry(TypeDescription desc, ReferenceQueue queue) {
+ super(desc, queue);
+ typeName = desc.getTypeName();
+ }
+
+ public final String typeName;
+ }
+
+ private final HashMap map = new HashMap();
+ private final ReferenceQueue queue = new ReferenceQueue();
+ }
+
+ private static final Cache cache = new Cache();
+
+ private final TypeClass typeClass;
+ private final String typeName;
+ private final String arrayTypeName;
+ private final Class zClass;
+ private final TypeDescription[] superTypes;
+ private final ITypeDescription componentType;
+ private final boolean hasTypeArguments;
+ private final IFieldDescription[] fieldDescriptions;
+ private IMethodDescription[] methodDescriptions = null;
+ private IMethodDescription[] superMethodDescriptions;
+}
diff --git a/ridljar/com/sun/star/lib/uno/typeinfo/AttributeTypeInfo.java b/ridljar/com/sun/star/lib/uno/typeinfo/AttributeTypeInfo.java
new file mode 100644
index 000000000000..e0d7bd3cc1e2
--- /dev/null
+++ b/ridljar/com/sun/star/lib/uno/typeinfo/AttributeTypeInfo.java
@@ -0,0 +1,95 @@
+/*************************************************************************
+ *
+ * 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.lib.uno.typeinfo;
+
+import com.sun.star.uno.Type;
+
+public class AttributeTypeInfo extends TypeInfo
+{
+ protected int m_index;
+ private final Type m_unoType; // @since UDK 3.2
+
+ /**
+ Create an attribute type info with a UNO type that cannot unambiguously
+ be represented as a Java&nbsp;1.2 type.
+
+ @param name the name of this attribute; must not be <code>null</code>
+
+ @param index the index among the direct members
+
+ @param flags any flags (<code>READONLY</code>, <code>BOUND</code>,
+ <code>UNSIGNED</code>, <code>ANY</code>, <code>INTERFACE</code>)
+
+ @param unoType the exact UNO type; or <code>null</code> if the UNO type
+ is already unambiguously represented by the Java&nbsp;1.2 type
+
+ @since UDK 3.2
+ */
+ public AttributeTypeInfo(String name, int index, int flags, Type unoType) {
+ super(name, flags);
+ m_index = index;
+ m_unoType = unoType;
+ }
+
+ public AttributeTypeInfo(String name, int index, int flags)
+ {
+ this(name, index, flags, null);
+ }
+
+ public int getIndex()
+ {
+ return m_index;
+ }
+
+ public boolean isReadOnly()
+ {
+ return (m_flags & TypeInfo.READONLY) != 0;
+ }
+
+ /**
+ Returns the status of the 'bound' flag.
+
+ @since UDK 3.2
+ */
+ public final boolean isBound() {
+ return (m_flags & TypeInfo.BOUND) != 0;
+ }
+
+ /**
+ Get the exact UNO type of this attribute type info, in case it cannot
+ unambiguously be represented as a Java&nbsp;1.2 type.
+
+ @return the exact UNO type of this attribute type info, or
+ <code>null</code> if the UNO type is already unambiguously represented by
+ the Java&nbsp;1.2 type
+
+ @since UDK 3.2
+ */
+ public final Type getUnoType() {
+ return m_unoType;
+ }
+}
diff --git a/ridljar/com/sun/star/lib/uno/typeinfo/ConstantTypeInfo.java b/ridljar/com/sun/star/lib/uno/typeinfo/ConstantTypeInfo.java
new file mode 100644
index 000000000000..44f9f9bc371d
--- /dev/null
+++ b/ridljar/com/sun/star/lib/uno/typeinfo/ConstantTypeInfo.java
@@ -0,0 +1,40 @@
+/*************************************************************************
+ *
+ * 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.lib.uno.typeinfo;
+
+/**
+ @deprecated <code>UNOTYPEINFO</code> for constants is not needed
+ */
+public class ConstantTypeInfo extends TypeInfo
+{
+ public ConstantTypeInfo(String name, int flags)
+ {
+ super(name, flags);
+ }
+}
+
+
diff --git a/ridljar/com/sun/star/lib/uno/typeinfo/MemberTypeInfo.java b/ridljar/com/sun/star/lib/uno/typeinfo/MemberTypeInfo.java
new file mode 100644
index 000000000000..384295bb9cad
--- /dev/null
+++ b/ridljar/com/sun/star/lib/uno/typeinfo/MemberTypeInfo.java
@@ -0,0 +1,105 @@
+/*************************************************************************
+ *
+ * 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.lib.uno.typeinfo;
+
+import com.sun.star.uno.Type;
+
+public class MemberTypeInfo extends TypeInfo
+{
+ int m_index;
+ private final Type m_unoType; // @since UDK 3.2
+ private final int m_typeParameterIndex; // @since UDK 3.2
+
+ /**
+ Create a member type info with a UNO type that cannot unambiguously be
+ represented as a Java&nbsp;1.2 type.
+
+ @param name the name of this member; must not be <code>null</code>
+
+ @param index the index among the direct members
+
+ @param flags any flags (<code>UNSIGNED</code>, <code>ANY</code>,
+ <code>INTERFACE</code>, <code>TYPE_PARAMETER</code>)
+
+ @param unoType the exact UNO type; or <code>null</code> if the UNO type
+ is already unambiguously represented by the Java&nbsp;1.2 type
+
+ @param typeParameterIndex the index of the type parameter that determines
+ the type of this parameterized member; or <code>-1</code> if this member
+ is of an explicit type, or is the member of a plain struct type
+
+ @since UDK 3.2
+ */
+ public MemberTypeInfo(
+ String name, int index, int flags, Type unoType, int typeParameterIndex)
+ {
+ super(name, flags);
+ m_index = index;
+ m_unoType = unoType;
+ m_typeParameterIndex = typeParameterIndex;
+ }
+
+ public MemberTypeInfo(String name, int index, int flags )
+ {
+ this(name, index, flags, null, -1);
+ }
+
+ public int getIndex()
+ {
+ return m_index;
+ }
+
+ /**
+ Get the exact UNO type of this member type info, in case it cannot
+ unambiguously be represented as a Java&nbsp;1.2 type.
+
+ @return the exact UNO type of this member type info, or <code>null</code>
+ if the UNO type is already unambiguously represented by the Java&nbsp;1.2
+ type
+
+ @since UDK 3.2
+ */
+ public final Type getUnoType() {
+ return m_unoType;
+ }
+
+ /**
+ Returns the index of the type parameter that determines the parameterized
+ type of this member.
+
+ @return the index of the type parameter that determines the type of this
+ parameterized member; if this member is of an explicit type, or is the
+ member of a plain struct type, <code>-1</code> is returned
+
+ @since UDK 3.2
+ */
+ public final int getTypeParameterIndex() {
+ return m_typeParameterIndex;
+ }
+}
+
+
diff --git a/ridljar/com/sun/star/lib/uno/typeinfo/MethodTypeInfo.java b/ridljar/com/sun/star/lib/uno/typeinfo/MethodTypeInfo.java
new file mode 100644
index 000000000000..4b8ebe65a260
--- /dev/null
+++ b/ridljar/com/sun/star/lib/uno/typeinfo/MethodTypeInfo.java
@@ -0,0 +1,98 @@
+/*************************************************************************
+ *
+ * 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.lib.uno.typeinfo;
+
+import com.sun.star.uno.Type;
+
+public class MethodTypeInfo extends TypeInfo
+{
+ protected int m_index;
+ private final Type m_unoType; // @since UDK 3.2
+
+ /**
+ Create a method type info with a UNO return type that cannot
+ unambiguously be represented as a Java&nbsp;1.2 type.
+
+ @param name the name of this method; must not be <code>null</code>
+
+ @param index the index among the direct members
+
+ @param flags any flags (<code>ONEWAY</code>, <code>UNSIGNED</code>,
+ <code>ANY</code>, <code>INTERFACE</code>)
+
+ @param unoType the exact UNO return type; or <code>null</code> if the UNO
+ type is already unambiguously represented by the Java&nbsp;1.2 type
+
+ @since UDK 3.2
+ */
+ public MethodTypeInfo(String name, int index, int flags, Type unoType) {
+ super(name, flags);
+ m_index = index;
+ m_unoType = unoType;
+ }
+
+ public MethodTypeInfo(String name, int index, int flags)
+ {
+ this(name, index, flags, null);
+ }
+
+ public int getIndex()
+ {
+ return m_index;
+ }
+
+ public boolean isReturnUnsigned()
+ {
+ return isUnsigned();
+ }
+
+ public boolean isOneway()
+ {
+ return (m_flags & TypeInfo.ONEWAY) != 0;
+ }
+
+ public boolean isConst()
+ {
+ return (m_flags & TypeInfo.CONST) != 0;
+ }
+
+ /**
+ Get the exact UNO return type of this method type info, in case it cannot
+ unambiguously be represented as a Java&nbsp;1.2 type.
+
+ @return the exact UNO return type of this method type info, or
+ <code>null</code> if the UNO type is already unambiguously represented by
+ the Java&nbsp;1.2 type
+
+ @since UDK 3.2
+ */
+ public final Type getUnoType() {
+ return m_unoType;
+ }
+}
+
+
diff --git a/ridljar/com/sun/star/lib/uno/typeinfo/ParameterTypeInfo.java b/ridljar/com/sun/star/lib/uno/typeinfo/ParameterTypeInfo.java
new file mode 100644
index 000000000000..3aecce7a6891
--- /dev/null
+++ b/ridljar/com/sun/star/lib/uno/typeinfo/ParameterTypeInfo.java
@@ -0,0 +1,114 @@
+/*************************************************************************
+ *
+ * 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.lib.uno.typeinfo;
+
+import com.sun.star.uno.Type;
+
+public class ParameterTypeInfo extends TypeInfo
+{
+ protected int m_index;
+ protected String m_methodName;
+ private final Type m_unoType; // @since UDK 3.2
+
+ /**
+ Create a parameter type info with a UNO type that cannot unambiguously be
+ represented as a Java&nbsp;1.2 type.
+
+ @param name the name of this parameter; must not be <code>null</code>
+
+ @param methodName the name of the method; must not be <code>null</code>
+
+ @param index the index among the parameters
+
+ @param flags any flags (<code>IN</code>, <code>OUT</code>,
+ <code>UNSIGNED</code>, <code>ANY</code>, <code>INTERFACE</code>)
+
+ @param unoType the exact UNO type; or <code>null</code> if the UNO type
+ is already unambiguously represented by the Java&nbsp;1.2 type
+
+ @since UDK 3.2
+ */
+ public ParameterTypeInfo(
+ String name, String methodName, int index, int flags, Type unoType)
+ {
+ super(name, flags);
+ m_index = index;
+ m_methodName = methodName;
+ m_unoType = unoType;
+ }
+
+ public ParameterTypeInfo(String name, String methodName, int index, int flags)
+ {
+ this(name, methodName, index, flags, null);
+ }
+
+ public String getMethodName()
+ {
+ return m_methodName;
+ }
+
+ public int getIndex()
+ {
+ return m_index;
+ }
+
+ public boolean isIN()
+ {
+ return ((m_flags & TypeInfo.IN) != 0 ||
+ (m_flags & (TypeInfo.IN | TypeInfo.OUT)) == 0); // nothing set => IN
+ }
+
+ public boolean isOUT()
+ {
+ return (m_flags & TypeInfo.OUT) != 0;
+ }
+
+ public boolean isINOUT()
+ {
+ return (m_flags & (TypeInfo.IN | TypeInfo.OUT)) == (TypeInfo.IN | TypeInfo.OUT);
+ }
+
+ /**
+ Get the exact UNO type of this parameter type info, in case it cannot
+ unambiguously be represented as a Java&nbsp;1.2 type.
+
+ <p>If this is an out or in&ndash;out parameter, the UNO type must be a
+ sequence type, taking into account that such a parameter is represented
+ in Java as a parameter of array type.</p>
+
+ @return the exact UNO type of this parameter type info, or
+ <code>null</code> if the UNO type is already unambiguously represented by
+ the Java&nbsp;1.2 type
+
+ @since UDK 3.2
+ */
+ public final Type getUnoType() {
+ return m_unoType;
+ }
+}
+
+
diff --git a/ridljar/com/sun/star/lib/uno/typeinfo/TypeInfo.java b/ridljar/com/sun/star/lib/uno/typeinfo/TypeInfo.java
new file mode 100644
index 000000000000..40745df56b44
--- /dev/null
+++ b/ridljar/com/sun/star/lib/uno/typeinfo/TypeInfo.java
@@ -0,0 +1,85 @@
+/*************************************************************************
+ *
+ * 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.lib.uno.typeinfo;
+
+
+/** Defines a class to describe additional type information.
+ */
+public class TypeInfo
+{
+ public static final int IN = 0x00000001;
+ public static final int OUT = 0x00000002;
+ public static final int UNSIGNED = 0x00000004;
+ public static final int READONLY = 0x00000008;
+ public static final int ONEWAY = 0x00000010;
+ public static final int CONST = 0x00000020;
+ public static final int ANY = 0x00000040;
+ public static final int INTERFACE = 0x00000080;
+
+ /**
+ Marks an extended attribute of an interface type as bound.
+
+ <p>Only used in the <code>flags</code> argument of the
+ <code>AttributeTypeInfo</code> constructors.</p>
+
+ @since UDK 3.2
+ */
+ public static final int BOUND = 0x00000100;
+
+ protected int m_flags;
+ protected String m_name;
+
+ public TypeInfo(String name, int flags)
+ {
+ m_name = name;
+ m_flags = flags;
+ }
+
+ public String getName()
+ {
+ return m_name;
+ }
+
+ public int getFlags() {
+ return m_flags;
+ }
+
+ public boolean isUnsigned()
+ {
+ return (m_flags & TypeInfo.UNSIGNED) != 0;
+ }
+
+ public boolean isAny()
+ {
+ return (m_flags & TypeInfo.ANY) != 0;
+ }
+
+ public boolean isInterface()
+ {
+ return (m_flags & TypeInfo.INTERFACE) != 0;
+ }
+}
diff --git a/ridljar/com/sun/star/lib/util/DisposeListener.java b/ridljar/com/sun/star/lib/util/DisposeListener.java
new file mode 100644
index 000000000000..a53834148708
--- /dev/null
+++ b/ridljar/com/sun/star/lib/util/DisposeListener.java
@@ -0,0 +1,43 @@
+/*************************************************************************
+ *
+ * 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.lib.util;
+
+/**
+ * Counterpart to <code>DisposeNotifier</code>.
+ *
+ * @see DisposeNotifier
+ */
+public interface DisposeListener {
+ /**
+ * Callback fired by a <code>DisposeNotifier</code> once it is disposed.
+ *
+ * @param source the <code>DisposeNotifer</code> that fires the callback;
+ * will never be <code>null</code>
+ */
+ void notifyDispose(DisposeNotifier source);
+}
diff --git a/ridljar/com/sun/star/lib/util/DisposeNotifier.java b/ridljar/com/sun/star/lib/util/DisposeNotifier.java
new file mode 100644
index 000000000000..7ef8bf740d01
--- /dev/null
+++ b/ridljar/com/sun/star/lib/util/DisposeNotifier.java
@@ -0,0 +1,53 @@
+/*************************************************************************
+ *
+ * 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.lib.util;
+
+/**
+ * Optional interface to be implemented by objects stored in a
+ * <code>WeakMap</code>.
+ *
+ * @see WeakMap
+ */
+public interface DisposeNotifier {
+ /**
+ * Adds a dispose listener, to be notified when this object is disposed.
+ *
+ * <p>It is unspecified what happens when the same listener is added
+ * multiple times.</p>
+ *
+ * <p>It is unspecified exactly when the <code>notifyDispose</code> callback
+ * is fired: immediately before the notifier is disposed, while it is in the
+ * process of disposing, or some time after it got disposed. But even if
+ * adding a listener to an already disposed notifer, the listener must
+ * eventually receive a <code>notifyDispose</code> callback.</p>
+ *
+ * @param listener a dispose listener, to be notified when this object is
+ * disposed; must not be <code>null</code>
+ */
+ void addDisposeListener(DisposeListener listener);
+}
diff --git a/ridljar/com/sun/star/lib/util/WeakMap.java b/ridljar/com/sun/star/lib/util/WeakMap.java
new file mode 100644
index 000000000000..7c2ccde1ded1
--- /dev/null
+++ b/ridljar/com/sun/star/lib/util/WeakMap.java
@@ -0,0 +1,311 @@
+/*************************************************************************
+ *
+ * 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.lib.util;
+
+import java.lang.ref.ReferenceQueue;
+import java.lang.ref.WeakReference;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * A hash map that holds values of type <code>WeakReference</code>.
+ *
+ * <p>Like <code>HashMap</code>, this implementation provides all of the
+ * optional map operations, and permits the <code>null</code> key.</p>
+ *
+ * <p>Also like <code>HashMap</code>, this implementation is not synchronized.
+ * If multiple threads share an instance, and at least one of them executes any
+ * modifying operations on the <code>WeakMap</code>, they have to use external
+ * synchronization.</p>
+ *
+ * <p>Unlike other map implementations, <code>WeakMap</code> is asymmetric in
+ * that <code>put</code> expects the given value to be a plain object that is
+ * then wrapped in a <code>WeakReference</code>, while the occurences of values
+ * in all other methods (<code>containsValue</code>, <code>entrySet</code>,
+ * <code>equals</code>, <code>get</code>, <code>hashCode</code>,
+ * <code>remove</code>, <code>values</code>, and also the return value of
+ * <code>put</code>) expect already wrapped instances of
+ * <code>WeakReference</code>. That is, after <code>weakMap.put("key",
+ * o)</code>, <code>weakMap.get("key").equals(o)</code> does not work as
+ * na&iuml;vely expected; neither does
+ * <code>weakMap1.putAll(weakMap2)</code>.</p>
+ *
+ * <p>At an arbitrary time after the <code>WeakReference</code> value of an
+ * entry has been cleared by the garbage collector, the entry is automatically
+ * removed from the map.</p>
+ *
+ * <p>Values placed into a <code>WeakMap</code> may optionally support the
+ * <code>DisposeNotifier</code> interface. For those that do, the associated
+ * <code>WeakReference</code> wrappers are automatically cleared as soon as the
+ * values are disposed.</p>
+ */
+public final class WeakMap implements Map {
+ /**
+ * Constructs an empty <code>WeakMap</code>.
+ */
+ public WeakMap() {}
+
+ /**
+ * Constructs a new <code>WeakMap</code> with the same mappings as the
+ * specified <code>Map</code>.
+ *
+ * @param m the map whose mappings are to be placed in this map
+ */
+ public WeakMap(Map m) {
+ putAll(m);
+ }
+
+ /**
+ * Returns the number of key&ndash;value mappings in this map.
+ *
+ * <p>This is a non-modifying operation.</p>
+ *
+ * @return the number of key&ndash;value mappings in this map
+ */
+ public int size() {
+ return map.size();
+ }
+
+ /**
+ * Returns <code>true</code> if this map contains no key&ndash;value
+ * mappings.
+ *
+ * <p>This is a non-modifying operation.</p>
+ *
+ * @return <code>true</code> if this map contains no key&ndash;value
+ * mappings
+ */
+ public boolean isEmpty() {
+ return map.isEmpty();
+ }
+
+ /**
+ * Returns <code>true</code> if this map contains a mapping for the
+ * specified key.
+ *
+ * <p>This is a non-modifying operation.</p>
+ *
+ * @param key the key whose presence in this map is to be tested
+ * @return <code>true</code> if this map contains a mapping for the
+ * specified key
+ */
+ public boolean containsKey(Object key) {
+ return map.containsKey(key);
+ }
+
+ /**
+ * Returns <code>true</code> if this map maps one or more keys to the
+ * specified value.
+ *
+ * <p>This is a non-modifying operation.</p>
+ *
+ * @param value the value whose presence in this map is to be tested
+ * @return <code>true</code> if this map maps one or more keys to the
+ * specified value
+ */
+ public boolean containsValue(Object value) {
+ return map.containsValue(value);
+ }
+
+ /**
+ * Returns the value to which the specified key is mapped in this map, or
+ * <code>null</code> if the map contains no mapping for this key.
+ *
+ * <p>This is a non-modifying operation.</p>
+ *
+ * @param key the key whose associated value is to be returned
+ *
+ * @return the value to which this map maps the specified key, or
+ * <code>null</code> if the map contains no mapping for this key
+ */
+ public Object get(Object key) {
+ return map.get(key);
+ }
+
+ /**
+ * Associates the specified value with the specified key in this map.
+ *
+ * <p>This is a modifying operation.</p>
+ *
+ * @param key the key with witch the specified value is to be associated
+ * @param value the value to be associated with the specified key. This
+ * must be a plain object, which is then wrapped in a
+ * <code>WeakReference</code>.
+ * @return previous value associated with the specified key, or
+ * <code>null</code> if there was no mapping for the key
+ */
+ public Object put(Object key, Object value) {
+ cleanUp();
+ return map.put(key, new Entry(key, value, queue));
+ }
+
+ /**
+ * Removes the mapping for this key from this map if present.
+ *
+ * <p>This is a modifying operation.</p>
+ *
+ * @param key the key whose mapping is to be removed from the map
+ * @return previous value associated with the specified key, or
+ * <code>null</code> if there was no mapping for the key
+ */
+ public Object remove(Object key) {
+ cleanUp();
+ return map.remove(key);
+ }
+
+ /**
+ * Copies all of the mappings from the specified map to this map.
+ *
+ * <p>This is a modifying operation.</p>
+ *
+ * @param m mappings to be stored in this map. The values of those mappings
+ * must be plain objects, which are then wrapped in instances of
+ * <code>WeakReference</code>.
+ */
+ public void putAll(Map t) {
+ cleanUp();
+ for (Iterator i = t.entrySet().iterator(); i.hasNext();) {
+ Map.Entry e = (Map.Entry) i.next();
+ Object k = e.getKey();
+ map.put(k, new Entry(k, e.getValue(), queue));
+ }
+ }
+
+ /**
+ * Removes all mappings from this map.
+ *
+ * <p>This is a modifying operation.</p>
+ */
+ public void clear() {
+ cleanUp();
+ map.clear();
+ }
+
+ /**
+ * Returns a view of the keys contained in this map.
+ *
+ * <p>This is a non-modifying operation.</p>
+ *
+ * @return a set view of the keys contained in this map
+ */
+ public Set keySet() {
+ return map.keySet();
+ }
+
+ /**
+ * Returns a collection view of the values contained in this map.
+ *
+ * <p>This is a non-modifying operation.</p>
+ *
+ * @return a collection view of the values contained in this map
+ */
+ public Collection values() {
+ return map.values();
+ }
+
+ /**
+ * Returns a collection view of the mappings contained in this map.
+ *
+ * <p>This is a non-modifying operation.</p>
+ *
+ * @return a collection view of the mappings contained in this map
+ */
+ public Set entrySet() {
+ return map.entrySet();
+ }
+
+ public boolean equals(Object o) {
+ return map.equals(o);
+ }
+
+ public int hashCode() {
+ return map.hashCode();
+ }
+
+ /**
+ * Returns the referent of a <code>WeakReference</code>, silently handling a
+ * <code>null</code> argument.
+ *
+ * <p>This static method is useful to wrap around the return values of
+ * methods like <code>get</code>.</p>
+ *
+ * @param ref must be either an instance of <code>WeakReference</code> or
+ * <code>null</code>
+ * @return the referent of the specified <code>WeakReference</code>, or
+ * <code>null</code> if <code>ref</code> is <code>null</code>
+ */
+ public static Object getValue(Object ref) {
+ return ref == null ? null : ((WeakReference) ref).get();
+ }
+
+ // cleanUp must only be called from within modifying methods. Otherwise,
+ // the implementations of entrySet, keySet and values would break
+ // (specificially, iterating over the collections returned by those
+ // methods), as non-modifying methods might modify the underlying map.
+ private void cleanUp() {
+ for (;;) {
+ Entry e = (Entry) queue.poll();
+ if (e == null) {
+ break;
+ }
+ // It is possible that an Entry e1 becomes weakly reachable, then
+ // another Entry e2 is added to the map for the same key, and only
+ // then e1 is enqueued. To not erroneously remove the new e2 in
+ // that case, check whether the map still contains e1:
+ Object k = e.key;
+ if (e == map.get(k)) {
+ map.remove(k);
+ }
+ }
+ }
+
+ private static final class Entry extends WeakReference
+ implements DisposeListener
+ {
+ public void notifyDispose(DisposeNotifier source) {
+ Entry.this.clear(); // qualification needed for Java 1.3
+ enqueue();
+ }
+
+ private Entry(Object key, Object value, ReferenceQueue queue) {
+ super(value, queue);
+ this.key = key;
+ if (value instanceof DisposeNotifier) {
+ ((DisposeNotifier) value).addDisposeListener(this);
+ }
+ }
+
+ private final Object key;
+ }
+
+ private final HashMap map = new HashMap();
+ private final ReferenceQueue queue = new ReferenceQueue();
+}