01: /**************************************************************************************
02: * Copyright (c) Jonas BonŽr, Alexandre Vasseur. All rights reserved. *
03: * http://aspectwerkz.codehaus.org *
04: * ---------------------------------------------------------------------------------- *
05: * The software in this package is published under the terms of the LGPL license *
06: * a copy of which has been included with this distribution in the license.txt file. *
07: **************************************************************************************/package org.codehaus.aspectwerkz.hook;
08:
09: import java.lang.instrument.Instrumentation;
10: import java.lang.instrument.ClassFileTransformer;
11:
12: /**
13: * Java 1.5 preMain agent
14: * Can be used with -javaagent:aspectwerkz-core-XXX.jar
15: *
16: * @author <a href="mailto:alex@gnilux.com">Alexandre Vasseur</a>
17: */
18: public class Agent {
19:
20: /**
21: * The instrumentation instance
22: */
23: private static Instrumentation s_instrumentation;
24:
25: /**
26: * The ClassFileTransformer wrapping AspectWerkz weaver
27: */
28: public static ClassFileTransformer s_transformer = new PreProcessorAdapter();
29:
30: /**
31: * JSR-163 preMain Agent entry method
32: */
33: public static void premain(String options,
34: Instrumentation instrumentation) {
35: s_instrumentation = instrumentation;
36: s_instrumentation.addTransformer(s_transformer);
37: }
38:
39: /**
40: * Returns the Instrumentation system level instance
41: */
42: public static Instrumentation getInstrumentation() {
43: if (s_instrumentation == null) {
44: throw new UnsupportedOperationException(
45: "Java 5 was not started with preMain -javaagent for AspectWerkz");
46: }
47: return s_instrumentation;
48: }
49:
50: }
|