1
2
3
4
5
6
7
8
9
10 package it.imolinfo.jbi4cics.jbi.wsdl;
11
12 import static it.imolinfo.jbi4cics.jbi.wsdl.Jbi4CicsExtension.CODE_PAGE_NAME_ATTRIBUTE;
13 import static it.imolinfo.jbi4cics.jbi.wsdl.Jbi4CicsExtension.Q_ELEM_JBI4CICS_COPY_COBOL;
14 import static it.imolinfo.jbi4cics.jbi.wsdl.Jbi4CicsExtension.Q_ELEM_JBI4CICS_OUTPUT_COPY_COBOL;
15 import static it.imolinfo.jbi4cics.jbi.wsdl.Jbi4CicsExtension.SAME_COPY_COBOL_ATTRIBUTE;
16 import static it.imolinfo.jbi4cics.jbi.wsdl.Jbi4CicsExtension.SERVICE_PACKAGE_NAME_ATTRIBUTE;
17 import it.imolinfo.jbi4cics.Logger;
18 import it.imolinfo.jbi4cics.LoggerFactory;
19 import it.imolinfo.jbi4cics.jbi.Messages;
20 import javax.wsdl.Definition;
21 import javax.wsdl.WSDLException;
22 import javax.wsdl.extensions.ExtensibilityElement;
23 import javax.wsdl.extensions.ExtensionDeserializer;
24 import javax.wsdl.extensions.ExtensionRegistry;
25 import javax.xml.namespace.QName;
26 import org.w3c.dom.Element;
27 import com.ibm.wsdl.util.xml.DOMUtils;
28 import com.ibm.wsdl.util.xml.QNameUtils;
29
30
31
32
33
34
35
36
37 public final class Jbi4CicsBindingDeserializer
38 implements ExtensionDeserializer {
39
40
41
42
43 private static final Logger LOG
44 = LoggerFactory.getLogger(Jbi4CicsBindingDeserializer.class);
45
46
47
48
49 private static final Messages MESSAGES
50 = Messages.getMessages(Jbi4CicsBindingDeserializer.class);
51
52
53
54
55 Jbi4CicsBindingDeserializer() {
56 }
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84 public ExtensibilityElement unmarshall(Class parentType, QName elementType,
85 Element elem, Definition def, ExtensionRegistry extReg)
86 throws WSDLException {
87 Jbi4CicsBinding binding = (Jbi4CicsBinding)
88 extReg.createExtension(parentType, elementType);
89 String sameCopyCobol = DOMUtils.getAttribute(elem,
90 SAME_COPY_COBOL_ATTRIBUTE);
91
92
93 binding.setServicePackageName(
94 DOMUtils.getAttribute(elem, SERVICE_PACKAGE_NAME_ATTRIBUTE));
95 binding.setCodePage(
96 DOMUtils.getAttribute(elem, CODE_PAGE_NAME_ATTRIBUTE));
97 if (isNullOrBlank(sameCopyCobol)) {
98 binding.setSameCopyCobol(null);
99 } else {
100 binding.setSameCopyCobol(Boolean.valueOf(sameCopyCobol));
101 }
102
103
104 unmarshallCopiesCobol(binding, elem);
105
106 return binding;
107 }
108
109
110
111
112
113
114
115
116
117
118
119
120
121 private static boolean isNullOrBlank(final String str) {
122 if (str != null) {
123 for (int i = str.length() - 1; i >= 0; --i) {
124 if (str.charAt(i) > ' ') {
125 return false;
126 }
127 }
128 }
129 return true;
130 }
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146 private void unmarshallCopiesCobol(Jbi4CicsBinding binding, Element elem)
147 throws WSDLException {
148 boolean copyCobolFound = false;
149 boolean outCopyCobolFound = false;
150
151 for (Element e = DOMUtils.getFirstChildElement(elem);
152 e != null;
153 e = DOMUtils.getNextSiblingElement(e)) {
154 if (QNameUtils.matches(Q_ELEM_JBI4CICS_OUTPUT_COPY_COBOL, e)) {
155 if (outCopyCobolFound) {
156 throw createWSDLException(
157 "CIC001314_Element_found_many_times",
158 Q_ELEM_JBI4CICS_OUTPUT_COPY_COBOL);
159 }
160 binding.setOutputCopyCobol(e.getTextContent());
161 outCopyCobolFound = true;
162 } else if (QNameUtils.matches(Q_ELEM_JBI4CICS_COPY_COBOL, e)) {
163 if (copyCobolFound) {
164 throw createWSDLException(
165 "CIC001314_Element_found_many_times",
166 Q_ELEM_JBI4CICS_COPY_COBOL);
167 }
168 binding.setCopyCobol(e.getTextContent());
169 copyCobolFound = true;
170 }
171 }
172
173 if (!copyCobolFound) {
174 throw createWSDLException("CIC001309_Copy_cobol_not_found",
175 Q_ELEM_JBI4CICS_COPY_COBOL);
176 }
177 if (Boolean.FALSE.equals(binding.getSameCopyCobol())
178 && !outCopyCobolFound) {
179 throw createWSDLException("CIC001315_Output_copy_Cobol_required",
180 null);
181 }
182 }
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201 private static WSDLException createWSDLException(final String msgKey,
202 final Object msgArg) {
203 String msg;
204
205 if (msgArg == null) {
206 LOG.error(msgKey);
207 msg = MESSAGES.getString(msgKey);
208 } else {
209 LOG.error(msgKey, msgArg);
210 msg = MESSAGES.getString(msgKey, msgArg);
211 }
212
213
214 return new WSDLException(null, msg);
215 }
216 }