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 org.codehaus.aspectwerkz.hook.impl.ClassPreProcessorHelper;
10:
11: import java.lang.instrument.IllegalClassFormatException;
12: import java.lang.instrument.ClassFileTransformer;
13: import java.security.ProtectionDomain;
14:
15: /**
16: * Java 1.5 adapter for load time weaving
17: *
18: * @author <a href="mailto:alex@gnilux.com">Alexandre Vasseur</a>
19: */
20: public class PreProcessorAdapter implements ClassFileTransformer {
21:
22: /**
23: * Concrete AspectWerkz preprocessor.
24: */
25: private static ClassPreProcessor s_preProcessor;
26:
27: static {
28: try {
29: s_preProcessor = ClassPreProcessorHelper
30: .getClassPreProcessor();
31: } catch (Exception e) {
32: throw new ExceptionInInitializerError(
33: "could not initialize JSR163 preprocessor due to: "
34: + e.toString());
35: }
36: }
37:
38: /**
39: * Weaving delegation
40: *
41: * @param loader the defining class loader
42: * @param className the name of class beeing loaded
43: * @param classBeingRedefined when hotswap is called
44: * @param protectionDomain
45: * @param bytes the bytecode before weaving
46: * @return the weaved bytecode
47: */
48: public byte[] transform(ClassLoader loader, String className,
49: Class<?> classBeingRedefined,
50: ProtectionDomain protectionDomain, byte[] bytes)
51: throws IllegalClassFormatException {
52: // TODO: do we really have to skip hotswap ?
53: if (classBeingRedefined == null) {
54: return s_preProcessor.preProcess(className, bytes, loader);
55: } else {
56: //return s_preProcessor.preProcess(className, bytes, loader);
57: return bytes;
58: }
59: }
60:
61: }
|