01: // This file is part of KeY - Integrated Deductive Software Design
02: // Copyright (C) 2001-2007 Universitaet Karlsruhe, Germany
03: // Universitaet Koblenz-Landau, Germany
04: // Chalmers University of Technology, Sweden
05: //
06: // The KeY system is protected by the GNU General Public License.
07: // See LICENSE.TXT for details.
08: //
09: //
10:
11: /* Generated by Together */
12:
13: package de.uka.ilkd.key.casetool.together.keydebugclassloader;
14:
15: import java.net.URL;
16: import java.net.URLClassLoader;
17:
18: public class KeyDebugClassLoader extends URLClassLoader {
19:
20: private static int nextLoaderID = 0;
21:
22: private final int loaderID = nextLoaderID++;
23: private boolean reported = false;
24:
25: private static final URL[] urls = new URL[] { null };
26:
27: static {
28: try {
29: urls[0] = new URL("file:" + System.getProperty("key.home")
30: + "/system/binary/");
31: } catch (java.net.MalformedURLException e) {
32: System.err
33: .println("KeyError: Coulnd't create a file URL for"
34: + " the KeyDebugClassLoader.");
35: e.printStackTrace();
36: }
37:
38: }
39:
40: private final ClassLoader _specialParent;
41:
42: private String classAlwaysAskParent = "";
43:
44: public KeyDebugClassLoader() {
45: this (getSystemClassLoader());
46: }
47:
48: public KeyDebugClassLoader(ClassLoader parent) {
49: super (urls, null);
50: _specialParent = parent;
51: }
52:
53: public void setClassAlwaysAskParent(Class aClass) {
54: classAlwaysAskParent = aClass.getName();
55: }
56:
57: public Class loadClass(String name) {
58: try {
59: if (classShouldBeReloaded(name)) {
60: if (!reported) {
61: System.err.println("DEBUG:: KeyDebugClassLoader #"
62: + loaderID + " loading KeY classes.");
63: reported = true;
64: }
65:
66: // Uncomment to log loading of every class:
67: //System.err.println("DEBUG:: Loader #" +loaderID+
68: //" loads class "+name);
69:
70: return super .loadClass(name);
71: } else {
72: return _specialParent.loadClass(name);
73: }
74: } catch (ClassNotFoundException ex) {
75: System.err
76: .println(ex
77: + "\n IMPORTANT!!!!!!\nThe DebugClassLoader contains relative "
78: + "paths. To work properly, \"startkey\" must be invoked "
79: + "within directory \"system\".");
80: }
81: return null;
82: }
83:
84: public boolean classShouldBeReloaded(String name) {
85: return (name.startsWith("de.uka.ilkd.")
86: && !name
87: .startsWith("de.uka.ilkd.key.casetool.ReprModel")
88: && !name.equals(classAlwaysAskParent)
89: && !name.equals(this .getClass().getName()) && name
90: .indexOf("MyPatternBase") == -1);
91: }
92:
93: }
|