1
2
3
4
5
6
7
8
9
10
11 package com.legstar.coxb.impl;
12
13 import java.math.BigDecimal;
14
15 import com.legstar.coxb.CobolElement;
16 import com.legstar.coxb.ICobolComplexBinding;
17 import com.legstar.coxb.ICobolFloatBinding;
18 import com.legstar.coxb.CobolElementVisitor;
19 import com.legstar.coxb.common.CBinding;
20 import com.legstar.coxb.host.HostException;
21
22
23
24
25
26
27
28
29 public class CFloatBinding extends CBinding
30 implements ICobolFloatBinding {
31
32
33 private Float mValue = null;
34
35
36 public static final int BYTE_LENGTH = 4;
37
38
39
40
41
42
43
44
45
46
47 public CFloatBinding(
48 final String bindingName,
49 final String jaxbName,
50 final Class < ? > jaxbType,
51 final CobolElement cobolAnnotations,
52 final ICobolComplexBinding parentBinding) {
53 super(bindingName, jaxbName, jaxbType, cobolAnnotations, parentBinding);
54 }
55
56
57 public void accept(final CobolElementVisitor cev)
58 throws HostException {
59 cev.visit(this);
60 }
61
62
63 public Float getFloatValue() throws HostException {
64 return mValue;
65 }
66
67
68 public void setFloatValue(final Float value) throws HostException {
69 mValue = value;
70 }
71
72
73 public BigDecimal getBigDecimalValue() throws HostException {
74 return new BigDecimal(mValue);
75 }
76
77
78 public void setBigDecimalValue(
79 final BigDecimal value) throws HostException {
80 mValue = value.floatValue();
81 }
82
83
84 public int calcByteLength() {
85 return calcFloatByteLength();
86 }
87
88
89
90
91
92 public static int calcFloatByteLength() {
93 return BYTE_LENGTH;
94 }
95
96
97 public Object getObjectValue(
98 final Class < ? > type) throws HostException {
99 if (type.equals(Float.class) || type.equals(float.class)) {
100 return mValue;
101 } else if (type.equals(BigDecimal.class)) {
102 return getBigDecimalValue();
103 } else {
104 throw new HostException("Attempt to get binding " + getBindingName()
105 + " as an incompatible type " + type);
106 }
107 }
108
109
110 public void setObjectValue(final Object value) throws HostException {
111 if (value == null) {
112 mValue = null;
113 return;
114 }
115 if (value instanceof Float) {
116 mValue = (Float) value;
117 } else if (value instanceof BigDecimal) {
118 setBigDecimalValue((BigDecimal) value);
119 } else {
120 throw new HostException("Attempt to set binding " + getBindingName()
121 + " from an incompatible value " + value);
122 }
123 }
124
125
126 public boolean isSet() {
127 return (mValue != null);
128 }
129 }