01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */package org.apache.geronimo.persistence;
17:
18: import java.lang.instrument.ClassFileTransformer;
19: import java.lang.instrument.IllegalClassFormatException;
20: import java.security.ProtectionDomain;
21:
22: import javax.persistence.spi.ClassTransformer;
23:
24: /**
25: * @version $Rev: 476049 $ $Date: 2006-11-16 20:35:17 -0800 (Thu, 16 Nov 2006) $
26: */
27: public class TransformerWrapper implements ClassFileTransformer {
28:
29: private final ClassTransformer classTransformer;
30: private final ClassLoader classLoader;
31:
32: public TransformerWrapper(ClassTransformer classTransformer,
33: ClassLoader classLoader) {
34: this .classTransformer = classTransformer;
35: this .classLoader = classLoader;
36: }
37:
38: public byte[] transform(ClassLoader loader, String className,
39: Class<?> classBeingRedefined,
40: ProtectionDomain protectionDomain, byte[] classfileBuffer)
41: throws IllegalClassFormatException {
42: if (loader != classLoader) {
43: return null;
44: }
45: try {
46: return classTransformer.transform(loader, className,
47: classBeingRedefined, protectionDomain,
48: classfileBuffer);
49: } catch (IllegalClassFormatException e) {
50: throw e;
51: } catch (RuntimeException e) {
52: return null;
53: }
54: }
55: }
|