1
2
3
4
5
6
7
8
9
10 package it.imolinfo.jbi4cics.typemapping.cobol;
11
12 import it.imolinfo.jbi4cics.Logger;
13 import it.imolinfo.jbi4cics.LoggerFactory;
14 import it.imolinfo.jbi4cics.exception.FormatException;
15 import it.imolinfo.jbi4cics.messageformat.FieldDescriptor;
16 import it.imolinfo.jbi4cics.messageformat.commarea.CommareaBeanMappingDescriptor;
17 import org.apache.commons.lang.builder.EqualsBuilder;
18 import org.apache.commons.lang.builder.HashCodeBuilder;
19 import org.apache.commons.lang.builder.ReflectionToStringBuilder;
20
21
22
23
24
25 public class CobolTypeDescriptor implements FieldDescriptor {
26
27
28
29
30
31 public final static int STRING_JUSTIFICATION_LEFT = 0;
32
33 public final static int STRING_JUSTIFICATION_RIGHT = 1;
34
35 public final static int STRING_JUSTIFICATION_CENTER = 2;
36
37
38
39
40
41 public final static int SIGN_FORMAT_LEADING = 0;
42
43 public final static int SIGN_FORMAT_TRAILING = 1;
44
45 public final static int SIGN_FORMAT_LEADING_SEPARATE = 2;
46
47
48
49
50
51 private static final Logger LOG
52 = LoggerFactory.getLogger(CobolTypeDescriptor.class);
53
54
55
56
57 private String name;
58
59
60
61
62 private CobolType type;
63
64
65
66
67
68
69 private int justification = STRING_JUSTIFICATION_LEFT;
70
71 private String padCharacter = " ";
72
73 private int stringLength;
74
75 private String codePage;
76
77
78
79
80
81 private boolean signed;
82
83
84
85
86
87 private boolean bigEndian;
88
89
90
91
92
93 private int integerPartLength;
94
95 private int decimalPartLength;
96
97
98
99
100
101 private int zonedSignFormat = SIGN_FORMAT_LEADING;
102
103
104
105
106
107 private int level;
108
109 private CommareaBeanMappingDescriptor nestedCommarea;
110
111
112
113
114
115 private int occursSize;
116
117
118
119
120
121 public CobolTypeDescriptor() {
122 }
123
124 @Override
125 public String toString() {
126 return ReflectionToStringBuilder.toString(this);
127 }
128
129 @Override
130 public boolean equals(Object obj) {
131 CobolTypeDescriptor that;
132
133 if (obj == this) {
134 return true;
135 }
136 if (!(obj instanceof CobolTypeDescriptor)) {
137 return false;
138 }
139 that = (CobolTypeDescriptor) obj;
140 return new EqualsBuilder().append(bigEndian, that.bigEndian)
141 .append(codePage, that.codePage)
142 .append(decimalPartLength, that.decimalPartLength)
143 .append(integerPartLength, that.integerPartLength)
144 .append(justification, that.justification)
145 .append(level, that.level)
146 .append(name, that.name)
147 .append(nestedCommarea, that.nestedCommarea)
148 .append(occursSize, that.occursSize)
149 .append(padCharacter, that.padCharacter)
150 .append(signed, that.signed)
151 .append(stringLength, that.stringLength)
152 .append(type, that.type)
153 .append(zonedSignFormat, that.zonedSignFormat).isEquals();
154 }
155
156 @Override
157 public int hashCode() {
158 return new HashCodeBuilder().append(bigEndian)
159 .append(codePage)
160 .append(decimalPartLength)
161 .append(integerPartLength)
162 .append(justification)
163 .append(level)
164 .append(name)
165 .append(nestedCommarea)
166 .append(occursSize)
167 .append(padCharacter)
168 .append(signed)
169 .append(stringLength)
170 .append(type)
171 .append(zonedSignFormat).toHashCode();
172 }
173
174
175
176
177
178
179 public int getLevel() {
180 return level;
181 }
182
183
184
185
186
187
188 public void setLevel(int level) {
189 this.level = level;
190 }
191
192
193
194
195 public boolean isSigned() {
196 return signed;
197 }
198
199
200
201
202
203 public void setSigned(boolean signed) {
204 this.signed = signed;
205 }
206
207
208
209
210 public int getJustification() {
211 return justification;
212 }
213
214
215
216
217
218 public void setJustification(int justification) {
219 this.justification = justification;
220 }
221
222
223
224
225 public String getPadCharacter() {
226 return padCharacter;
227 }
228
229
230
231
232
233 public void setPadCharacter(String padCharacter) {
234 this.padCharacter = padCharacter;
235 }
236
237
238
239
240 public int getDecimalPartLength() {
241 return decimalPartLength;
242 }
243
244
245
246
247
248 public void setDecimalPartLength(int decimalPartLength) {
249 this.decimalPartLength = decimalPartLength;
250 }
251
252
253
254
255 public int getIntegerPartLength() {
256 return integerPartLength;
257 }
258
259
260
261
262
263 public void setIntegerPartLength(int integerPartLength) {
264 this.integerPartLength = integerPartLength;
265 }
266
267
268
269
270 public int getStringLength() {
271 return stringLength;
272 }
273
274
275
276
277
278 public void setStringLength(int stringLength) {
279 this.stringLength = stringLength;
280 }
281
282
283
284
285 public CobolType getType() {
286 return type;
287 }
288
289
290
291
292
293 public void setType(CobolType type) {
294 this.type = type;
295 }
296
297
298
299
300 public int getVirtualDecimalPoint() {
301 return getDecimalPartLength();
302 }
303
304
305
306
307
308
309 public int getBufferedLength() throws FormatException {
310 CobolType ct = getType();
311
312 if (ct == null) {
313 LOG.error("CIC002110_Unknown_cobol_type", ct);
314 throw new FormatException("CIC002110_Unknown_cobol_type",
315 new Object[] { ct });
316 }
317 return ct.getBufferedLength(this);
318 }
319
320
321
322
323 public boolean isBigEndian() {
324 return bigEndian;
325 }
326
327
328
329
330
331 public void setBigEndian(boolean bigEndian) {
332 this.bigEndian = bigEndian;
333 }
334
335
336
337
338
339
340 public String getCodePage() {
341 return codePage;
342 }
343
344
345
346
347
348
349 public void setCodePage(String codePage) {
350 CobolType ct = getType();
351
352 this.codePage = codePage;
353 if ((ct == CobolType.NESTED_COMMAREA) || (ct == CobolType.OCCURS)) {
354 nestedCommarea.setCodePage(codePage);
355 }
356 }
357
358
359
360
361 public int getZonedSignFormat() {
362 return zonedSignFormat;
363 }
364
365
366
367
368
369 public void setZonedSignFormat(int zonedSignFormat) {
370 this.zonedSignFormat = zonedSignFormat;
371 }
372
373
374
375
376 public String getName() {
377 return name;
378 }
379
380
381
382
383
384 public void setName(String name) {
385 this.name = name;
386 }
387
388 public Class getPreferredJavaType() throws FormatException {
389 CobolType ct = getType();
390
391 if (ct == null) {
392 LOG.error("CIC002111_Unexpected_cobol_type", ct);
393 throw new FormatException("CIC002111_Unexpected_cobol_type",
394 new Object[] { ct });
395 }
396 return ct.getPreferredJavaType(this);
397 }
398
399 public CommareaBeanMappingDescriptor getNestedCommarea() {
400 return nestedCommarea;
401 }
402
403 public void setNestedCommarea(CommareaBeanMappingDescriptor nestedCommarea) {
404 this.nestedCommarea = nestedCommarea;
405 }
406
407 public int getOccursSize() {
408 return occursSize;
409 }
410
411 public void setOccursSize(int occursSize) {
412 this.occursSize = occursSize;
413 }
414 }