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.CobolUsage;
15 import com.legstar.coxb.ICobolComplexBinding;
16 import com.legstar.coxb.ICobolOctetStreamBinding;
17 import com.legstar.coxb.CobolElementVisitor;
18 import com.legstar.coxb.common.CBinding;
19 import com.legstar.coxb.host.HostException;
20 import com.legstar.coxb.util.PictureUtil;
21
22
23
24
25
26
27
28
29
30
31
32 public class COctetStreamBinding extends CBinding
33 implements ICobolOctetStreamBinding {
34
35
36 private byte[] mValue = null;
37
38
39
40
41
42
43
44
45
46
47 public COctetStreamBinding(
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 byte[] getByteArrayValue() throws HostException {
64 return mValue;
65 }
66
67
68 public void setByteArrayValue(final byte[] value)
69 throws HostException {
70 mValue = value;
71 }
72
73
74 public int calcByteLength() {
75 return calcOctetStreamByteLength(getPicture(), getUsage());
76 }
77
78
79
80
81
82
83
84 public static int calcOctetStreamByteLength(
85 final String picture, final String usage) {
86 if (usage.equals(CobolUsage.INDEX)) {
87 return 4;
88 } else if (usage.equals(CobolUsage.POINTER)) {
89 return 4;
90 } else if (usage.equals(CobolUsage.PROCEDURE_POINTER)) {
91 return 8;
92 } else if (usage.equals(CobolUsage.FUNCTION_POINTER)) {
93 return 4;
94 }
95 return PictureUtil.getSymbolsNumber('X', picture);
96 }
97
98
99 public Object getObjectValue(
100 final Class < ? > type) throws HostException {
101 if (type.equals(byte[].class)) {
102 return mValue;
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 byte[]) {
116 mValue = (byte[]) 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 }