1
2
3
4
5
6
7
8 package it.imolinfo.jbi4ejb.webservice.generator.bcm;
9
10 import it.imolinfo.jbi4ejb.Logger;
11 import it.imolinfo.jbi4ejb.LoggerFactory;
12 import it.imolinfo.jbi4ejb.exception.ClassGenerationException;
13 import it.imolinfo.jbi4ejb.webservice.generator.EJBUtils;
14
15 import java.util.ArrayList;
16 import java.util.List;
17
18 import org.objectweb.asm.ClassAdapter;
19 import org.objectweb.asm.ClassVisitor;
20 import org.objectweb.asm.MethodVisitor;
21
22
23
24
25
26
27
28 public class RemoveEJBInterfaceAdapter extends ClassAdapter {
29
30
31 private static final Logger LOG
32 = LoggerFactory.getLogger(RemoveEJBInterfaceAdapter.class);
33
34
35 private String classesDirName = null;
36
37
38
39
40
41
42
43 public RemoveEJBInterfaceAdapter(ClassVisitor arg0, String classesDirName) {
44 super(arg0);
45 this.classesDirName = classesDirName;
46 }
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67 public void visit(int version, int access, String name, String signature,
68 String superName, String [] interfaces) {
69
70 LOG.debug("Removing java/rmi/Remote from the class: " + name);
71 List<String> newInterfaces = new ArrayList<String>();
72
73 if (interfaces != null) {
74 for (int i = 0; i < interfaces.length; i++) {
75 String newInterface = interfaces[i];
76
77 if (!(newInterface.equals("java/rmi/Remote")) && (!newInterface.equals("javax/ejb/EJBObject"))) {
78 newInterfaces.add(interfaces[i]);
79 }
80 }
81 }
82
83
84 for (int i = 0; i < newInterfaces.size(); i++) {
85 String interfaceClassname = newInterfaces.get(i).replace('/', '.');
86 try {
87 EJBUtils.removeEJBRemoteInterface(interfaceClassname, classesDirName);
88 } catch (ClassGenerationException e) {
89
90 String msg = "Error in removing java.rmi.Remote from interface " + e.getMessage();
91 LOG.warn(msg, e);
92 }
93 }
94
95 String[] newInterfacesArray = newInterfaces.toArray(new String[0]);
96
97 super.visit(version, access, name, signature, superName, newInterfacesArray);
98 }
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123 public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
124
125 List<String> newExceptions = new ArrayList<String>();
126
127 if (exceptions != null) {
128 for (int i = 0; i < exceptions.length; i++) {
129 String exception = exceptions[i];
130
131 if (!(exception.equals("java/rmi/RemoteException")) && (!(exception.equals("javax/ejb/EJBException")))) {
132 newExceptions.add(exceptions[i]);
133 } else {
134 LOG.debug("Removing java/rmi/RemoteException from the method: " + name);
135 }
136 }
137 }
138 String[] newExceptionsArray = newExceptions.toArray(new String[0]);
139 return super.visitMethod(access, name, desc, signature, newExceptionsArray);
140 }
141
142 }
143
144