01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */
04: package com.tc.aspectwerkz.transform.inlining.deployer;
05:
06: import com.tc.aspectwerkz.exception.WrappedRuntimeException;
07: import com.tc.aspectwerkz.util.ContextClassLoader;
08:
09: /**
10: * Factory for the different redefiner implementations.
11: *
12: * @author <a href="mailto:jboner@codehaus.org">Jonas BonŽr </a>
13: */
14: public class RedefinerFactory {
15: private static final String HOTSWAP_REDEFINER_CLASS_NAME = "com.tc.aspectwerkz.extension.hotswap.HotSwapRedefiner";
16:
17: private static final String JVMTI_REDEFINER_CLASS_NAME = "com.tc.aspectwerkz.hook.JVMTIRedefiner";
18:
19: /**
20: * Creates a new redefiner instance.
21: * Try first with JDK 5 and failover on Java 1.4 HotSwap (requires native AW module)
22: *
23: * @return the redefiner instance
24: */
25: public static Redefiner newRedefiner(final Type type) {
26: if (type.equals(Type.HOTSWAP)) {
27: try {
28: Class redefinerClass = ContextClassLoader
29: .forName(JVMTI_REDEFINER_CLASS_NAME);
30: return (Redefiner) redefinerClass.newInstance();
31: } catch (Throwable t) {
32: try {
33: Class redefinerClass = ContextClassLoader
34: .forName(HOTSWAP_REDEFINER_CLASS_NAME);
35: return (Redefiner) redefinerClass.newInstance();
36: } catch (ClassNotFoundException e) {
37: // TODO this message will be wrong if Java 5 did not started a preMain
38: throw new WrappedRuntimeException(
39: "redefiner class [HotSwapRedefiner] could not be found on classpath, make sure you have the aspectwerkz extensions jar file in your classpath",
40: e);
41: } catch (Exception e) {
42: // TODO this message will be wrong upon Java 5..
43: throw new WrappedRuntimeException(
44: "redefiner class [HotSwapRedefiner] could not be instantiated",
45: e);
46: }
47: }
48:
49: } else if (type.equals(Type.JVMTI)) {
50: throw new UnsupportedOperationException(
51: "JVMTI is not supported yet");
52: } else {
53: throw new UnsupportedOperationException(
54: "unknown redefiner type: " + type.toString());
55: }
56: }
57:
58: /**
59: * Type-safe enum for the different redefiner implementations.
60: *
61: * @author <a href="mailto:jboner@codehaus.org">Jonas BonŽr </a>
62: */
63: public static class Type {
64: public static final Type HOTSWAP = new Type("HOTSWAP");
65: public static final Type JVMTI = new Type("JVMTI");
66:
67: private final String m_name;
68:
69: private Type(String name) {
70: m_name = name;
71: }
72:
73: public String toString() {
74: return m_name;
75: }
76: }
77: }
|