01: // Copyright 2000 Samuele Pedroni
02:
03: package jxxload_help;
04:
05: import org.python.core.PyJavaClass;
06:
07: public class DiscardHelp extends Object {
08:
09: private DiscardHelp() {
10: }
11:
12: private static boolean check(Class c, ClassLoader loader,
13: java.util.Vector interfaces) {
14: try {
15: Class s = c;
16: do {
17: if (s.getClassLoader() == loader)
18: return true;
19: s = s.getSuperclass();
20: } while (s != null);
21:
22: for (java.util.Enumeration enumm = interfaces.elements(); enumm
23: .hasMoreElements();) {
24: Class intf = (Class) enumm.nextElement();
25: if (intf.isAssignableFrom(c))
26: return true;
27: }
28:
29: } catch (SecurityException e) {
30: }
31: return false;
32: }
33:
34: // clearly not thread safe
35: public static void discard(ClassLoader loader,
36: java.util.Vector interfaces) {
37:
38: org.python.core.InternalTables tbl = PyJavaClass
39: .getInternalTables();
40:
41: tbl._beginCanonical();
42:
43: PyJavaClass jc;
44: while ((jc = (PyJavaClass) tbl._next()) != null) {
45: Class c = (Class) jc.__tojava__(Class.class);
46: if (check(c, loader, interfaces))
47: tbl._flushCurrent();
48: }
49:
50: tbl._beginOverAdapterClasses();
51:
52: Class c;
53:
54: while ((c = (Class) tbl._next()) != null) {
55: if (interfaces.contains(c))
56: tbl._flushCurrent();
57: }
58:
59: tbl._beginOverAdapters();
60:
61: while ((c = (Class) tbl._next()) != null) {
62: if (interfaces.contains(c))
63: tbl._flushCurrent();
64: }
65:
66: }
67:
68: }
|