Kaydet (Commit) 4418ad03 authored tarafından Noel Grandin's avatar Noel Grandin Kaydeden (comit) Michael Stahl

Java5 update - convert code to use generics

Note that WeakMap no longer extends Map, because it does not conform
to the generic Map interface.

Change-Id: I72ea681528c932d84c95f095434e1dc95b0a3d16
üst 30d4c3c7
...@@ -55,7 +55,7 @@ public final class TypeDescription implements ITypeDescription { ...@@ -55,7 +55,7 @@ public final class TypeDescription implements ITypeDescription {
return get(t); return get(t);
} }
public static TypeDescription getTypeDescription(Class zClass) { public static TypeDescription getTypeDescription(Class<?> zClass) {
return getDefinitely(new Type(zClass)); return getDefinitely(new Type(zClass));
} }
...@@ -206,7 +206,7 @@ public final class TypeDescription implements ITypeDescription { ...@@ -206,7 +206,7 @@ public final class TypeDescription implements ITypeDescription {
} }
// @see ITypeDescription#getZClass // @see ITypeDescription#getZClass
public Class getZClass() { public Class<?> getZClass() {
return zClass; return zClass;
} }
...@@ -244,7 +244,7 @@ public final class TypeDescription implements ITypeDescription { ...@@ -244,7 +244,7 @@ public final class TypeDescription implements ITypeDescription {
{ {
TypeClass typeClass = type.getTypeClass(); TypeClass typeClass = type.getTypeClass();
String typeName = type.getTypeName(); String typeName = type.getTypeName();
Class zClass = type.getZClass(); Class<?> zClass = type.getZClass();
if (zClass == null) { if (zClass == null) {
throw new ClassNotFoundException("UNO type " + type); throw new ClassNotFoundException("UNO type " + type);
} }
...@@ -322,7 +322,7 @@ public final class TypeDescription implements ITypeDescription { ...@@ -322,7 +322,7 @@ public final class TypeDescription implements ITypeDescription {
{ {
// This code exploits the fact that an instantiated polymorphic // This code exploits the fact that an instantiated polymorphic
// struct type may not be the direct base of a struct type: // struct type may not be the direct base of a struct type:
Class superClass = zClass.getSuperclass(); Class<?> superClass = zClass.getSuperclass();
TypeDescription[] superTypes = superClass != Object.class TypeDescription[] superTypes = superClass != Object.class
? new TypeDescription[] { get(new Type(superClass)) } ? new TypeDescription[] { get(new Type(superClass)) }
: null; : null;
...@@ -349,7 +349,7 @@ public final class TypeDescription implements ITypeDescription { ...@@ -349,7 +349,7 @@ public final class TypeDescription implements ITypeDescription {
case TypeClass.INTERFACE_value: case TypeClass.INTERFACE_value:
{ {
List superTypes = new List(); List superTypes = new List();
Class[] interfaces = zClass.getInterfaces(); Class<?>[] interfaces = zClass.getInterfaces();
for (int i = 0; i < interfaces.length; ++i) { for (int i = 0; i < interfaces.length; ++i) {
Type t = new Type(interfaces[i]); Type t = new Type(interfaces[i]);
if (t.getTypeClass() == TypeClass.INTERFACE) { if (t.getTypeClass() == TypeClass.INTERFACE) {
...@@ -374,7 +374,7 @@ public final class TypeDescription implements ITypeDescription { ...@@ -374,7 +374,7 @@ public final class TypeDescription implements ITypeDescription {
private TypeDescription( private TypeDescription(
TypeClass typeClass, String typeName, String arrayTypeName, TypeClass typeClass, String typeName, String arrayTypeName,
Class zClass, TypeDescription[] superTypes, Class<?> zClass, TypeDescription[] superTypes,
ITypeDescription componentType) ITypeDescription componentType)
{ {
this.typeClass = typeClass; this.typeClass = typeClass;
...@@ -414,16 +414,16 @@ public final class TypeDescription implements ITypeDescription { ...@@ -414,16 +414,16 @@ public final class TypeDescription implements ITypeDescription {
getDefinitely(Type.VOID), null) }; getDefinitely(Type.VOID), null) };
} else { } else {
int methodOffset = 0; int methodOffset = 0;
ArrayList superList = new ArrayList(); ArrayList<MethodDescription> superList = new ArrayList<MethodDescription>();
for (int i = 0; i < superTypes.length; ++i) { for (int i = 0; i < superTypes.length; ++i) {
IMethodDescription[] ds = superTypes[i].getMethodDescriptions(); IMethodDescription[] ds = superTypes[i].getMethodDescriptions();
for (int j = 0; j < ds.length; ++j) { for (int j = 0; j < ds.length; ++j) {
superList.add(new MethodDescription(ds[j], methodOffset++)); superList.add(new MethodDescription(ds[j], methodOffset++));
} }
} }
superMethodDescriptions = (IMethodDescription[]) superList.toArray( superMethodDescriptions = superList.toArray(
new IMethodDescription[superList.size()]); new IMethodDescription[superList.size()]);
ArrayList directList = new ArrayList(); ArrayList<MethodDescription> directList = new ArrayList<MethodDescription>();
TypeInfo[] infos = getTypeInfo(); TypeInfo[] infos = getTypeInfo();
int infoCount = infos == null ? 0 : infos.length; int infoCount = infos == null ? 0 : infos.length;
int index = 0; int index = 0;
...@@ -465,7 +465,7 @@ public final class TypeDescription implements ITypeDescription { ...@@ -465,7 +465,7 @@ public final class TypeDescription implements ITypeDescription {
+ ": entries not ordererd"); + ": entries not ordererd");
} }
Method method = findMethod(methods, info.getName()); Method method = findMethod(methods, info.getName());
Class[] params = method.getParameterTypes(); Class<?>[] params = method.getParameterTypes();
ITypeDescription[] in = new ITypeDescription[params.length]; ITypeDescription[] in = new ITypeDescription[params.length];
ITypeDescription[] out ITypeDescription[] out
= new ITypeDescription[params.length]; = new ITypeDescription[params.length];
...@@ -499,7 +499,7 @@ public final class TypeDescription implements ITypeDescription { ...@@ -499,7 +499,7 @@ public final class TypeDescription implements ITypeDescription {
method)); method));
} }
} }
methodDescriptions = (IMethodDescription[]) directList.toArray( methodDescriptions = directList.toArray(
new IMethodDescription[directList.size()]); new IMethodDescription[directList.size()]);
} }
} }
...@@ -512,7 +512,7 @@ public final class TypeDescription implements ITypeDescription { ...@@ -512,7 +512,7 @@ public final class TypeDescription implements ITypeDescription {
if (i < 0) { if (i < 0) {
return null; return null;
} }
java.util.List args = new java.util.ArrayList(); java.util.List<TypeDescription> args = new java.util.ArrayList<TypeDescription>();
do { do {
++i; // skip '<' or ',' ++i; // skip '<' or ','
int j = i; int j = i;
...@@ -555,7 +555,7 @@ public final class TypeDescription implements ITypeDescription { ...@@ -555,7 +555,7 @@ public final class TypeDescription implements ITypeDescription {
throw new IllegalArgumentException( throw new IllegalArgumentException(
"UNO type name \"" + typeName + "\" is syntactically invalid"); "UNO type name \"" + typeName + "\" is syntactically invalid");
} }
return (TypeDescription[]) args.toArray( return args.toArray(
new TypeDescription[args.size()]); new TypeDescription[args.size()]);
} }
...@@ -626,7 +626,7 @@ public final class TypeDescription implements ITypeDescription { ...@@ -626,7 +626,7 @@ public final class TypeDescription implements ITypeDescription {
} }
private static ITypeDescription getTypeDescription( private static ITypeDescription getTypeDescription(
Class zClass, TypeInfo typeInfo) Class<?> zClass, TypeInfo typeInfo)
{ {
return getDefinitely( return getDefinitely(
new Type( new Type(
...@@ -649,11 +649,11 @@ public final class TypeDescription implements ITypeDescription { ...@@ -649,11 +649,11 @@ public final class TypeDescription implements ITypeDescription {
} }
public TypeDescription[] toArray() { public TypeDescription[] toArray() {
return (TypeDescription[]) list.toArray( return list.toArray(
new TypeDescription[list.size()]); new TypeDescription[list.size()]);
} }
private final ArrayList list = new ArrayList(); private final ArrayList<TypeDescription> list = new ArrayList<TypeDescription>();
} }
private static final class Cache { private static final class Cache {
...@@ -662,7 +662,7 @@ public final class TypeDescription implements ITypeDescription { ...@@ -662,7 +662,7 @@ public final class TypeDescription implements ITypeDescription {
public TypeDescription get(String typeName) { public TypeDescription get(String typeName) {
synchronized (map) { synchronized (map) {
cleanUp(); cleanUp();
Entry e = (Entry) map.get(typeName); Entry e = map.get(typeName);
return e == null ? null : (TypeDescription) e.get(); return e == null ? null : (TypeDescription) e.get();
} }
} }
...@@ -684,8 +684,8 @@ public final class TypeDescription implements ITypeDescription { ...@@ -684,8 +684,8 @@ public final class TypeDescription implements ITypeDescription {
} }
} }
private static final class Entry extends SoftReference { private static final class Entry extends SoftReference<TypeDescription> {
public Entry(TypeDescription desc, ReferenceQueue queue) { public Entry(TypeDescription desc, ReferenceQueue<TypeDescription> queue) {
super(desc, queue); super(desc, queue);
typeName = desc.getTypeName(); typeName = desc.getTypeName();
} }
...@@ -693,8 +693,8 @@ public final class TypeDescription implements ITypeDescription { ...@@ -693,8 +693,8 @@ public final class TypeDescription implements ITypeDescription {
public final String typeName; public final String typeName;
} }
private final HashMap map = new HashMap(); private final HashMap<String, Entry> map = new HashMap<String, Entry>();
private final ReferenceQueue queue = new ReferenceQueue(); private final ReferenceQueue<TypeDescription> queue = new ReferenceQueue<TypeDescription>();
} }
private static final Cache cache = new Cache(); private static final Cache cache = new Cache();
...@@ -702,7 +702,7 @@ public final class TypeDescription implements ITypeDescription { ...@@ -702,7 +702,7 @@ public final class TypeDescription implements ITypeDescription {
private final TypeClass typeClass; private final TypeClass typeClass;
private final String typeName; private final String typeName;
private final String arrayTypeName; private final String arrayTypeName;
private final Class zClass; private final Class<?> zClass;
private final TypeDescription[] superTypes; private final TypeDescription[] superTypes;
private final ITypeDescription componentType; private final ITypeDescription componentType;
private final boolean hasTypeArguments; private final boolean hasTypeArguments;
......
...@@ -58,7 +58,15 @@ import java.util.Set; ...@@ -58,7 +58,15 @@ import java.util.Set;
* <code>WeakReference</code> wrappers are automatically cleared as soon as the * <code>WeakReference</code> wrappers are automatically cleared as soon as the
* values are disposed.</p> * values are disposed.</p>
*/ */
public final class WeakMap implements Map { public final class WeakMap<K,V> {
/**
* Declare the map as WeakReference instead of Entry because it makes the return
* type signatures of values() and keySet() cleaner.
*/
private final HashMap<K, WeakReference<V>> map = new HashMap<K, WeakReference<V>>();
private final ReferenceQueue<V> queue = new ReferenceQueue<V>();
/** /**
* Constructs an empty <code>WeakMap</code>. * Constructs an empty <code>WeakMap</code>.
*/ */
...@@ -70,7 +78,7 @@ public final class WeakMap implements Map { ...@@ -70,7 +78,7 @@ public final class WeakMap implements Map {
* *
* @param m the map whose mappings are to be placed in this map * @param m the map whose mappings are to be placed in this map
*/ */
public WeakMap(Map m) { public WeakMap(Map<K,V> m) {
putAll(m); putAll(m);
} }
...@@ -108,7 +116,7 @@ public final class WeakMap implements Map { ...@@ -108,7 +116,7 @@ public final class WeakMap implements Map {
* @return <code>true</code> if this map contains a mapping for the * @return <code>true</code> if this map contains a mapping for the
* specified key * specified key
*/ */
public boolean containsKey(Object key) { public boolean containsKey(K key) {
return map.containsKey(key); return map.containsKey(key);
} }
...@@ -122,7 +130,7 @@ public final class WeakMap implements Map { ...@@ -122,7 +130,7 @@ public final class WeakMap implements Map {
* @return <code>true</code> if this map maps one or more keys to the * @return <code>true</code> if this map maps one or more keys to the
* specified value * specified value
*/ */
public boolean containsValue(Object value) { public boolean containsValue(WeakReference<V> value) {
return map.containsValue(value); return map.containsValue(value);
} }
...@@ -137,7 +145,7 @@ public final class WeakMap implements Map { ...@@ -137,7 +145,7 @@ public final class WeakMap implements Map {
* @return the value to which this map maps the specified key, or * @return the value to which this map maps the specified key, or
* <code>null</code> if the map contains no mapping for this key * <code>null</code> if the map contains no mapping for this key
*/ */
public Object get(Object key) { public WeakReference<V> get(K key) {
return map.get(key); return map.get(key);
} }
...@@ -153,9 +161,9 @@ public final class WeakMap implements Map { ...@@ -153,9 +161,9 @@ public final class WeakMap implements Map {
* @return previous value associated with the specified key, or * @return previous value associated with the specified key, or
* <code>null</code> if there was no mapping for the key * <code>null</code> if there was no mapping for the key
*/ */
public Object put(Object key, Object value) { public WeakReference<V> put(K key, V value) {
cleanUp(); cleanUp();
return map.put(key, new Entry(key, value, queue)); return map.put(key, new Entry<K,V>(key, value, queue));
} }
/** /**
...@@ -167,7 +175,7 @@ public final class WeakMap implements Map { ...@@ -167,7 +175,7 @@ public final class WeakMap implements Map {
* @return previous value associated with the specified key, or * @return previous value associated with the specified key, or
* <code>null</code> if there was no mapping for the key * <code>null</code> if there was no mapping for the key
*/ */
public Object remove(Object key) { public WeakReference<V> remove(K key) {
cleanUp(); cleanUp();
return map.remove(key); return map.remove(key);
} }
...@@ -181,12 +189,12 @@ public final class WeakMap implements Map { ...@@ -181,12 +189,12 @@ public final class WeakMap implements Map {
* must be plain objects, which are then wrapped in instances of * must be plain objects, which are then wrapped in instances of
* <code>WeakReference</code>. * <code>WeakReference</code>.
*/ */
public void putAll(Map t) { public void putAll(Map<K,V> m) {
cleanUp(); cleanUp();
for (Iterator i = t.entrySet().iterator(); i.hasNext();) { for (Iterator<Map.Entry<K,V>> i = m.entrySet().iterator(); i.hasNext();) {
Map.Entry e = (Map.Entry) i.next(); Map.Entry<K,V> e = i.next();
Object k = e.getKey(); K k = e.getKey();
map.put(k, new Entry(k, e.getValue(), queue)); map.put(k, new Entry<K,V>(k, e.getValue(), queue));
} }
} }
...@@ -207,7 +215,7 @@ public final class WeakMap implements Map { ...@@ -207,7 +215,7 @@ public final class WeakMap implements Map {
* *
* @return a set view of the keys contained in this map * @return a set view of the keys contained in this map
*/ */
public Set keySet() { public Set<K> keySet() {
return map.keySet(); return map.keySet();
} }
...@@ -218,7 +226,7 @@ public final class WeakMap implements Map { ...@@ -218,7 +226,7 @@ public final class WeakMap implements Map {
* *
* @return a collection view of the values contained in this map * @return a collection view of the values contained in this map
*/ */
public Collection values() { public Collection<WeakReference<V>> values() {
return map.values(); return map.values();
} }
...@@ -229,7 +237,7 @@ public final class WeakMap implements Map { ...@@ -229,7 +237,7 @@ public final class WeakMap implements Map {
* *
* @return a collection view of the mappings contained in this map * @return a collection view of the mappings contained in this map
*/ */
public Set entrySet() { public Set<Map.Entry<K,WeakReference<V>>> entrySet() {
return map.entrySet(); return map.entrySet();
} }
...@@ -253,17 +261,20 @@ public final class WeakMap implements Map { ...@@ -253,17 +261,20 @@ public final class WeakMap implements Map {
* @return the referent of the specified <code>WeakReference</code>, or * @return the referent of the specified <code>WeakReference</code>, or
* <code>null</code> if <code>ref</code> is <code>null</code> * <code>null</code> if <code>ref</code> is <code>null</code>
*/ */
public static Object getValue(Object ref) { public static <T> T getValue(WeakReference<T> ref) {
return ref == null ? null : ((WeakReference) ref).get(); return ref == null ? null : ref.get();
} }
// cleanUp must only be called from within modifying methods. Otherwise, /**
// the implementations of entrySet, keySet and values would break * cleanUp() must only be called from within modifying methods. Otherwise,
// (specificially, iterating over the collections returned by those * the implementations of entrySet, keySet and values would break
// methods), as non-modifying methods might modify the underlying map. * (Specifically, iterating over the collections returned by those
* methods), as non-modifying methods might modify the underlying map.
**/
@SuppressWarnings("unchecked")
private void cleanUp() { private void cleanUp() {
for (;;) { for (;;) {
Entry e = (Entry) queue.poll(); Entry<K,V> e = (Entry<K,V>) queue.poll();
if (e == null) { if (e == null) {
break; break;
} }
...@@ -278,15 +289,12 @@ public final class WeakMap implements Map { ...@@ -278,15 +289,12 @@ public final class WeakMap implements Map {
} }
} }
private static final class Entry extends WeakReference private static final class Entry<K,V> extends WeakReference<V>
implements DisposeListener implements DisposeListener
{ {
public void notifyDispose(DisposeNotifier source) { private final K key;
Entry.this.clear(); // qualification needed for Java 1.3
enqueue();
}
private Entry(Object key, Object value, ReferenceQueue queue) { private Entry(K key, V value, ReferenceQueue<V> queue) {
super(value, queue); super(value, queue);
this.key = key; this.key = key;
if (value instanceof DisposeNotifier) { if (value instanceof DisposeNotifier) {
...@@ -294,9 +302,13 @@ public final class WeakMap implements Map { ...@@ -294,9 +302,13 @@ public final class WeakMap implements Map {
} }
} }
private final Object key; /**
* @see DisposeListener#notifyDispose(DisposeNotifier)
*/
public void notifyDispose(DisposeNotifier source) {
clear();
enqueue();
}
} }
private final HashMap map = new HashMap();
private final ReferenceQueue queue = new ReferenceQueue();
} }
...@@ -57,7 +57,7 @@ public class Any { ...@@ -57,7 +57,7 @@ public class Any {
* @param object the data of the any. * @param object the data of the any.
* @deprecated as of UDK 2.0 * @deprecated as of UDK 2.0
*/ */
public Any(Class zInterface, Object object) { public Any(Class<?> zInterface, Object object) {
this(new Type(zInterface), object); this(new Type(zInterface), object);
} }
......
...@@ -175,5 +175,5 @@ public interface ITypeDescription { ...@@ -175,5 +175,5 @@ public interface ITypeDescription {
* <p> * <p>
* @return the corresponding java class. * @return the corresponding java class.
*/ */
Class getZClass(); Class<?> getZClass();
} }
...@@ -78,7 +78,7 @@ public class Type { ...@@ -78,7 +78,7 @@ public class Type {
TYPE_NAME_ANY TYPE_NAME_ANY
}; };
private static final HashMap __javaClassToTypeClass = new HashMap(); private static final HashMap<Class<?>, TypeClass[]> __javaClassToTypeClass = new HashMap<Class<?>, TypeClass[]>();
static { static {
__javaClassToTypeClass.put( __javaClassToTypeClass.put(
void.class, new TypeClass[] { TypeClass.VOID, TypeClass.VOID }); void.class, new TypeClass[] { TypeClass.VOID, TypeClass.VOID });
...@@ -189,7 +189,7 @@ public class Type { ...@@ -189,7 +189,7 @@ public class Type {
* @param zClass the Java class of this type. Must not be * @param zClass the Java class of this type. Must not be
* <code>null</code>. * <code>null</code>.
*/ */
public Type(Class zClass) { public Type(Class<?> zClass) {
init(null, zClass, false, false); init(null, zClass, false, false);
} }
...@@ -243,7 +243,7 @@ public class Type { ...@@ -243,7 +243,7 @@ public class Type {
* *
* @since UDK 3.2.0 * @since UDK 3.2.0
*/ */
public Type(Class zClass, boolean alternative) { public Type(Class<?> zClass, boolean alternative) {
init(null, zClass, alternative, false); init(null, zClass, alternative, false);
} }
...@@ -333,7 +333,7 @@ public class Type { ...@@ -333,7 +333,7 @@ public class Type {
* @return the type name; may be <code>null</code> in extreme situations * @return the type name; may be <code>null</code> in extreme situations
* (inconsistent <code>TypeClass</code>, error loading a class) * (inconsistent <code>TypeClass</code>, error loading a class)
*/ */
public Class getZClass() { public Class<?> getZClass() {
synchronized (this) { synchronized (this) {
if (_class == null) { if (_class == null) {
_class = determineClass(); _class = determineClass();
...@@ -401,8 +401,8 @@ public class Type { ...@@ -401,8 +401,8 @@ public class Type {
} }
case TypeClass.EXCEPTION_value: case TypeClass.EXCEPTION_value:
case TypeClass.INTERFACE_value: case TypeClass.INTERFACE_value:
Class c1 = getZClass(); Class<?> c1 = getZClass();
Class c2 = type.getZClass(); Class<?> c2 = type.getZClass();
return c1 != null && c2 != null && c1.isAssignableFrom(c2); return c1 != null && c2 != null && c1.isAssignableFrom(c2);
default: default:
...@@ -428,9 +428,9 @@ public class Type { ...@@ -428,9 +428,9 @@ public class Type {
} }
private void init( private void init(
String name, Class zClass, boolean alternative, boolean arguments) String name, Class<?> zClass, boolean alternative, boolean arguments)
{ {
TypeClass[] tc = (TypeClass[]) __javaClassToTypeClass.get(zClass); TypeClass[] tc = __javaClassToTypeClass.get(zClass);
if (tc != null) { if (tc != null) {
// tc only contains primitive type classes, except for // tc only contains primitive type classes, except for
// TypeClass.INTERFACE, which stands for XInterface (the alternative // TypeClass.INTERFACE, which stands for XInterface (the alternative
...@@ -488,7 +488,7 @@ public class Type { ...@@ -488,7 +488,7 @@ public class Type {
} }
} }
private Class determineClass() { private Class<?> determineClass() {
switch (_typeClass.getValue()) { switch (_typeClass.getValue()) {
case TypeClass.VOID_value: case TypeClass.VOID_value:
return _typeName.equals(TYPE_NAME_VOID) ? void.class : null; return _typeName.equals(TYPE_NAME_VOID) ? void.class : null;
...@@ -580,7 +580,7 @@ public class Type { ...@@ -580,7 +580,7 @@ public class Type {
if (args >= 0) { if (args >= 0) {
base = base.substring(0, args); base = base.substring(0, args);
} }
Class c; Class<?> c;
try { try {
c = Class.forName(base); c = Class.forName(base);
} catch (ClassNotFoundException e) { } catch (ClassNotFoundException e) {
...@@ -604,7 +604,7 @@ public class Type { ...@@ -604,7 +604,7 @@ public class Type {
case TypeClass.EXCEPTION_value: case TypeClass.EXCEPTION_value:
case TypeClass.INTERFACE_value: case TypeClass.INTERFACE_value:
{ {
Class c; Class<?> c;
try { try {
c = Class.forName(_typeName); c = Class.forName(_typeName);
} catch (ClassNotFoundException e) { } catch (ClassNotFoundException e) {
...@@ -616,7 +616,7 @@ public class Type { ...@@ -616,7 +616,7 @@ public class Type {
case TypeClass.STRUCT_value: case TypeClass.STRUCT_value:
{ {
int args = _typeName.indexOf('<'); int args = _typeName.indexOf('<');
Class c; Class<?> c;
try { try {
c = Class.forName( c = Class.forName(
args < 0 ? _typeName : _typeName.substring(0, args)); args < 0 ? _typeName : _typeName.substring(0, args));
...@@ -638,6 +638,6 @@ public class Type { ...@@ -638,6 +638,6 @@ public class Type {
protected TypeClass _typeClass; // TODO should be final protected TypeClass _typeClass; // TODO should be final
protected String _typeName; // TODO should be final protected String _typeName; // TODO should be final
protected Class _class; protected Class<?> _class;
protected ITypeDescription _iTypeDescription; protected ITypeDescription _iTypeDescription;
} }
...@@ -149,7 +149,7 @@ public class UnoRuntime { ...@@ -149,7 +149,7 @@ public class UnoRuntime {
} }
} }
// Ensure that the object implements the requested interface type: // Ensure that the object implements the requested interface type:
Class c = type.getZClass(); Class<?> c = type.getZClass();
if (c == null || !c.isInstance(object)) { if (c == null || !c.isInstance(object)) {
object = null; object = null;
} }
...@@ -367,7 +367,7 @@ public class UnoRuntime { ...@@ -367,7 +367,7 @@ public class UnoRuntime {
* if no context has been set for the current thread * if no context has been set for the current thread
*/ */
public static XCurrentContext getCurrentContext() { public static XCurrentContext getCurrentContext() {
return (XCurrentContext) currentContext.get(); return currentContext.get();
} }
/** /**
...@@ -407,13 +407,13 @@ public class UnoRuntime { ...@@ -407,13 +407,13 @@ public class UnoRuntime {
throws java.lang.Exception throws java.lang.Exception
{ {
synchronized (environments) { synchronized (environments) {
IEnvironment env = (IEnvironment) WeakMap.getValue( IEnvironment env = WeakMap.getValue(
environments.get(name + context)); environments.get(name + context));
if (env == null) { if (env == null) {
Class c = Class.forName( Class<?> c = Class.forName(
"com.sun.star.lib.uno.environments." + name + "." + name "com.sun.star.lib.uno.environments." + name + "." + name
+ "_environment"); + "_environment");
Constructor ctor = c.getConstructor( Constructor<?> ctor = c.getConstructor(
new Class[] { Object.class }); new Class[] { Object.class });
env = (IEnvironment) ctor.newInstance(new Object[] { context }); env = (IEnvironment) ctor.newInstance(new Object[] { context });
environments.put(name + context, env); environments.put(name + context, env);
...@@ -453,9 +453,9 @@ public class UnoRuntime { ...@@ -453,9 +453,9 @@ public class UnoRuntime {
String name = from.getName() + "_" + to.getName(); String name = from.getName() + "_" + to.getName();
String hashName = from.getName() + from.getContext() + "_" String hashName = from.getName() + from.getContext() + "_"
+ to.getName() + to.getContext(); + to.getName() + to.getContext();
IBridge bridge = (IBridge) WeakMap.getValue(bridges.get(hashName)); IBridge bridge = WeakMap.getValue(bridges.get(hashName));
if(bridge == null) { if(bridge == null) {
Class zClass = null; Class<?> zClass = null;
String className = name + "_bridge"; String className = name + "_bridge";
try { try {
zClass = Class.forName(className); zClass = Class.forName(className);
...@@ -464,9 +464,9 @@ public class UnoRuntime { ...@@ -464,9 +464,9 @@ public class UnoRuntime {
+ className; + className;
zClass = Class.forName(className); zClass = Class.forName(className);
} }
Class[] signature = { Class<?>[] signature = {
IEnvironment.class, IEnvironment.class, args.getClass() }; IEnvironment.class, IEnvironment.class, args.getClass() };
Constructor constructor = zClass.getConstructor(signature); Constructor<?> constructor = zClass.getConstructor(signature);
Object[] iargs = { from, to, args }; Object[] iargs = { from, to, args };
bridge = (IBridge) constructor.newInstance(iargs); bridge = (IBridge) constructor.newInstance(iargs);
bridges.put(hashName, bridge); bridges.put(hashName, bridge);
...@@ -521,16 +521,16 @@ public class UnoRuntime { ...@@ -521,16 +521,16 @@ public class UnoRuntime {
* offering a replacement. * offering a replacement.
*/ */
public static IBridge[] getBridges() { public static IBridge[] getBridges() {
ArrayList l = new ArrayList(); ArrayList<Object> l = new ArrayList<Object>();
synchronized (bridges) { synchronized (bridges) {
for (Iterator i = bridges.values().iterator(); i.hasNext();) { for (Iterator<java.lang.ref.WeakReference<IBridge>> i = bridges.values().iterator(); i.hasNext();) {
Object o = WeakMap.getValue(i.next()); IBridge o = WeakMap.getValue(i.next());
if (o != null) { if (o != null) {
l.add(o); l.add(o);
} }
} }
} }
return (IBridge[]) l.toArray(new IBridge[l.size()]); return l.toArray(new IBridge[l.size()]);
} }
/** /**
...@@ -596,8 +596,8 @@ public class UnoRuntime { ...@@ -596,8 +596,8 @@ public class UnoRuntime {
*/ */
static public boolean reset() { static public boolean reset() {
synchronized (bridges) { synchronized (bridges) {
for (Iterator i = bridges.values().iterator(); i.hasNext();) { for (Iterator<java.lang.ref.WeakReference<IBridge>> i = bridges.values().iterator(); i.hasNext();) {
IBridge b = (IBridge) WeakMap.getValue(i.next()); IBridge b = WeakMap.getValue(i.next());
if (b != null) { if (b != null) {
// The following call to dispose was originally made to // The following call to dispose was originally made to
// com.sun.star.lib.sandbox.Disposable.dispose, which cannot // com.sun.star.lib.sandbox.Disposable.dispose, which cannot
...@@ -681,8 +681,8 @@ public class UnoRuntime { ...@@ -681,8 +681,8 @@ public class UnoRuntime {
private static final String oidSuffix = ";java[];" + getUniqueKey(); private static final String oidSuffix = ";java[];" + getUniqueKey();
private static final ThreadLocal currentContext = new ThreadLocal(); private static final ThreadLocal<XCurrentContext> currentContext = new ThreadLocal<XCurrentContext>();
private static final WeakMap environments = new WeakMap(); private static final WeakMap<String,IEnvironment> environments = new WeakMap<String,IEnvironment>();
private static final WeakMap bridges = new WeakMap(); private static final WeakMap<String,IBridge> bridges = new WeakMap<String,IBridge>();
} }
...@@ -69,7 +69,7 @@ public final class UnoLoader { ...@@ -69,7 +69,7 @@ public final class UnoLoader {
UnoClassLoader cl; UnoClassLoader cl;
try { try {
cl = (UnoClassLoader) AccessController.doPrivileged( cl = (UnoClassLoader) AccessController.doPrivileged(
new PrivilegedExceptionAction() { new PrivilegedExceptionAction<Object>() {
public Object run() throws MalformedURLException { public Object run() throws MalformedURLException {
return new UnoClassLoader( return new UnoClassLoader(
base, null, UnoLoader.class.getClassLoader()); base, null, UnoLoader.class.getClassLoader());
......
...@@ -24,7 +24,7 @@ import static org.junit.Assert.*; ...@@ -24,7 +24,7 @@ import static org.junit.Assert.*;
public final class WeakMap_Test { public final class WeakMap_Test {
@Test public void test() { @Test public void test() {
WeakMap m = new WeakMap(); WeakMap<String,Object> m = new WeakMap<String,Object>();
assertEquals(0, m.size()); assertEquals(0, m.size());
assertTrue(m.isEmpty()); assertTrue(m.isEmpty());
assertFalse(m.containsKey("key1")); assertFalse(m.containsKey("key1"));
......
...@@ -71,10 +71,10 @@ public final class UnoRuntime_Test { ...@@ -71,10 +71,10 @@ public final class UnoRuntime_Test {
UnoRuntime.areSame( UnoRuntime.areSame(
new Any( new Any(
new Type("com.sun.star.beans.Optional<unsigned long>"), new Type("com.sun.star.beans.Optional<unsigned long>"),
new Optional()), new Optional<Integer>()),
new Any( new Any(
new Type("com.sun.star.beans.Optional<unsigned long>"), new Type("com.sun.star.beans.Optional<unsigned long>"),
new Optional(false, new Integer(0))))); new Optional<Integer>(false, new Integer(0)))));
assertFalse(UnoRuntime.areSame(new Test1(), new Test2())); assertFalse(UnoRuntime.areSame(new Test1(), new Test2()));
Test2 test2 = new Test2(); Test2 test2 = new Test2();
assertTrue( assertTrue(
...@@ -83,6 +83,7 @@ public final class UnoRuntime_Test { ...@@ -83,6 +83,7 @@ public final class UnoRuntime_Test {
UnoRuntime.queryInterface(Ifc.class, test2), test2)); UnoRuntime.queryInterface(Ifc.class, test2), test2));
} }
@SuppressWarnings("rawtypes")
@Test public void test_completeValue() { @Test public void test_completeValue() {
assertEquals( assertEquals(
new Integer(0), UnoRuntime.completeValue(Type.UNSIGNED_LONG, null)); new Integer(0), UnoRuntime.completeValue(Type.UNSIGNED_LONG, null));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment