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.BINDING_ELEMENT;
13 import static it.imolinfo.jbi4cics.jbi.wsdl.Jbi4CicsExtension.CODE_PAGE_NAME_ATTRIBUTE;
14 import static it.imolinfo.jbi4cics.jbi.wsdl.Jbi4CicsExtension.COPY_COBOL_ELEMENT;
15 import static it.imolinfo.jbi4cics.jbi.wsdl.Jbi4CicsExtension.DEFAULT_PREFIX;
16 import static it.imolinfo.jbi4cics.jbi.wsdl.Jbi4CicsExtension.NS_URI_JBI4CICS;
17 import static it.imolinfo.jbi4cics.jbi.wsdl.Jbi4CicsExtension.OUTPUT_COPY_COBOL_ELEMENT;
18 import static it.imolinfo.jbi4cics.jbi.wsdl.Jbi4CicsExtension.SAME_COPY_COBOL_ATTRIBUTE;
19 import static it.imolinfo.jbi4cics.jbi.wsdl.Jbi4CicsExtension.SERVICE_PACKAGE_NAME_ATTRIBUTE;
20 import it.imolinfo.jbi4cics.Logger;
21 import it.imolinfo.jbi4cics.LoggerFactory;
22 import it.imolinfo.jbi4cics.jbi.Messages;
23 import java.io.PrintWriter;
24 import javax.wsdl.Definition;
25 import javax.wsdl.WSDLException;
26 import javax.wsdl.extensions.ExtensibilityElement;
27 import javax.wsdl.extensions.ExtensionRegistry;
28 import javax.wsdl.extensions.ExtensionSerializer;
29 import javax.xml.namespace.QName;
30 import com.ibm.wsdl.util.xml.DOMUtils;
31
32
33
34
35
36
37
38
39
40
41 public class Jbi4CicsBindingSerializer implements ExtensionSerializer {
42
43
44
45
46 private static final Logger LOG
47 = LoggerFactory.getLogger(Jbi4CicsBindingSerializer.class);
48
49
50
51
52 private static final Messages MESSAGES
53 = Messages.getMessages(Jbi4CicsBindingSerializer.class);
54
55
56
57
58 Jbi4CicsBindingSerializer() {
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 void marshall(Class parentType, QName elementType,
85 ExtensibilityElement extension, PrintWriter writer,
86 Definition def, ExtensionRegistry extReg) throws WSDLException {
87 String prefix = null;
88
89
90 try {
91 prefix = DOMUtils.getPrefix(NS_URI_JBI4CICS, def);
92 } catch (WSDLException e) {
93 LOG.warn("CIC001300_Jbi4cics_namespace_not_found",
94 new Object[] { NS_URI_JBI4CICS }, e);
95 }
96
97
98 if (prefix == null) {
99 prefix = DEFAULT_PREFIX;
100 def.addNamespace(DEFAULT_PREFIX, NS_URI_JBI4CICS);
101 }
102 prefix = prefix.concat(":");
103
104 if (LOG.isDebugEnabled()) {
105 LOG.debug("Prefix found: " + prefix);
106 }
107
108 if (extension instanceof Jbi4CicsBinding) {
109 Jbi4CicsBinding binding = (Jbi4CicsBinding) extension;
110
111 doMarshall(binding, writer, prefix);
112 } else {
113 LOG.warn("CIC001308_Invalid_extension_element", BINDING_ELEMENT);
114 }
115 }
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131 private void doMarshall(Jbi4CicsBinding binding, PrintWriter writer,
132 String prefix) throws WSDLException {
133 Boolean sameCopyCobol = binding.getSameCopyCobol();
134 String string;
135
136 writer.print("<" + prefix + BINDING_ELEMENT);
137
138
139 string = binding.getServicePackageName();
140 if (string != null) {
141 DOMUtils.printAttribute(SERVICE_PACKAGE_NAME_ATTRIBUTE, string,
142 writer);
143 } else {
144 throw createWSDLException("CIC001310_Invalid_service_package_name");
145 }
146
147
148 string = binding.getCodePage();
149 if (string != null) {
150 DOMUtils.printAttribute(CODE_PAGE_NAME_ATTRIBUTE, string, writer);
151 } else {
152 throw createWSDLException("CIC001311_Invalid_code_page");
153 }
154
155
156 if (sameCopyCobol != null) {
157 DOMUtils.printAttribute(SAME_COPY_COBOL_ATTRIBUTE,
158 sameCopyCobol.toString(), writer);
159 }
160 writer.print(">\n");
161
162
163 string = binding.getCopyCobol();
164 if (string == null) {
165 throw createWSDLException("CIC001312_Invalid_copy_cobol");
166 }
167 writer.print("<" + prefix + COPY_COBOL_ELEMENT + ">"
168 + DOMUtils.cleanString(string) + "</" + prefix
169 + COPY_COBOL_ELEMENT + ">\n");
170
171
172 string = binding.getOutputCopyCobol();
173 if ((string == null) || (string.trim().length() == 0)) {
174 if (Boolean.FALSE.equals(sameCopyCobol)) {
175 throw createWSDLException("CIC001313_Invalid_copy_cobol");
176 }
177 } else {
178 writer.print("<" + prefix + OUTPUT_COPY_COBOL_ELEMENT + ">"
179 + DOMUtils.cleanString(string) + "</" + prefix
180 + OUTPUT_COPY_COBOL_ELEMENT + ">\n");
181 }
182
183 writer.print("</" + prefix + BINDING_ELEMENT + ">\n");
184 }
185
186
187
188
189
190
191
192
193
194
195 private static WSDLException createWSDLException(final String msgKey) {
196 LOG.error(msgKey);
197 return new WSDLException(WSDLException.INVALID_WSDL,
198 MESSAGES.getString(msgKey));
199 }
200 }