KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > codehaus > aspectwerkz > extension > hotswap > HotSwapClient


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 BSD-style license *
6  * a copy of which has been included with this distribution in the license.txt file. *
7  **************************************************************************************/

8 package org.codehaus.aspectwerkz.extension.hotswap;
9
10 import org.codehaus.aspectwerkz.hook.impl.ClassPreProcessorHelper;
11 import org.codehaus.aspectwerkz.exception.WrappedRuntimeException;
12
13 /**
14  * In process HotSwap - Java level API <p/>When used, the hook* classes (AspectWerkz - core) MUST be
15  * in bootclasspath to ensure correct behavior and lookup of the ClassPreProcessor singleton
16  *
17  * @author <a HREF="mailto:alex@gnilux.com">Alexandre Vasseur </a>
18  */

19 public class HotSwapClient {
20
21     static {
22         System.loadLibrary("aspectwerkz");
23     }
24
25     /**
26      * Native method to calls the JVM C level API
27      *
28      * @param className
29      * @param klazz
30      * @param newBytes
31      * @param newLength
32      * @return
33      */

34     private static native int hotswap(String JavaDoc className, Class JavaDoc klazz, byte[] newBytes, int newLength);
35
36     /**
37      * In process hotswap
38      *
39      * @param klazz
40      * @param newBytes
41      */

42     public static void hotswap(final Class JavaDoc klazz, final byte[] newBytes) {
43         int code = hotswap(klazz.getName(), klazz, newBytes, newBytes.length);
44         if (code != 0) {
45             throw new RuntimeException JavaDoc("HotSwap failed for " + klazz.getName() + ": " + code);
46         }
47     }
48
49 }
Popular Tags