1
2
3
4
5
6
7
8
9 package it.imolinfo.jbi4corba.webservice.generator.bcm;
10
11 import it.imolinfo.jbi4corba.Logger;
12 import it.imolinfo.jbi4corba.LoggerFactory;
13
14 import java.util.HashMap;
15 import java.util.Map;
16
17 import org.objectweb.asm.ClassAdapter;
18 import org.objectweb.asm.ClassVisitor;
19 import org.objectweb.asm.ClassWriter;
20 import org.objectweb.asm.FieldVisitor;
21 import org.objectweb.asm.Opcodes;
22
23
24
25
26
27
28
29
30 public class WsdlToCorbaAdapter extends ClassAdapter {
31
32
33
34
35 private static final Logger LOG
36 = LoggerFactory.getLogger(WsdlToCorbaAdapter.class);
37
38
39 protected String classesDirName = null;
40 protected String className = null;
41 protected ClassWriter classWriter = null;
42
43 protected Map<String, String> mapOfFields = new HashMap<String, String>();
44
45
46
47
48 private ByteCodeManipulationUtil bcmUtil = new ByteCodeManipulationUtil();
49
50
51
52
53
54
55
56
57
58
59 public WsdlToCorbaAdapter(ClassVisitor cv,
60 ClassWriter cw,
61 String cn,
62 String classes) {
63 super(cv);
64
65 classesDirName = classes;
66 classWriter = cw;
67 className = cn;
68
69 LOG.debug("new WsdlToCorbaAdapter; ClassVisitor=" + cv
70 + "; ClassWriter=" + cw
71 + "; ClassName=" + cn);
72 }
73
74
75
76
77
78
79
80
81
82
83 @Override
84 public void visit(int version,
85 int access,
86 String name,
87 String signature,
88 String superName,
89 String [] interfaces) {
90 LOG.debug(">>>>> visit - begin");
91
92 LOG.debug("VISIT"
93 + ".\n version=" + version
94 + ";\n access=" + access
95 + ";\n name=" + name
96 + ";\n signature=" + signature
97 + ";\n superName=" + superName
98 + ";\n interfaces=" + interfaces
99 + ".\n abstract-code=" + Opcodes.ACC_ABSTRACT
100 + ".\n (Opcodes.ACC_ABSTRACT & access)="
101 + (Opcodes.ACC_ABSTRACT & access)
102 + ".\n access & (~ Opcodes.ACC_ABSTRACT)="
103 + (access & (~ Opcodes.ACC_ABSTRACT)));
104
105
106
107
108 LOG.debug("This class (" + name + ") was an abstract "
109 + "... now is a concrete class.");
110
111 LOG.debug("<<<<< visit - end");
112 super.visit(version, access, name, signature, superName, interfaces);
113 }
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137 @Override
138 public FieldVisitor visitField(
139 int access,
140 String name,
141 String desc,
142 String signature,
143 Object value) {
144
145 LOG.debug(">>>>> visitField - begin:" + desc);
146
147 LOG.debug("visitField. access=" + access
148 + "; name=" + name
149 + "; desc=" + desc
150 + "; signature=" + signature
151 + "; value=" + value);
152
153 if (Opcodes.ACC_PUBLIC == access || Opcodes.ACC_PROTECTED == access) {
154
155
156
157 mapOfFields.put(name, desc);
158 }
159 LOG.debug("<<<<< visitField - end");
160
161
162 return super.visitField(Opcodes.ACC_PROTECTED, name, desc, signature, value);
163 }
164
165
166
167
168 @Override
169 public void visitEnd() {
170
171 for (String name : mapOfFields.keySet()) {
172 String desc = mapOfFields.get(name);
173
174
175 bcmUtil.createSetter(classWriter,getClassNameWithoutClassesDir(), name, desc);
176 bcmUtil.createGetter(classWriter,getClassNameWithoutClassesDir(), name, desc, false);
177 }
178
179 bcmUtil.createToString(classWriter);
180 bcmUtil.createEquals(classWriter);
181
182 super.visitEnd();
183 }
184
185
186
187
188 public String getClassNameWithoutClassesDir() {
189 String c = className.substring(
190 classesDirName.length() + 1,
191 className.length());
192
193 LOG.debug("###### getClassNameWithoutClassesDir=" + c);
194 return c;
195 }
196
197 }