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.ICobolArrayDoubleBinding;
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 CArrayDoubleBinding extends CArrayBinding
32 implements ICobolArrayDoubleBinding {
33
34
35 private List < Double > mList = null;
36
37
38
39
40
41
42
43
44
45
46 public CArrayDoubleBinding(
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 calcItemByteLength() {
63 return CDoubleBinding.calcDoubleByteLength();
64 }
65
66
67
68
69 public List < Double > getDoubleList() {
70 return mList;
71 }
72
73
74
75
76 public void setDoubleList(
77 final List < Double > list) {
78 mList = list;
79 }
80
81
82
83
84 public List < BigDecimal > getBigDecimalList() {
85 List < BigDecimal > list = new ArrayList < BigDecimal >();
86 for (Double value : mList) {
87 list.add(new BigDecimal(value));
88 }
89 return list;
90 }
91
92
93
94
95 public void setBigDecimalList(
96 final List < BigDecimal > list) {
97 mList = new ArrayList < Double >();
98 for (BigDecimal value : list) {
99 mList.add(value.doubleValue());
100 }
101 }
102
103
104 public Object getObjectValue(
105 final Class < ? > type) throws HostException {
106 if (type.equals(Double.class)) {
107 return mList;
108 } else if (type.equals(BigDecimal.class)) {
109 return getBigDecimalList();
110 } else {
111 throw new HostException("Attempt to get binding " + getBindingName()
112 + " as an incompatible type " + type);
113 }
114 }
115
116
117 @SuppressWarnings("unchecked")
118 public void setObjectValue(final Object value) throws HostException {
119 if (value == null) {
120 mList = null;
121 return;
122 }
123 if (value instanceof List) {
124 if (((List < ? >) value).size() == 0) {
125 mList = new ArrayList < Double >();
126 return;
127 }
128
129
130 Object item = ((List < ? >) value).get(0);
131 if (item instanceof Double) {
132 mList = (List < Double >) value;
133 return;
134 } else if (item instanceof BigDecimal) {
135 setBigDecimalList((List < BigDecimal >) value);
136 return;
137 }
138 }
139 throw new HostException("Attempt to set binding " + getBindingName()
140 + " from an incompatible value " + value);
141 }
142
143
144 public boolean isSet() {
145 return (mList != null);
146 }
147 }