KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.codehaus.aspectwerkz.hook.impl.ClassPreProcessorHelper;
11
12 import java.lang.instrument.IllegalClassFormatException JavaDoc;
13 import java.lang.instrument.ClassFileTransformer JavaDoc;
14 import java.security.ProtectionDomain JavaDoc;
15
16 /**
17  * Java 1.5 adapter for load time weaving
18  *
19  * @author <a HREF="mailto:alex@gnilux.com">Alexandre Vasseur</a>
20  */

21 public class PreProcessorAdapter implements ClassFileTransformer JavaDoc {
22
23     /**
24      * Concrete AspectWerkz preprocessor.
25      */

26     private static ClassPreProcessor s_preProcessor;
27
28     static {
29         try {
30             s_preProcessor = ClassPreProcessorHelper.getClassPreProcessor();
31         } catch (Exception JavaDoc e) {
32             throw new ExceptionInInitializerError JavaDoc("could not initialize JSR163 preprocessor due to: " + e.toString());
33         }
34     }
35
36     /**
37      * Weaving delegation
38      *
39      * @param loader the defining class loader
40      * @param className the name of class beeing loaded
41      * @param classBeingRedefined when hotswap is called
42      * @param protectionDomain
43      * @param bytes the bytecode before weaving
44      * @return the weaved bytecode
45      */

46     public byte[] transform(ClassLoader JavaDoc loader, String JavaDoc className, Class JavaDoc<?> classBeingRedefined,
47                             ProtectionDomain JavaDoc protectionDomain, byte[] bytes) throws IllegalClassFormatException JavaDoc {
48         // TODO: do we really have to skip hotswap ?
49
if (classBeingRedefined == null) {
50             return s_preProcessor.preProcess(className, bytes, loader);
51         } else {
52             //return s_preProcessor.preProcess(className, bytes, loader);
53
return bytes;
54         }
55     }
56
57 }
58
Popular Tags