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.jbi.Messages;
13 import it.imolinfo.jbi4ejb.webservice.generator.DynamicEJBWSDLGenerator;
14
15 import java.lang.reflect.Method;
16 import java.util.ArrayList;
17 import java.util.List;
18
19 import org.objectweb.asm.ClassAdapter;
20 import org.objectweb.asm.ClassVisitor;
21 import org.objectweb.asm.MethodVisitor;
22
23
24
25
26
27
28
29 public class RemoteInterfaceExceptionAdapter extends ClassAdapter {
30
31
32 private static final Logger LOG
33 = LoggerFactory.getLogger(RemoteInterfaceExceptionAdapter.class);
34 private static final Messages MESSAGES
35 = Messages.getMessages(RemoteInterfaceExceptionAdapter.class);
36
37
38 private final ClassLoader classLoader;
39
40
41 private final List<String> exceptionsAdded = new ArrayList<String>();
42
43
44
45
46
47
48
49
50
51 public RemoteInterfaceExceptionAdapter(ClassVisitor arg0, ClassLoader classLoader) {
52 super(arg0);
53 this.classLoader = classLoader;
54 }
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78 @SuppressWarnings("unchecked")
79 public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
80
81
82 List<String> newExceptions = new ArrayList<String>();
83
84 if (exceptions != null) {
85 for (int i = 0; i < exceptions.length; i++) {
86
87 String exception = exceptions[i];
88 String exceptionName = exception.replace('/', '.');
89 LOG.debug("Exception found in method " + name + ": "+ exceptionName);
90
91 Class myExceptionClass = null;
92 try {
93 myExceptionClass = classLoader.loadClass(exceptionName);
94 } catch (ClassNotFoundException e) {
95 LOG.warn("EJB001101_Exception_in_rethrowing_exception", new Object[]{e.getMessage()});
96 }
97
98 if (myExceptionClass != null) {
99
100 if (myExceptionClass.getGenericSuperclass().equals(org.codehaus.xfire.fault.FaultInfoException.class)) {
101 LOG.debug("The exception: " + exceptionName + " is a FaultInfoException");
102 }
103 Method getFaultInfoMethod = null;
104 try {
105
106 getFaultInfoMethod = myExceptionClass.getMethod("getFaultInfo", new Class[]{});
107 } catch (SecurityException e) {
108 LOG.warn("EJB001101_Exception_in_rethrowing_exception", new Object[]{e.getMessage()});
109 } catch (NoSuchMethodException e) {
110 LOG.warn("EJB001101_Exception_in_rethrowing_exception", new Object[]{e.getMessage()});
111 }
112 if (getFaultInfoMethod != null) {
113 Class returnType = getFaultInfoMethod.getReturnType();
114 String exceptionInternalName = returnType.getName().replace('.', '/');
115
116 newExceptions.add(exceptionInternalName);
117
118 if (!exceptionsAdded.contains(returnType.getName())) {
119 exceptionsAdded.add(returnType.getName());
120 }
121 }
122 }
123 }
124 }
125
126 String[] newExceptionsArray = newExceptions.toArray(new String[0]);
127 for (int i = 0; i < newExceptionsArray.length; i++) {
128 LOG.debug("modifiying the method " + name + " with the exception: " + newExceptionsArray[i]);
129 }
130
131 return super.visitMethod(access, name, desc, signature, newExceptionsArray);
132 }
133
134
135
136
137
138
139
140 public List<String> getExceptionsAdded() {
141 return exceptionsAdded;
142 }
143
144
145 }
146
147