1
2
3
4
5
6
7
8
9
10
11 package com.legstar.coxb.impl.reflect;
12
13 import java.util.ArrayList;
14 import java.util.List;
15
16 import com.legstar.coxb.CobolComplexType;
17 import com.legstar.coxb.CobolElement;
18 import com.legstar.coxb.common.CArrayComplexBinding;
19 import com.legstar.coxb.host.HostException;
20 import com.legstar.coxb.ICobolComplexBinding;
21
22
23
24
25
26
27
28 public class CArrayComplexReflectBinding extends CArrayComplexBinding {
29
30
31 private Object mJaxbObjectFactory;
32
33
34 private List < Object > mJaxbObject;
35
36
37
38
39
40
41
42
43
44
45
46
47
48 public CArrayComplexReflectBinding(
49 final String bindingName,
50 final String jaxbName,
51 final Class < ? > jaxbType,
52 final CobolElement cobolAnnotations,
53 final ICobolComplexBinding parentBinding,
54 final ICobolComplexBinding complexItemBinding,
55 final Object objectFactory) {
56
57 super(bindingName, jaxbName, jaxbType, cobolAnnotations, parentBinding,
58 complexItemBinding);
59 mJaxbObjectFactory = objectFactory;
60
61 setValueObjectClassName(jaxbType.getName());
62 setValueObjectsFactoryClassName(objectFactory.getClass().getName());
63
64
65 CobolComplexType cobolComplexType =
66 (CobolComplexType) jaxbType.getAnnotation(CobolComplexType.class);
67 if (cobolComplexType != null
68 && cobolComplexType.javaClassName() != null
69 && cobolComplexType.javaClassName().length() > 0) {
70 setValueObjectClassName(cobolComplexType.javaClassName());
71
72
73 setValueObjectsFactoryClassName(null);
74 }
75 }
76
77
78
79 public void createJaxbObject() throws HostException {
80 createValueObject();
81 }
82
83
84 public void createValueObject() throws HostException {
85 mJaxbObject = new ArrayList < Object >();
86 }
87
88
89 public void setItemValue(
90 final int index) throws HostException {
91
92 if (mJaxbObject == null) {
93 createJaxbObject();
94 }
95
96
97 if (index < mJaxbObject.size()) {
98 getComplexItemBinding().setObjectValue(mJaxbObject.get(index));
99 } else {
100 getComplexItemBinding().setObjectValue(null);
101 }
102 }
103
104
105
106 public void addJaxbPropertyValue(
107 final int index) throws HostException {
108 addPropertyValue(index);
109 }
110
111
112 public void addPropertyValue(
113 final int index) throws HostException {
114
115 if (mJaxbObject == null) {
116 throw new HostException(
117 "Binded object not initialized for " + getBindingName());
118 }
119 mJaxbObject.add(getComplexItemBinding().getObjectValue(getJaxbType()));
120 }
121
122
123
124
125 public Object getObjectFactory() {
126 return mJaxbObjectFactory;
127 }
128
129
130
131
132 public List < ? > getObjectList() {
133 return mJaxbObject;
134 }
135
136
137
138
139 @SuppressWarnings("unchecked")
140 public void setObjectList(final List < ? > list) {
141 mJaxbObject = ( List < Object >) list;
142 }
143
144
145 public Object getObjectValue(
146 final Class < ? > type) throws HostException {
147 if (type.equals(getJaxbType())) {
148 return mJaxbObject;
149 } else {
150 throw new HostException("Attempt to get binding " + getBindingName()
151 + " as an incompatible type " + type);
152 }
153 }
154
155
156 @SuppressWarnings("unchecked")
157 public void setObjectValue(final Object value) throws HostException {
158 if (value == null) {
159 mJaxbObject = null;
160 return;
161 }
162 if (value instanceof List) {
163 if (((List < ? >) value).size() == 0) {
164 mJaxbObject = new ArrayList < Object >();
165 return;
166 }
167
168
169 Object item = ((List < ? >) value).get(0);
170 if (item.getClass().equals(getJaxbType())) {
171 mJaxbObject = (List < Object >) value;
172 return;
173 }
174 }
175 throw new HostException("Attempt to set binding " + getBindingName()
176 + " from an incompatible value " + value);
177 }
178
179
180 public boolean isSet() {
181 return (mJaxbObject != null);
182 }
183 }