1
2
3
4
5
6
7
8
9
10
11 package com.legstar.coxb.impl;
12
13 import java.math.BigDecimal;
14 import com.legstar.coxb.CobolElement;
15 import com.legstar.coxb.ICobolComplexBinding;
16 import com.legstar.coxb.ICobolDoubleBinding;
17 import com.legstar.coxb.CobolElementVisitor;
18 import com.legstar.coxb.common.CBinding;
19 import com.legstar.coxb.host.HostException;
20
21
22
23
24
25
26
27
28 public class CDoubleBinding extends CBinding implements ICobolDoubleBinding {
29
30
31 private Double mValue = null;
32
33
34 public static final int BYTE_LENGTH = 8;
35
36
37
38
39
40
41
42
43
44
45 public CDoubleBinding(
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 Double getDoubleValue() throws HostException {
62 return mValue;
63 }
64
65
66 public void setDoubleValue(final Double value) throws HostException {
67 mValue = value;
68 }
69
70
71 public BigDecimal getBigDecimalValue() throws HostException {
72 return new BigDecimal(mValue);
73 }
74
75
76 public void setBigDecimalValue(
77 final BigDecimal value) throws HostException {
78 mValue = value.doubleValue();
79 }
80
81
82 public int calcByteLength() {
83 return calcDoubleByteLength();
84 }
85
86
87
88
89
90 public static int calcDoubleByteLength() {
91 return BYTE_LENGTH;
92 }
93
94
95 public Object getObjectValue(
96 final Class < ? > type) throws HostException {
97 if (type.equals(Double.class) || type.equals(double.class)) {
98 return mValue;
99 } else if (type.equals(BigDecimal.class)) {
100 return getBigDecimalValue();
101 } else {
102 throw new HostException("Attempt to get binding " + getBindingName()
103 + " as an incompatible type " + type);
104 }
105 }
106
107
108 public void setObjectValue(final Object value) throws HostException {
109 if (value == null) {
110 mValue = null;
111 return;
112 }
113 if (value instanceof Double) {
114 mValue = (Double) value;
115 } else if (value instanceof BigDecimal) {
116 setBigDecimalValue((BigDecimal) value);
117 } else {
118 throw new HostException("Attempt to set binding " + getBindingName()
119 + " from an incompatible value " + value);
120 }
121 }
122
123
124 public boolean isSet() {
125 return (mValue != null);
126 }
127 }