|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| |
|
17 |
| |
|
18 |
| |
|
19 |
| |
|
20 |
| |
|
21 |
| |
|
22 |
| |
|
23 |
| |
|
24 |
| |
|
25 |
| package org.objectweb.easybeans.tests.common.enhancer; |
|
26 |
| |
|
27 |
| import java.io.InputStream; |
|
28 |
| import java.net.URL; |
|
29 |
| import java.net.URLClassLoader; |
|
30 |
| import java.util.List; |
|
31 |
| |
|
32 |
| import org.objectweb.asm.ClassReader; |
|
33 |
| import org.objectweb.easybeans.deployment.annotations.analyzer.ScanClassVisitor; |
|
34 |
| import org.objectweb.easybeans.deployment.annotations.helper.ResolverHelper; |
|
35 |
| import org.objectweb.easybeans.deployment.annotations.metadata.ClassAnnotationMetadata; |
|
36 |
| import org.objectweb.easybeans.deployment.annotations.metadata.EjbJarAnnotationMetadata; |
|
37 |
| import org.objectweb.easybeans.deployment.annotations.metadata.MethodAnnotationMetadata; |
|
38 |
| import org.objectweb.easybeans.enhancer.Enhancer; |
|
39 |
| |
|
40 |
| |
|
41 |
| |
|
42 |
| |
|
43 |
| |
|
44 |
| |
|
45 |
| |
|
46 |
| public final class ClassesEnhancer extends Enhancer { |
|
47 |
| |
|
48 |
| |
|
49 |
| |
|
50 |
| |
|
51 |
| public static enum TYPE {INTERCEPTOR, CALLBACK, ALL} |
|
52 |
| |
|
53 |
| |
|
54 |
| |
|
55 |
| |
|
56 |
| public static final String EXT_CLASS = ".class"; |
|
57 |
| |
|
58 |
| |
|
59 |
| |
|
60 |
| |
|
61 |
| |
|
62 |
| |
|
63 |
7
| public ClassesEnhancer(final ClassLoader loader, final EjbJarAnnotationMetadata ejbJarAnnotationMetadata) {
|
|
64 |
7
| super(loader, ejbJarAnnotationMetadata, null);
|
|
65 |
| } |
|
66 |
| |
|
67 |
| |
|
68 |
| |
|
69 |
| |
|
70 |
| |
|
71 |
| |
|
72 |
| |
|
73 |
21
| public static void enhanceNewClassLoader(final List<String> classesToEnhance, final TYPE type) throws Exception {
|
|
74 |
21
| ClassLoader loader = Thread.currentThread().getContextClassLoader();
|
|
75 |
21
| ClassLoader childLoader = new URLClassLoader(new URL[]{}, loader);
|
|
76 |
21
| Thread.currentThread().setContextClassLoader(childLoader);
|
|
77 |
21
| try{
|
|
78 |
21
| enhance(classesToEnhance, TYPE.INTERCEPTOR);
|
|
79 |
| }finally{ |
|
80 |
21
| Thread.currentThread().setContextClassLoader(loader);
|
|
81 |
| } |
|
82 |
| } |
|
83 |
| |
|
84 |
| |
|
85 |
| |
|
86 |
| |
|
87 |
| |
|
88 |
| |
|
89 |
| |
|
90 |
25
| public static void enhance(final List<String> classesToEnhance, final TYPE type) throws Exception {
|
|
91 |
25
| EjbJarAnnotationMetadata ejbJarAnnotationMetadata = new EjbJarAnnotationMetadata();
|
|
92 |
25
| ScanClassVisitor scanVisitor = new ScanClassVisitor(ejbJarAnnotationMetadata);
|
|
93 |
25
| ClassLoader loader = Thread.currentThread().getContextClassLoader();
|
|
94 |
| |
|
95 |
25
| InputStream is = null;
|
|
96 |
25
| for (String clazz : classesToEnhance) {
|
|
97 |
80
| is = loader.getResourceAsStream(clazz);
|
|
98 |
80
| new ClassReader(is).accept(scanVisitor, false);
|
|
99 |
| } |
|
100 |
| |
|
101 |
25
| ResolverHelper.resolve(ejbJarAnnotationMetadata);
|
|
102 |
| |
|
103 |
| |
|
104 |
| |
|
105 |
7
| for (ClassAnnotationMetadata classAnnotationMetadata : ejbJarAnnotationMetadata
|
|
106 |
| .getClassAnnotationMetadataCollection()) { |
|
107 |
34
| if (classAnnotationMetadata.isBean()) {
|
|
108 |
| |
|
109 |
13
| classAnnotationMetadata.setGlobalEasyBeansInterceptors(null);
|
|
110 |
13
| for (MethodAnnotationMetadata m : classAnnotationMetadata.getMethodAnnotationMetadataCollection()) {
|
|
111 |
153
| m.setInterceptors(null);
|
|
112 |
| } |
|
113 |
| } |
|
114 |
| } |
|
115 |
| |
|
116 |
7
| ClassesEnhancer classesEnhancer = new ClassesEnhancer(loader, ejbJarAnnotationMetadata);
|
|
117 |
7
| classesEnhancer.enhance();
|
|
118 |
| } |
|
119 |
| |
|
120 |
| } |