improved interface registration algorithm
This commit is contained in:
sdv%sparc.spb.su 2000-10-11 20:35:12 +00:00
Родитель a0840d1082
Коммит 98f5d52c7a
1 изменённых файлов: 50 добавлений и 31 удалений

Просмотреть файл

@ -48,7 +48,7 @@ public class InterfaceRegistry {
try {
register(Class.forName(name));
} catch (Exception e) {
debug(e.toString());
e.printStackTrace();
}
}
@ -78,35 +78,56 @@ public class InterfaceRegistry {
}
}
private static void registerInterfaces(Class cl) {
public static void unregister(IID iid) {
interfaces.remove(iid);
iMethods.remove(iid);
}
private static Hashtable registerInterfaces(Class cl) {
try {
Object iidStr = cl.getField(IID_STRING).get(cl);
if (iidStr instanceof String) {
IID iid = new IID((String)iidStr);
// if this iface hasn't been registered, yet
if (interfaces.get(iid) == null) {
String[] methodNames = Utilities.getInterfaceMethodNames((String)iidStr);
if (methodNames != null) {
Method[] rmethods = new Method[methodNames.length];
Class[] ifaces = new Class[]{cl};
Hashtable mhash = new Hashtable(methodNames.length);
Class[] ifaces = cl.getInterfaces();
// check for single inheritance (xpcom)
if (ifaces.length < 2) {
// recursively get all parent interface methods
do {
Method[] methods = ifaces[0].getDeclaredMethods();
Hashtable mhash = null;
Method[] methods = cl.getDeclaredMethods();
// the very super iface
if (ifaces.length == 0) {
mhash = new Hashtable(methods.length);
} else {
mhash = new Hashtable(registerInterfaces(ifaces[0]));
}
for (int i = 0; i < methods.length; i++) {
mhash.put(methods[i].getName(), methods[i]);
}
ifaces = ifaces[0].getInterfaces();
// check for single inheritance (xpcom)
} while (ifaces.length == 1);
for (int j = methodNames.length - 1; j >= 0; j--) {
rmethods[j] = (Method)mhash.get(subscriptMethodName(methodNames[j]));
}
interfaces.put(iid, cl);
iMethods.put(iid, new MethodArray(rmethods));
iMethods.put(iid, new MethodArray(rmethods, mhash));
debug(cl.getName() + ": " + iid + " ( " + cl + " )");
printMethods(rmethods);
return mhash;
}
}
// simply pass iface methods
} else {
MethodArray m = (MethodArray)iMethods.get(iid);
if (m != null) {
return m.names;
}
}
}
} catch (NoSuchFieldException e) {
@ -115,11 +136,7 @@ public class InterfaceRegistry {
} catch (IllegalAccessException e1) {
debug("can't access field...");
}
// register interfaces extended by the interface
Class[] ifaces = cl.getInterfaces();
for (int i = 0; i < ifaces.length; i++) {
registerInterfaces(ifaces[i]);
}
return new Hashtable();
}
public static Class getInterface(IID iid) {
@ -151,7 +168,7 @@ public class InterfaceRegistry {
MethodArray m = (MethodArray)iMethods.get(iid);
if (m != null && m.methods != null) {
for (int i = 0; i < m.methods.length; i++) {
if (method.equals(m.methods[i])) {
if (m.methods[i] != null && method.equals(m.methods[i])) {
result = i;
break;
}
@ -218,7 +235,9 @@ public class InterfaceRegistry {
class MethodArray {
Method[] methods;
MethodArray(Method[] _methods) {
Hashtable names;
MethodArray(Method[] _methods, Hashtable _names) {
methods = _methods;
names = _names;
}
}