1
2
3
4
5
6
7
8
9
10
11 package com.legstar.coxb.impl;
12
13 import java.math.BigDecimal;
14 import java.math.BigInteger;
15 import java.util.ArrayList;
16 import java.util.List;
17
18 import com.legstar.coxb.CobolElement;
19 import com.legstar.coxb.ICobolComplexBinding;
20 import com.legstar.coxb.common.CArrayBinding;
21 import com.legstar.coxb.host.HostException;
22
23
24
25
26
27 public abstract class AbstractArrayNumericBinding extends CArrayBinding {
28
29
30 private List < BigDecimal > mList = null;
31
32
33
34
35
36
37
38
39
40
41 public AbstractArrayNumericBinding(final String bindingName,
42 final String jaxbName, final Class < ? > jaxbType,
43 final CobolElement cobolAnnotations,
44 final ICobolComplexBinding parentBinding) {
45 super(bindingName, jaxbName, jaxbType, cobolAnnotations, parentBinding);
46 }
47
48
49
50
51 public List < Byte > getByteList() {
52 List < Byte > list = new ArrayList < Byte >();
53 for (BigDecimal value : mList) {
54 list.add(value.byteValue());
55 }
56 return list;
57 }
58
59
60
61
62 public void setByteList(final List < Byte > list) {
63 mList = new ArrayList < BigDecimal >();
64 for (Byte value : list) {
65 mList.add(new BigDecimal(value));
66 }
67 }
68
69
70
71
72 public List < Short > getShortList() {
73 List < Short > list = new ArrayList < Short >();
74 for (BigDecimal value : mList) {
75 list.add(value.shortValue());
76 }
77 return list;
78 }
79
80
81
82
83 public void setShortList(final List < Short > list) {
84 mList = new ArrayList < BigDecimal >();
85 for (Short value : list) {
86 mList.add(new BigDecimal(value));
87 }
88 }
89
90
91
92
93 public List < Integer > getIntegerList() {
94 List < Integer > list = new ArrayList < Integer >();
95 for (BigDecimal value : mList) {
96 list.add(value.intValue());
97 }
98 return list;
99 }
100
101
102
103
104 public void setIntegerList(final List < Integer > list) {
105 mList = new ArrayList < BigDecimal >();
106 for (Integer value : list) {
107 mList.add(new BigDecimal(value));
108 }
109 }
110
111
112
113
114 public List < Long > getLongList() {
115 List < Long > list = new ArrayList < Long >();
116 for (BigDecimal value : mList) {
117 list.add(value.longValue());
118 }
119 return list;
120 }
121
122
123
124
125 public void setLongList(final List < Long > list) {
126 mList = new ArrayList < BigDecimal >();
127 for (Long value : list) {
128 mList.add(new BigDecimal(value));
129 }
130 }
131
132
133
134
135 public List < BigDecimal > getBigDecimalList() {
136 return mList;
137 }
138
139
140
141
142 public void setBigDecimalList(final List < BigDecimal > list) {
143 mList = list;
144 }
145
146
147
148
149 public List < BigInteger > getBigIntegerList() {
150 List < BigInteger > list = new ArrayList < BigInteger >();
151 for (BigDecimal value : mList) {
152 list.add(value.toBigInteger());
153 }
154 return list;
155 }
156
157
158
159
160 public void setBigIntegerList(final List < BigInteger > list) {
161 mList = new ArrayList < BigDecimal >();
162 for (BigInteger value : list) {
163 mList.add(new BigDecimal(value));
164 }
165 }
166
167
168
169
170 public List < Boolean > getBooleanList() {
171 List < Boolean > list = new ArrayList < Boolean >();
172 for (BigDecimal value : mList) {
173 if (value.intValue() == 0) {
174 list.add(Boolean.FALSE);
175 } else {
176 list.add(Boolean.TRUE);
177 }
178 }
179 return list;
180 }
181
182
183
184
185 public void setBooleanList(final List < Boolean > list) {
186 mList = new ArrayList < BigDecimal >();
187 for (Boolean value : list) {
188 mList.add(new BigDecimal((value) ? "1" : "0"));
189 }
190 }
191
192
193 public Object getObjectValue(final Class < ? > type) throws HostException {
194 if (type.equals(BigDecimal.class)) {
195 return mList;
196 } else if (type.equals(BigInteger.class)) {
197 return getBigIntegerList();
198 } else if (type.equals(Long.class) || type.equals(long.class)) {
199 return getLongList();
200 } else if (type.equals(Integer.class) || type.equals(int.class)) {
201 return getIntegerList();
202 } else if (type.equals(Short.class) || type.equals(short.class)) {
203 return getShortList();
204 } else if (type.equals(Byte.class) || type.equals(byte.class)) {
205 return getByteList();
206 } else if (type.equals(Boolean.class) || type.equals(boolean.class)) {
207 return getBooleanList();
208 } else {
209 throw new HostException("Attempt to get binding "
210 + getBindingName() + " as an incompatible type " + type);
211 }
212 }
213
214
215 @SuppressWarnings("unchecked")
216 public void setObjectValue(final Object value) throws HostException {
217 if (value == null) {
218 mList = null;
219 return;
220 }
221 if (value instanceof List) {
222 if (((List < ? >) value).size() == 0) {
223 mList = new ArrayList < BigDecimal >();
224 return;
225 }
226
227
228
229
230 Object item = ((List < ? >) value).get(0);
231 if (item instanceof BigDecimal) {
232 mList = (List < BigDecimal >) value;
233 return;
234 } else if (item instanceof BigInteger) {
235 setBigIntegerList((List < BigInteger >) value);
236 return;
237 } else if (item instanceof Long) {
238 setLongList((List < Long >) value);
239 return;
240 } else if (item instanceof Integer) {
241 setIntegerList((List < Integer >) value);
242 return;
243 } else if (item instanceof Short) {
244 setShortList((List < Short >) value);
245 return;
246 } else if (item instanceof Byte) {
247 setByteList((List < Byte >) value);
248 return;
249 } else if (item instanceof Boolean) {
250 setBooleanList((List < Boolean >) value);
251 return;
252 }
253 }
254 throw new HostException("Attempt to set binding " + getBindingName()
255 + " from an incompatible value " + value);
256 }
257
258
259 public boolean isSet() {
260 return (mList != null);
261 }
262 }