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.ICobolArrayFloatBinding;
15 import com.legstar.coxb.ICobolComplexBinding;
16 import com.legstar.coxb.CobolElementVisitor;
17 import com.legstar.coxb.common.CArrayBinding;
18 import com.legstar.coxb.host.HostException;
19
20 import java.math.BigDecimal;
21 import java.util.ArrayList;
22 import java.util.List;
23
24
25
26
27
28
29
30
31 public class CArrayFloatBinding extends CArrayBinding implements ICobolArrayFloatBinding {
32
33
34 private List < Float > mList = null;
35
36
37
38
39
40
41
42
43
44
45 public CArrayFloatBinding(
46 final String bindingName,
47 final String jaxbName,
48 final Class < ? > jaxbType,
49 final CobolElement cobolAnnotations,
50 final ICobolComplexBinding parentBinding) {
51 super(bindingName, jaxbName, jaxbType, cobolAnnotations, parentBinding);
52 }
53
54
55 public void accept(final CobolElementVisitor cev)
56 throws HostException {
57 cev.visit(this);
58 }
59
60
61 public int calcItemByteLength() {
62 return CFloatBinding.calcFloatByteLength();
63 }
64
65
66
67
68 public List < Float > getFloatList() {
69 return mList;
70 }
71
72
73
74
75 public void setFloatList(
76 final List < Float > list) {
77 mList = list;
78 }
79
80
81
82
83 public List < BigDecimal > getBigDecimalList() {
84 List < BigDecimal > list = new ArrayList < BigDecimal >();
85 for (Float value : mList) {
86 list.add(new BigDecimal(value));
87 }
88 return list;
89 }
90
91
92
93
94 public void setBigDecimalList(
95 final List < BigDecimal > list) {
96 mList = new ArrayList < Float >();
97 for (BigDecimal value : list) {
98 mList.add(value.floatValue());
99 }
100 }
101
102
103 public Object getObjectValue(
104 final Class < ? > type) throws HostException {
105 if (type.equals(Float.class)) {
106 return mList;
107 } else if (type.equals(BigDecimal.class)) {
108 return getBigDecimalList();
109 } else {
110 throw new HostException("Attempt to get binding " + getBindingName()
111 + " as an incompatible type " + type);
112 }
113 }
114
115
116 @SuppressWarnings("unchecked")
117 public void setObjectValue(final Object value) throws HostException {
118 if (value == null) {
119 mList = null;
120 return;
121 }
122 if (value instanceof List) {
123 if (((List < ? >) value).size() == 0) {
124 mList = new ArrayList < Float >();
125 return;
126 }
127
128
129 Object item = ((List < ? >) value).get(0);
130 if (item instanceof Float) {
131 mList = (List < Float >) value;
132 return;
133 } else if (item instanceof BigDecimal) {
134 setBigDecimalList((List < BigDecimal >) value);
135 return;
136 }
137 }
138 throw new HostException("Attempt to set binding " + getBindingName()
139 + " from an incompatible value " + value);
140 }
141
142
143 public boolean isSet() {
144 return (mList != null);
145 }
146
147 }