1
2
3
4
5
6
7
8 package it.imolinfo.jbi4corba.webservice.generator.bcm;
9
10 import it.imolinfo.jbi4corba.Logger;
11 import it.imolinfo.jbi4corba.LoggerFactory;
12 import it.imolinfo.jbi4corba.webservice.generator.InterfaceType;
13 import it.imolinfo.jbi4corba.webservice.generator.TypeUtils;
14
15 import java.util.HashMap;
16 import java.util.Map;
17
18 import org.objectweb.asm.ClassAdapter;
19 import org.objectweb.asm.ClassVisitor;
20 import org.objectweb.asm.ClassWriter;
21 import org.objectweb.asm.MethodVisitor;
22 import org.objectweb.asm.Type;
23
24
25
26
27 public class ConstructorAdapter extends ClassAdapter {
28
29
30
31
32 private static final Logger LOG = LoggerFactory
33 .getLogger(ConstructorAdapter.class);
34
35 protected String className = null;
36
37 protected ClassWriter classWriter = null;
38
39 protected Map<String, String> mapOfFields = new HashMap<String, String>();
40
41
42
43
44 private Map<String, InterfaceType> allInterfaceTypes;
45
46
47
48
49
50
51
52
53
54
55
56 public ConstructorAdapter(ClassVisitor cv, ClassWriter cw, String cn,
57 Map<String, InterfaceType> allInTypes, boolean isEx) {
58
59 super(cv);
60
61 classWriter = cw;
62 className = cn;
63
64 allInterfaceTypes = allInTypes;
65
66 LOG.debug("CRB000604_new_GetterSetterAdapter", new Object[] { cv, cw,
67 cn, isEx });
68 }
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87 @Override
88 public void visit(int version, int access, String name, String signature,
89 String superName, String[] interfaces) {
90 LOG.debug(">>>>> visit - begin");
91
92 LOG.debug("CRB000603_VISIT", new Object[] { version, access, name,
93 signature, superName, interfaces });
94
95 super.visit(version, access, name, signature, superName, interfaces);
96
97 }
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114 @Override
115 public MethodVisitor visitMethod(int access, String name, String desc,
116 String signature, String[] exceptions) {
117
118 LOG.debug(">>>>> visitMethod - begin");
119
120 LOG.debug("visitMethod. access=" + access + "; name=" + name
121 + "; desc=" + desc + "; signature=" + signature
122 + "; exceptions=" + exceptions);
123
124
125 if ("<init>".equals(name)) {
126
127 LOG.debug("default constructor modifications.");
128
129 desc = changeInterfaceTypeDesc(desc);
130
131 ConstructorModMethodVisitor mv = new ConstructorModMethodVisitor(
132 super
133 .visitMethod(access, name, desc, signature,
134 exceptions), className, allInterfaceTypes);
135
136 LOG.debug("<<<<< visitMethod - end. Constructor MethodVisitor="
137 + mv);
138
139 return mv;
140
141 }
142
143
144 LOG.debug("<<<<< visitMethod - end. " + "methodName=" + name
145 + "; methodDescription=" + desc);
146 return super.visitMethod(access, name, desc, signature, exceptions);
147 }
148
149
150
151
152
153
154
155
156 private String changeInterfaceTypeDesc(String desc) {
157
158
159
160 int start = desc.indexOf("(");
161 int end = desc.lastIndexOf(")");
162
163 String descStart = desc.substring(0, start + 1);
164 String descEnd = desc.substring(end, desc.length());
165
166 InternalMethodDescriptionParser parser = new InternalMethodDescriptionParser(
167 desc);
168 String params[] = parser.parse().toArray(new String[] {});
169 String result = descStart;
170
171 for (int i = 0; i < params.length; i++) {
172 boolean isArray = TypeUtils.isArray(params[i]);
173 if (TypeUtils.isSearchedType(params[i], isArray,
174 allInterfaceTypes, TypeUtils.INTERFACE) != null) {
175
176 if (isArray) {
177 result += Type
178 .getDescriptor(javax.xml.ws.wsaddressing.W3CEndpointReference[].class);
179 } else {
180 result += Type
181 .getDescriptor(javax.xml.ws.wsaddressing.W3CEndpointReference.class);
182 }
183
184 } else {
185 result += params[i];
186 }
187 }
188 result += descEnd;
189 return result;
190
191 }
192
193 @Override
194 public void visitEnd() {
195
196 super.visitEnd();
197 }
198
199 }