KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > object > bytecode > hook > impl > Util


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package com.tc.object.bytecode.hook.impl;
5
6 import com.tc.object.TCObject;
7 import com.tc.object.bytecode.Manageable;
8
9 public class Util {
10
11   private Util() {
12     //
13
}
14
15   public static void exit() {
16     exit(null);
17   }
18
19   public static void exit(Throwable JavaDoc t) {
20     if (t != null) {
21       t.printStackTrace(System.err);
22       System.err.flush();
23     }
24
25     try {
26       Thread.sleep(500);
27     } catch (InterruptedException JavaDoc e) {
28       // ignore
29
}
30
31     System.exit(1);
32   }
33
34
35   /**
36    * This method resolves all the references in an object before clone is called so that clone can clone all the
37    * references. This is called from the instrumented code.
38    */

39   public static void resolveAllReferencesBeforeClone(Object JavaDoc toBeCloned) {
40     if (toBeCloned instanceof Manageable) {
41       TCObject tcObject = ((Manageable) toBeCloned).__tc_managed();
42       if (tcObject != null) {
43         tcObject.resolveAllReferences();
44       }
45     }
46   }
47
48   /**
49    * This method unsets the TCObject reference in the cloned object if the clone() method had done a shallow copy. This
50    * is called from the instrumented code.
51    */

52   public static Object JavaDoc fixTCObjectReferenceOfClonedObject(Object JavaDoc original, Object JavaDoc clone) {
53     if (clone instanceof Manageable && original instanceof Manageable) {
54       Manageable mClone = (Manageable) clone;
55       Manageable mOriginal = (Manageable) original;
56       if (mClone.__tc_managed() != null && clone != original && mClone.__tc_managed() == mOriginal.__tc_managed()) {
57         // A shallow copy is returned. We dont want the clone to have the same TCObject
58
mClone.__tc_managed(null);
59       }
60     }
61     return clone;
62   }
63
64 }
65
Popular Tags