01: /*
02: * Copyright 2002-2006 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: package org.springframework.instrument.classloading.glassfish;
18:
19: import java.lang.instrument.ClassFileTransformer;
20: import java.lang.instrument.IllegalClassFormatException;
21: import java.security.ProtectionDomain;
22:
23: import javax.persistence.spi.ClassTransformer;
24:
25: /**
26: * Adapter that implements the JPA ClassTransformer interface (as required by GlassFish)
27: * based on a given JDK 1.5 ClassFileTransformer.
28: *
29: * @author Costin Leau
30: * @author Juergen Hoeller
31: * @since 2.0.1
32: */
33: class ClassTransformerAdapter implements ClassTransformer {
34:
35: private final ClassFileTransformer classFileTransformer;
36:
37: /**
38: * Build a new ClassTransformerAdapter for the given ClassFileTransformer.
39: * @param classFileTransformer the JDK 1.5 ClassFileTransformer to wrap
40: */
41: public ClassTransformerAdapter(
42: ClassFileTransformer classFileTransformer) {
43: this .classFileTransformer = classFileTransformer;
44: }
45:
46: public byte[] transform(ClassLoader loader, String className,
47: Class<?> classBeingRedefined,
48: ProtectionDomain protectionDomain, byte[] classfileBuffer)
49: throws IllegalClassFormatException {
50:
51: byte[] result = this .classFileTransformer.transform(loader,
52: className, classBeingRedefined, protectionDomain,
53: classfileBuffer);
54:
55: // If no transformation was done, return null.
56: return (result == classfileBuffer ? null : result);
57: }
58:
59: }
|