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.ICobolArrayOctetStreamBinding;
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.util.ArrayList;
21 import java.util.List;
22
23
24
25
26
27
28
29
30 public class CArrayOctetStreamBinding extends CArrayBinding
31 implements ICobolArrayOctetStreamBinding {
32
33
34 private List < byte[] > mList = null;
35
36
37
38
39
40
41
42
43
44
45 public CArrayOctetStreamBinding(
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 COctetStreamBinding.calcOctetStreamByteLength(getPicture(), getUsage());
63 }
64
65
66 public List < byte[] > getValue() throws HostException {
67
68 if (mList == null) {
69
70
71 if (isRedefined() || getRedefines().length() > 0) {
72 return null;
73 }
74
75 mList = new ArrayList < byte[] >();
76 }
77
78 return mList;
79 }
80
81
82 public void setValue(
83 final List < byte[] > list) throws HostException {
84 mList = list;
85 }
86
87
88 @SuppressWarnings("unchecked")
89 public void setValue(final Object value) throws HostException {
90 if (value == null) {
91 mList = null;
92 return;
93 }
94 if (value instanceof List) {
95 mList = (List < byte[] >) value;
96 } else {
97 throw new HostException(
98 "Value passed to " + getBindingName() + " is not a List");
99 }
100 }
101
102
103
104
105 public List < byte[] > getByteArrayList() {
106 return mList;
107 }
108
109
110
111
112 public void setByteArrayList(
113 final List < byte[] > list) {
114 mList = list;
115 }
116
117
118 public Object getObjectValue(
119 final Class < ? > type) throws HostException {
120 if (type.equals(byte[].class)) {
121 return mList;
122 } else {
123 throw new HostException("Attempt to get binding " + getBindingName()
124 + " as an incompatible type " + type);
125 }
126 }
127
128
129 @SuppressWarnings("unchecked")
130 public void setObjectValue(final Object value) throws HostException {
131 if (value == null) {
132 mList = null;
133 return;
134 }
135 if (value instanceof List) {
136 if (((List < ? >) value).size() == 0) {
137 mList = new ArrayList < byte[] >();
138 return;
139 }
140
141
142 Object item = ((List < ? >) value).get(0);
143 if (item instanceof byte[]) {
144 mList = (List < byte[] >) value;
145 return;
146 }
147 }
148 throw new HostException("Attempt to set binding " + getBindingName()
149 + " from an incompatible value " + value);
150 }
151
152
153 public boolean isSet() {
154 return (mList != null);
155 }
156 }