KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > aspectwerkz > transform > inlining > deployer > RedefinerFactory


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.aspectwerkz.transform.inlining.deployer;
5
6
7 import com.tc.aspectwerkz.exception.WrappedRuntimeException;
8 import com.tc.aspectwerkz.util.ContextClassLoader;
9
10 /**
11  * Factory for the different redefiner implementations.
12  *
13  * @author <a HREF="mailto:jboner@codehaus.org">Jonas BonŽr </a>
14  */

15 public class RedefinerFactory {
16   private static final String JavaDoc HOTSWAP_REDEFINER_CLASS_NAME =
17           "com.tc.aspectwerkz.extension.hotswap.HotSwapRedefiner";
18
19   private static final String JavaDoc JVMTI_REDEFINER_CLASS_NAME =
20           "com.tc.aspectwerkz.hook.JVMTIRedefiner";
21
22   /**
23    * Creates a new redefiner instance.
24    * Try first with JDK 5 and failover on Java 1.4 HotSwap (requires native AW module)
25    *
26    * @return the redefiner instance
27    */

28   public static Redefiner newRedefiner(final Type type) {
29     if (type.equals(Type.HOTSWAP)) {
30       try {
31         Class JavaDoc redefinerClass = ContextClassLoader.forName(JVMTI_REDEFINER_CLASS_NAME);
32         return (Redefiner) redefinerClass.newInstance();
33       } catch (Throwable JavaDoc t) {
34         try {
35           Class JavaDoc redefinerClass = ContextClassLoader.forName(HOTSWAP_REDEFINER_CLASS_NAME);
36           return (Redefiner) redefinerClass.newInstance();
37         } catch (ClassNotFoundException JavaDoc e) {
38           // TODO this message will be wrong if Java 5 did not started a preMain
39
throw new WrappedRuntimeException(
40                   "redefiner class [HotSwapRedefiner] could not be found on classpath, make sure you have the aspectwerkz extensions jar file in your classpath",
41                   e
42           );
43         } catch (Exception JavaDoc e) {
44           // TODO this message will be wrong upon Java 5..
45
throw new WrappedRuntimeException("redefiner class [HotSwapRedefiner] could not be instantiated", e);
46         }
47       }
48
49     } else if (type.equals(Type.JVMTI)) {
50       throw new UnsupportedOperationException JavaDoc("JVMTI is not supported yet");
51     } else {
52       throw new UnsupportedOperationException JavaDoc("unknown redefiner type: " + type.toString());
53     }
54   }
55
56   /**
57    * Type-safe enum for the different redefiner implementations.
58    *
59    * @author <a HREF="mailto:jboner@codehaus.org">Jonas BonŽr </a>
60    */

61   public static class Type {
62     public static final Type HOTSWAP = new Type("HOTSWAP");
63     public static final Type JVMTI = new Type("JVMTI");
64
65     private final String JavaDoc m_name;
66
67     private Type(String JavaDoc name) {
68       m_name = name;
69     }
70
71     public String JavaDoc toString() {
72       return m_name;
73     }
74   }
75 }
76
Popular Tags