001: // This file is part of KeY - Integrated Deductive Software Design
002: // Copyright (C) 2001-2007 Universitaet Karlsruhe, Germany
003: // Universitaet Koblenz-Landau, Germany
004: // Chalmers University of Technology, Sweden
005: //
006: // The KeY system is protected by the GNU General Public License.
007: // See LICENSE.TXT for details.
008: //
009: //
010:
011: /* Generated by Together */
012:
013: package de.uka.ilkd.key.casetool.together.keydebugclassloader;
014:
015: import java.lang.reflect.Field;
016: import java.util.Vector;
017:
018: import com.togethersoft.openapi.sci.pattern.SciPattern;
019:
020: import de.uka.ilkd.key.casetool.together.patterns.HelperClasses.MyPatternBase.MyClassPatternBase;
021: import de.uka.ilkd.key.util.Debug;
022:
023: public abstract class KeyPattern extends MyClassPatternBase implements
024: SciPattern {
025:
026: public String KEY_SET_METHOD;
027: public String KEY_CONSTRUCTOR_PARAMETER;
028: public String KEY_NONE;
029:
030: {
031: Field field = null;
032: try {
033: field = getClass().getField("UI_NONE");
034: if (field == null) {
035: Debug.out("Together-API<6.0");
036: KEY_SET_METHOD = (String) getClass().getField(
037: "SET_METHOD").get(this );
038: KEY_CONSTRUCTOR_PARAMETER = (String) getClass()
039: .getField("CONSTRUCTOR_PARAMETER").get(this );
040: KEY_NONE = (String) getClass().getField("NONE").get(
041: this );
042: } else {
043: Debug.out("Together-API>=6.0");
044: KEY_SET_METHOD = (String) getClass().getField(
045: "UI_SET_METHOD").get(this );
046: KEY_CONSTRUCTOR_PARAMETER = (String) getClass()
047: .getField("UI_CONSTRUCTOR_PARAMETER").get(this );
048: KEY_NONE = (String) getClass().getField("UI_NONE").get(
049: this );
050: }
051: } catch (IllegalAccessException iae) {
052: System.err
053: .println("keypattern: underlying constructor is inaccesible.");
054: System.err.println("The exception was: " + iae);
055: iae.printStackTrace();
056: } catch (IllegalArgumentException iae) {
057: System.err
058: .println("keypattern: specified object is not an "
059: + "instance of the class or interface declaring"
060: + "the underlying field (or a subclass or implementor"
061: + "thereof).field is not accessible.");
062: System.err.println("The exception was: " + iae);
063: iae.printStackTrace();
064: } catch (NoSuchFieldException e) {
065: String message = "Together renamed some fields, when changing from API <6.0 to >=6.0.\n";
066: message += "The thrown exception indicates that you have a (probably) new version,\n";
067: message += "where the fields have been renamed once again.\n";
068: message += " Please mail this error to: key@ira.uka.de\n";
069: message += "The thrown exception was " + e;
070: System.err.println("keypattern:" + message);
071: e.printStackTrace();
072: } catch (SecurityException se) {
073: String message = "Together renamed some fields, when changing from API <6.0 to >=6.0.\n";
074: message += "The thrown exception indicates, that you use (probably) a newer\n";
075: message += "version, where the access permissions have been restricted.";
076: message += " Please mail this error to: key@ira.uka.de\n";
077: message += "The thrown exception was: " + se;
078: System.err.println("keypattern:" + message);
079: se.printStackTrace();
080: }
081:
082: }
083:
084: private KeyPattern this clone;
085:
086: public final boolean prepare() {
087: int i;
088: if ("on".equals(System.getProperty("KeyDebugClassLoader"))) {
089: this clone = reloadClassDef();
090: // IdeMessageManagerAccess.printMessage(IdeMessageType.INFORMATION, "jetzt habe ich reload gemacht!\n");
091: Class cl = this .getClass();
092: Vector fieldVector = new Vector();
093: Field[] fields = cl.getDeclaredFields();
094: for (i = 0; i < fields.length; i++) {
095: fieldVector.addElement(fields[i]);
096: }
097: Class help = cl;
098: while (help.getSuperclass() != null) {
099: help = help.getSuperclass();
100: fields = help.getDeclaredFields();
101: for (i = 0; i < fields.length; i++) {
102: fields[i].setAccessible(true); // damit auch private der Oberklassen lesbar werden
103: fieldVector.addElement(fields[i]);
104: }
105: }
106: for (i = 0; i < fieldVector.size(); i++) {
107: Field actField = (Field) fieldVector.elementAt(i);
108: try {
109: // System.out.println(actField.getName() + " mit wert " + actField.get(this)+"\n");
110: actField.set(this clone, actField.get(this ));
111: } catch (IllegalAccessException iae) {
112: System.err
113: .println("keypattern: setting/getting of field failed. Reason:\n"
114: + "the underlying constructor is inaccessible.");
115: System.err.println("The exception was:" + iae);
116: iae.printStackTrace();
117: } catch (IllegalArgumentException iarg) {
118: System.err
119: .println("keypattern: setting/getting of field failed. Reason:\n"
120: + "The specified object is not an instance of the\n"
121: + "class or interface declaring the underlying field\n"
122: + "(or a subclass or implementor thereof), or if an\n"
123: + "unwrapping conversion fails.");
124: System.err.println("The exception was:" + iarg);
125: iarg.printStackTrace();
126: } catch (NullPointerException ne) {
127: System.err
128: .println("keypattern: setting of field failed. Reason:\n"
129: + "the specified object is null and the field is\n"
130: + "an instance field.");
131: System.err.println("The exception was:" + ne);
132: ne.printStackTrace();
133: } catch (ExceptionInInitializerError ei) {
134: System.err
135: .println("keypattern: setting of field failed. Reason:\n"
136: + "the initialization provoked by this method fails.");
137: System.err.println("The exception was:" + ei);
138: ei.printStackTrace();
139: }
140:
141: }
142: } else {
143: this clone = this ;
144: }
145:
146: return this clone.prepare1();
147: }
148:
149: /* because we change the semantics of the original prepare method, we introduce this simulation method
150: to invoke the prepare method in the super class */
151: public final void super PrepareSimu() {
152: super .prepare();
153: }
154:
155: public boolean prepare1() {
156: return true;
157: }
158:
159: public boolean canApply() {
160: return this clone.canApply1();
161: }
162:
163: public boolean canApply1() {
164: return true;
165: }
166:
167: public void apply() {
168: this clone.apply1();
169: }
170:
171: public void apply1() {
172: }
173:
174: public final void super ApplySimu() {
175: super .apply();
176: }
177:
178: protected void finalize() throws Throwable {
179: this clone.finalize1();
180: }
181:
182: protected void finalize1() throws Throwable {
183: }
184:
185: protected void super FinalizeSimu() throws Throwable {
186: super .finalize();
187: }
188:
189: // reloads the class-definition of the this-object
190: // and returns a new instance of it.
191: private KeyPattern reloadClassDef() {
192: String this ClassName = this .getClass().getName();
193: // IdeMessageManagerAccess.printMessage(IdeMessageType.INFORMATION,"Name der nachgeladenen Klasse: "+thisClassName+"\n");
194: KeyPattern pattern = null;
195: try {
196: KeyDebugClassLoader classLoader = new KeyDebugClassLoader();
197: // Because of the explicit cast later KeyScript must not be
198: // reloaded by KeyDebugClassLoader (otherwise we get an cast-error)
199: classLoader.setClassAlwaysAskParent(KeyPattern.class);
200: Class cl = classLoader.loadClass(this ClassName);
201: pattern = (KeyPattern) cl.newInstance();
202: } catch (ExceptionInInitializerError ei) {
203: System.err
204: .println("keypattern: the initialization provoked "
205: + "by this method fails.");
206: System.err.println("The exception was: " + ei);
207: ei.printStackTrace();
208: } catch (IllegalAccessException iae) {
209: System.err.println("keypattern: class or "
210: + "initializer is not accessible.");
211: System.err.println("The exception was: " + iae);
212: iae.printStackTrace();
213: } catch (InstantiationException ie) {
214: System.err
215: .println("keypattern: class tried to\n"
216: + "instantiate represents an abstract class, an interface,"
217: + "an array class, a primitive type, or void; or if the"
218: + "instantiation fails for some other reason.");
219: System.err.println("The exception was: " + ie);
220: ie.printStackTrace();
221: } catch (SecurityException se) {
222: System.err.println("keypattern: no permission to create"
223: + "a new instance");
224: System.err.println("The exception was: " + se);
225: se.printStackTrace();
226: }
227: return pattern;
228: }
229: }
|