01: /*
02: * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
03: * Distributed under the terms of either:
04: * - the common development and distribution license (CDDL), v1.0; or
05: * - the GNU Lesser General Public License, v2.1 or later
06: * $Id: MetaDataTransformer.java 3811 2007-06-25 15:06:16Z gbevin $
07: */
08: package com.uwyn.rife.instrument;
09:
10: import java.lang.instrument.IllegalClassFormatException;
11: import java.security.ProtectionDomain;
12:
13: import com.uwyn.rife.site.instrument.MetaDataBytecodeTransformer;
14:
15: /**
16: * This is a bytecode transformer that will modify classes so that they
17: * receive the functionalities that are required to support meta-data
18: * merging.
19: *
20: * @author Geert Bevin (gbevin[remove] at uwyn dot com)
21: * @version $Revision: 3811 $
22: * @since 1.6
23: */
24: public class MetaDataTransformer extends RifeTransformer {
25: public final static String META_DATA_SUFFIX = "MetaData";
26:
27: protected byte[] transformRife(ClassLoader loader,
28: String className, Class<?> classBeingRedefined,
29: ProtectionDomain protectionDomain, byte[] classfileBuffer)
30: throws IllegalClassFormatException {
31: if (!className.endsWith(META_DATA_SUFFIX)) {
32: String classname_dotted = className.replace('/', '.');
33: Class metadata_class = null;
34: try {
35: metadata_class = loader.loadClass(classname_dotted
36: + META_DATA_SUFFIX);
37: } catch (ClassNotFoundException e) {
38: metadata_class = null;
39: }
40:
41: if (metadata_class != null) {
42: byte[] result = MetaDataBytecodeTransformer
43: .mergeMetaDataIntoBytes(classfileBuffer,
44: metadata_class);
45: if (result != null) {
46: return result;
47: }
48: }
49: }
50:
51: return classfileBuffer;
52: }
53: }
|