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 java.util.ArrayList;
13 import java.util.List;
14
15
16 import org.objectweb.asm.ClassAdapter;
17 import org.objectweb.asm.ClassVisitor;
18 import org.objectweb.asm.FieldVisitor;
19 import org.objectweb.asm.Opcodes;
20
21
22
23
24 public class CorbaEnumAdapter extends ClassAdapter {
25
26
27 private static final Logger LOG
28 = LoggerFactory.getLogger(CorbaEnumAdapter.class);
29
30
31 private String internalClassName = null;
32
33
34 private boolean corbaEnum = false;
35
36
37 private List<String> enumLabelList = new ArrayList<String>();
38
39
40
41
42
43
44
45 public CorbaEnumAdapter(ClassVisitor cv) {
46 super(cv);
47
48 LOG.debug("new CorbaEnumAdapter; ClassVisitor=" + cv);
49 }
50
51
52
53
54
55
56
57
58
59
60 @Override
61 public void visit(int version,
62 int access,
63 String name,
64 String signature,
65 String superName,
66 String [] interfaces) {
67 LOG.debug(">>>>> visit - begin");
68
69 LOG.debug("VISIT"
70 + ".\n version=" + version
71 + ";\n access=" + access
72 + ";\n name=" + name
73 + ";\n signature=" + signature
74 + ";\n superName=" + superName
75 + ";\n interfaces=" + interfaces);
76
77 setInternalClassName(name);
78
79 super.visit(version, access, name, signature, superName, interfaces);
80 }
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104 @Override
105 public FieldVisitor visitField(int access,
106 String name,
107 String desc,
108 String signature,
109 Object value) {
110
111 LOG.debug(">>>>> visitField - begin. access=" + access
112 + "; name=" + name
113 + "; desc=" + desc
114 + "; signature=" + signature
115 + "; value=" + value);
116
117 int __arrayFieldAccess = Opcodes.ACC_PRIVATE + Opcodes.ACC_STATIC;
118 String __arrayFieldDesc = "[L" + getInternalClassName() + ";";
119
120 if ("__array".equals(name)
121 && (__arrayFieldAccess == access) && (__arrayFieldDesc.equals(desc))) {
122
123 LOG.debug("The class " + getInternalClassName() + " is a CorbaEnum.");
124 setCorbaEnum(true);
125
126 } else {
127 checkLabel(access, name, desc);
128 }
129
130 return super.visitField(access, name, desc, signature, value);
131 }
132
133
134
135
136
137
138
139
140
141 protected void checkLabel(int access, String name, String desc) {
142
143 int labelAccess = Opcodes.ACC_PUBLIC
144 + Opcodes.ACC_STATIC
145 + Opcodes.ACC_FINAL;
146
147 String labelDesc = "L" + getInternalClassName() + ";";
148
149 if (labelAccess == access && labelDesc.equals(desc)) {
150 LOG.debug("The field " + name + " is a label of the enumeration.");
151 getEnumLabelList().add(name);
152 }
153
154 }
155
156
157
158
159
160 public List<String> getEnumLabelList() {
161 return enumLabelList;
162 }
163
164
165
166
167
168 public void setEnumLabelList(List<String> val) {
169 this.enumLabelList = val;
170 }
171
172
173
174
175
176 public boolean isCorbaEnum() {
177 return corbaEnum;
178 }
179
180
181
182
183
184 public void setCorbaEnum(boolean val) {
185 this.corbaEnum = val;
186 }
187
188
189
190
191
192 public String getInternalClassName() {
193 return internalClassName;
194 }
195
196
197
198
199
200 public void setInternalClassName(String val) {
201 this.internalClassName = val;
202 }
203
204 }