1
2
3
4
5
6
7
8
9
10
11 package com.legstar.coxb.impl;
12
13 import com.legstar.coxb.CobolElement;
14 import com.legstar.coxb.CobolType;
15 import com.legstar.coxb.ICobolComplexBinding;
16 import com.legstar.coxb.ICobolStringBinding;
17 import com.legstar.coxb.CobolElementVisitor;
18 import com.legstar.coxb.host.HostException;
19 import com.legstar.coxb.util.PictureUtil;
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 public class CStringBinding extends AbstractAlphaNumericBinding
35 implements ICobolStringBinding {
36
37
38
39
40
41
42
43
44
45
46 public CStringBinding(
47 final String bindingName,
48 final String jaxbName,
49 final Class < ? > jaxbType,
50 final CobolElement cobolAnnotations,
51 final ICobolComplexBinding parentBinding) {
52 super(bindingName, jaxbName, jaxbType, cobolAnnotations, parentBinding);
53 }
54
55
56 public void accept(final CobolElementVisitor cev)
57 throws HostException {
58 cev.visit(this);
59 }
60
61
62 public int calcByteLength() {
63 return calcStringByteLength(getPicture(), getCobolType());
64 }
65
66
67
68
69
70
71
72 public static int calcStringByteLength(
73 final String picture, final CobolType cobolType) {
74 switch (cobolType) {
75 case ALPHABETIC_ITEM:
76 return PictureUtil.getSymbolsNumber(
77 new char[] {'A'}, picture);
78 case ALPHANUMERIC_ITEM:
79 return PictureUtil.getSymbolsNumber(
80 new char[] {'A', 'X', '9'}, picture);
81 case ALPHANUMERIC_EDITED_ITEM:
82 return PictureUtil.getSymbolsNumber(
83 new char[] {'A', 'X', '9', 'B', '0', '/'}, picture);
84 case EXTERNAL_FLOATING_ITEM:
85 return PictureUtil.getSymbolsNumber(
86 new char[] {'+', '-', '9', '.', 'E'}, picture);
87 case NUMERIC_EDITED_ITEM:
88 int count = 0;
89 String strippedPicture = picture;
90
91
92
93
94 int idx = picture.indexOf("CR");
95 if (idx > -1) {
96
97 count += 2;
98 strippedPicture = strippedPicture.replaceFirst("CR", "");
99 }
100 idx = picture.indexOf("DB");
101 if (idx > -1) {
102
103 count += 2;
104 strippedPicture = strippedPicture.replaceFirst("DB", "");
105 }
106
107
108 count += PictureUtil.getSymbolsNumber(new char[] { 'B', 'Z', '9',
109 '0', ',', '.', '-', '+', '/', '*', '$' }, strippedPicture);
110
111 return count;
112 default:
113 return PictureUtil.getSymbolsNumber(new char[] { 'X' }, picture);
114 }
115 }
116
117 }