1
2
3
4
5
6
7
8
9
10
11 package com.legstar.coxb.common;
12
13 import com.legstar.coxb.CobolElement;
14 import com.legstar.coxb.ICobolArrayBinding;
15 import com.legstar.coxb.ICobolComplexBinding;
16 import com.legstar.coxb.ICobolNumericBinding;
17 import com.legstar.coxb.host.HostException;
18
19
20
21
22
23 public abstract class CArrayBinding extends CBinding implements
24 ICobolArrayBinding {
25
26
27 private ICobolNumericBinding mCounter;
28
29
30 private int mItemByteLength = 0;
31
32
33
34
35
36
37
38
39
40
41 public CArrayBinding(final String bindingName, final String jaxbName,
42 final Class < ? > jaxbType, final CobolElement cobolAnnotations,
43 final ICobolComplexBinding parentBinding) {
44 super(bindingName, jaxbName, jaxbType, cobolAnnotations, parentBinding);
45 }
46
47
48
49
50 public int getCurrentOccurs() throws HostException {
51
52
53
54
55 if (isVariableSize()) {
56 return getCounter().getBigIntegerValue().intValue();
57 }
58 return this.getMaxOccurs();
59 }
60
61
62
63
64
65
66 public int calcByteLength() {
67 long byteLength = getMaxOccurs() * (long) getItemByteLength();
68 return byteLength > Integer.MAX_VALUE ? Integer.MAX_VALUE
69 : (int) byteLength;
70 }
71
72
73
74
75
76
77
78 public boolean isVariableSize() {
79 return (getMinOccurs() < getMaxOccurs() && getDependingOn() != null && getDependingOn()
80 .length() > 0) ? true : false;
81 }
82
83
84
85
86
87
88
89
90
91 private ICobolNumericBinding getCounter() throws HostException {
92 if (mCounter == null) {
93 mCounter = getParentBinding().getCounter(getDependingOn());
94 }
95 return mCounter;
96 }
97
98
99
100
101
102
103
104
105
106 public int getByteLength() {
107 if (isGeneratedBinding() && !(this instanceof CArrayComplexBinding)
108 && mItemByteLength == 0) {
109
110 int itemByteLength = super.getByteLength();
111 setItemByteLength(itemByteLength);
112 setByteLength(itemByteLength * getMaxOccurs());
113 }
114 return super.getByteLength();
115 }
116
117
118
119
120 public int getItemByteLength() {
121 if (mItemByteLength == 0) {
122 if (isGeneratedBinding() && !(this instanceof CArrayComplexBinding)) {
123
124 mItemByteLength = super.getByteLength();
125 setByteLength(mItemByteLength * getMaxOccurs());
126 } else {
127 mItemByteLength = calcItemByteLength();
128 }
129 }
130 return mItemByteLength;
131 }
132
133
134
135
136 public void setItemByteLength(final int itemByteLength) {
137 mItemByteLength = itemByteLength;
138 }
139
140 }