KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > codehaus > aspectwerkz > hook > Agent


1 /**************************************************************************************
2  * Copyright (c) Jonas Bonér, Alexandre Vasseur. All rights reserved. *
3  * http://aspectwerkz.codehaus.org *
4  * ---------------------------------------------------------------------------------- *
5  * The software in this package is published under the terms of the LGPL license *
6  * a copy of which has been included with this distribution in the license.txt file. *
7  **************************************************************************************/

8 package org.codehaus.aspectwerkz.hook;
9
10 import java.lang.instrument.Instrumentation JavaDoc;
11 import java.lang.instrument.ClassFileTransformer JavaDoc;
12
13 /**
14  * Java 1.5 preMain agent
15  * Can be used with -javaagent:aspectwerkz-core-XXX.jar
16  *
17  * @author <a HREF="mailto:alex@gnilux.com">Alexandre Vasseur</a>
18  */

19 public class Agent {
20
21     /**
22      * The instrumentation instance
23      */

24     private static Instrumentation JavaDoc s_instrumentation;
25
26     /**
27      * The ClassFileTransformer wrapping AspectWerkz weaver
28      */

29     public static ClassFileTransformer JavaDoc s_transformer = new PreProcessorAdapter();
30
31     /**
32      * JSR-163 preMain Agent entry method
33      */

34     public static void premain(String JavaDoc options, Instrumentation JavaDoc 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 JavaDoc getInstrumentation() {
43         if (s_instrumentation == null) {
44             throw new UnsupportedOperationException JavaDoc("Java 5 was not started with preMain -javaagent for AspectWerkz");
45         }
46         return s_instrumentation;
47     }
48
49 }
50
Popular Tags