1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.geronimo.ews.jaxrpcmapping;
17
18 import org.apache.axis.Constants;
19 import org.apache.axis.constants.Style;
20 import org.apache.axis.constants.Use;
21 import org.apache.axis.utils.JavaUtils;
22 import org.apache.axis.utils.Messages;
23 import org.apache.axis.wsdl.symbolTable.BindingEntry;
24 import org.apache.axis.wsdl.symbolTable.CollectionTE;
25 import org.apache.axis.wsdl.symbolTable.DefinedType;
26 import org.apache.axis.wsdl.symbolTable.Element;
27 import org.apache.axis.wsdl.symbolTable.FaultInfo;
28 import org.apache.axis.wsdl.symbolTable.MimeInfo;
29 import org.apache.axis.wsdl.symbolTable.Parameter;
30 import org.apache.axis.wsdl.symbolTable.Parameters;
31 import org.apache.axis.wsdl.symbolTable.SymbolTable;
32 import org.apache.axis.wsdl.symbolTable.TypeEntry;
33 import org.apache.axis.wsdl.toJava.JavaClassWriter;
34 import org.apache.axis.wsdl.toJava.Utils;
35
36 import javax.wsdl.Binding;
37 import javax.wsdl.BindingOperation;
38 import javax.wsdl.Fault;
39 import javax.wsdl.Message;
40 import javax.wsdl.Operation;
41 import javax.wsdl.OperationType;
42 import javax.wsdl.Part;
43 import javax.wsdl.PortType;
44 import javax.wsdl.extensions.UnknownExtensibilityElement;
45 import javax.wsdl.extensions.soap.SOAPBinding;
46 import javax.wsdl.extensions.soap.SOAPOperation;
47 import javax.xml.namespace.QName;
48 import java.io.IOException;
49 import java.io.PrintWriter;
50 import java.util.ArrayList;
51 import java.util.Collection;
52 import java.util.HashMap;
53 import java.util.HashSet;
54 import java.util.Iterator;
55 import java.util.List;
56 import java.util.Map;
57 import java.util.Vector;
58
59 /***
60 * This is Wsdl2java's stub writer. It writes the <BindingName>Stub.java
61 * file which contains the <bindingName>Stub class.
62 *
63 * @author Ias (iasandcb@tmax.co.kr)
64 */
65 public class J2eeStubWriter extends JavaClassWriter {
66 private BindingEntry bEntry;
67 private Binding binding;
68 private SymbolTable symbolTable;
69
70 static String[] modeStrings = new String[]{"",
71 "org.apache.axis.description.ParameterDesc.IN",
72 "org.apache.axis.description.ParameterDesc.OUT",
73 "org.apache.axis.description.ParameterDesc.INOUT"};
74 static HashMap styles = new HashMap();
75 static HashMap uses = new HashMap();
76
77 static {
78 styles.put(Style.DOCUMENT, "org.apache.axis.constants.Style.DOCUMENT");
79 styles.put(Style.RPC, "org.apache.axis.constants.Style.RPC");
80 styles.put(Style.MESSAGE, "org.apache.axis.constants.Style.MESSAGE");
81 styles.put(Style.WRAPPED, "org.apache.axis.constants.Style.WRAPPED");
82 uses.put(Use.ENCODED, "org.apache.axis.constants.Use.ENCODED");
83 uses.put(Use.LITERAL, "org.apache.axis.constants.Use.LITERAL");
84 }
85
86 static int OPERDESC_PER_BLOCK = 10;
87
88 /***
89 * Constructor.
90 */
91 protected J2eeStubWriter(J2eeEmitter emitter,
92 BindingEntry bEntry,
93 SymbolTable symbolTable) {
94 super(emitter, bEntry.getName() + "Stub", "stub");
95 this.bEntry = bEntry;
96 this.binding = bEntry.getBinding();
97 this.symbolTable = symbolTable;
98 }
99
100 /***
101 * Returns "extends org.apache.axis.client.Stub ".
102 */
103 protected String getExtendsText() {
104 return "extends org.apache.axis.client.Stub ";
105 }
106
107 /***
108 * Returns "implements <SEI> ".
109 */
110 protected String getImplementsText() {
111 return "implements " + bEntry.getDynamicVar(J2eeBindingWriter.INTERFACE_NAME) + " ";
112 }
113
114 /***
115 * Write the body of the binding's stub file.
116 */
117 protected void writeFileBody(PrintWriter pw) throws IOException {
118 PortType portType = binding.getPortType();
119 HashSet types = getTypesInPortType(portType);
120 boolean hasMIME = Utils.hasMIME(bEntry);
121 if (types.size() > 0 || hasMIME) {
122 pw.println(" private java.util.Vector cachedSerClasses = new java.util.Vector();");
123 pw.println(" private java.util.Vector cachedSerQNames = new java.util.Vector();");
124 pw.println(" private java.util.Vector cachedSerFactories = new java.util.Vector();");
125 pw.println(" private java.util.Vector cachedDeserFactories = new java.util.Vector();");
126 }
127 pw.println();
128 pw.println(" static org.apache.axis.description.OperationDesc [] _operations;");
129 pw.println();
130 writeOperationMap(pw);
131 pw.println();
132 pw.println(" public " + className + "() throws org.apache.axis.AxisFault {");
133 pw.println(" this(null);");
134 pw.println(" }");
135 pw.println();
136 pw.println(" public " + className + "(java.net.URL endpointURL, javax.xml.rpc.Service service) throws org.apache.axis.AxisFault {");
137 pw.println(" this(service);");
138 pw.println(" super.cachedEndpoint = endpointURL;");
139 pw.println(" }");
140 pw.println();
141 pw.println(" public " + className + "(javax.xml.rpc.Service service) throws org.apache.axis.AxisFault {");
142 pw.println(" if (service == null) {");
143 pw.println(" super.service = new org.apache.axis.client.Service();");
144 pw.println(" } else {");
145 pw.println(" super.service = service;");
146 pw.println(" }");
147 pw
148 .println(" ((org.apache.axis.client.Service)super.service).setTypeMappingVersion(\""
149 + emitter.getTypeMappingVersion() + "\");");
150 List deferredBindings = new ArrayList();
151
152 int typeMappingCount = 0;
153 if (types.size() > 0) {
154 Iterator it = types.iterator();
155 while (it.hasNext()) {
156 TypeEntry type = (TypeEntry) it.next();
157
158 if (!Utils.shouldEmit(type)) {
159 continue;
160 }
161
162
163 if (typeMappingCount == 0) {
164 writeSerializationDecls(pw, hasMIME, binding.getQName().getNamespaceURI());
165 }
166
167
168 writeSerializationInit(pw, type);
169
170
171 typeMappingCount++;
172 }
173 }
174
175
176 if (typeMappingCount == 0 && hasMIME) {
177 writeSerializationDecls(pw, hasMIME, binding.getQName().getNamespaceURI());
178 typeMappingCount++;
179 }
180 pw.println(" }");
181 pw.println();
182 pw.println(" private org.apache.axis.client.Call createCall() throws java.rmi.RemoteException {");
183 pw.println(" try {");
184 pw.println(" org.apache.axis.client.Call _call =");
185 pw.println(" (org.apache.axis.client.Call) super.service.createCall();");
186 pw.println(" if (super.maintainSessionSet) {");
187 pw.println(" _call.setMaintainSession(super.maintainSession);");
188 pw.println(" }");
189 pw.println(" if (super.cachedUsername != null) {");
190 pw.println(" _call.setUsername(super.cachedUsername);");
191 pw.println(" }");
192 pw.println(" if (super.cachedPassword != null) {");
193 pw.println(" _call.setPassword(super.cachedPassword);");
194 pw.println(" }");
195 pw.println(" if (super.cachedEndpoint != null) {");
196 pw.println(" _call.setTargetEndpointAddress(super.cachedEndpoint);");
197 pw.println(" }");
198 pw.println(" if (super.cachedTimeout != null) {");
199 pw.println(" _call.setTimeout(super.cachedTimeout);");
200 pw.println(" }");
201 pw.println(" if (super.cachedPortName != null) {");
202 pw.println(" _call.setPortName(super.cachedPortName);");
203 pw.println(" }");
204 pw.println(" java.util.Enumeration keys = super.cachedProperties.keys();");
205 pw.println(" while (keys.hasMoreElements()) {");
206 pw.println(" java.lang.String key = (java.lang.String) keys.nextElement();");
207 pw.println(" _call.setProperty(key, super.cachedProperties.get(key));");
208 pw.println(" }");
209 if (typeMappingCount > 0) {
210 pw.println(" // " + Messages.getMessage("typeMap00"));
211 pw.println(" // " + Messages.getMessage("typeMap01"));
212 pw.println(" // " + Messages.getMessage("typeMap02"));
213 pw.println(" // " + Messages.getMessage("typeMap03"));
214 pw.println(" // " + Messages.getMessage("typeMap04"));
215 pw.println(" synchronized (this) {");
216 pw.println(" if (firstCall()) {");
217
218
219
220 pw.println(" // "
221 + Messages.getMessage("mustSetStyle"));
222 if (bEntry.hasLiteral()) {
223 pw.println(" _call.setEncodingStyle(null);");
224 } else {
225 Iterator iterator = bEntry.getBinding().getExtensibilityElements().iterator();
226 while (iterator.hasNext()) {
227 Object obj = iterator.next();
228 if (obj instanceof SOAPBinding) {
229 pw.println(" _call.setSOAPVersion(org.apache.axis.soap.SOAPConstants.SOAP11_CONSTANTS);");
230 pw.println(" _call.setEncodingStyle(org.apache.axis.Constants.URI_SOAP11_ENC);");
231 } else if (obj instanceof UnknownExtensibilityElement) {
232
233 UnknownExtensibilityElement unkElement = (UnknownExtensibilityElement) obj;
234 QName name = unkElement.getElementType();
235 if (name.getNamespaceURI().equals(Constants.URI_WSDL12_SOAP) &&
236 name.getLocalPart().equals("binding")) {
237 pw.println(" _call.setSOAPVersion(org.apache.axis.soap.SOAPConstants.SOAP12_CONSTANTS);");
238 pw.println(" _call.setEncodingStyle(org.apache.axis.Constants.URI_SOAP12_ENC);");
239 }
240 }
241 }
242 }
243 pw.println(" for (int i = 0; i < cachedSerFactories.size(); ++i) {");
244 pw.println(" java.lang.Class cls = (java.lang.Class) cachedSerClasses.get(i);");
245 pw.println(" javax.xml.namespace.QName qName =");
246 pw.println(" (javax.xml.namespace.QName) cachedSerQNames.get(i);");
247 pw.println(" java.lang.Class sf = (java.lang.Class)");
248 pw.println(" cachedSerFactories.get(i);");
249 pw.println(" java.lang.Class df = (java.lang.Class)");
250 pw.println(" cachedDeserFactories.get(i);");
251 pw.println(" _call.registerTypeMapping(cls, qName, sf, df, false);");
252 pw.println(" }");
253 pw.println(" }");
254 pw.println(" }");
255 }
256 pw.println(" return _call;");
257 pw.println(" }");
258 pw.println(" catch (java.lang.Throwable t) {");
259 pw.println(" throw new org.apache.axis.AxisFault(\""
260 + Messages.getMessage("badCall01") + "\", t);");
261 pw.println(" }");
262 pw.println(" }");
263 pw.println();
264 List operations = binding.getBindingOperations();
265 for (int i = 0; i < operations.size(); ++i) {
266 BindingOperation operation = (BindingOperation) operations.get(i);
267 Parameters parameters =
268 bEntry.getParameters(operation.getOperation());
269
270
271 String soapAction = "";
272 String opStyle = null;
273 Iterator operationExtensibilityIterator = operation.getExtensibilityElements().iterator();
274 for (; operationExtensibilityIterator.hasNext();) {
275 Object obj = operationExtensibilityIterator.next();
276 if (obj instanceof SOAPOperation) {
277 soapAction = ((SOAPOperation) obj).getSoapActionURI();
278 opStyle = ((SOAPOperation) obj).getStyle();
279 break;
280 } else if (obj instanceof UnknownExtensibilityElement) {
281
282 UnknownExtensibilityElement unkElement = (UnknownExtensibilityElement) obj;
283 QName name = unkElement.getElementType();
284 if (name.getNamespaceURI().equals(Constants.URI_WSDL12_SOAP) &&
285 name.getLocalPart().equals("operation")) {
286 if (unkElement.getElement().getAttribute("soapAction") != null) {
287 soapAction = unkElement.getElement().getAttribute("soapAction");
288 }
289 opStyle = unkElement.getElement().getAttribute("style");
290 }
291 }
292 }
293 Operation ptOperation = operation.getOperation();
294 OperationType type = ptOperation.getStyle();
295
296
297
298 if (type == OperationType.NOTIFICATION
299 || type == OperationType.SOLICIT_RESPONSE) {
300 pw.println(parameters.signature);
301 pw.println();
302 } else {
303 writeOperation(pw, operation, parameters, soapAction, opStyle,
304 type == OperationType.ONE_WAY, i);
305 }
306 }
307 }
308
309 private void writeOperationMap(PrintWriter pw) {
310 List operations = binding.getBindingOperations();
311 pw.println(" static {");
312 pw.println(" _operations = new org.apache.axis.description.OperationDesc[" +
313 operations.size() + "];");
314 for (int j = 0, k = 0; j < operations.size(); ++j) {
315 if ((j % OPERDESC_PER_BLOCK) == 0) {
316 k++;
317 pw.println(" _initOperationDesc" + k + "();");
318 }
319 }
320 for (int i = 0, k = 0; i < operations.size(); ++i) {
321 if ((i % OPERDESC_PER_BLOCK) == 0) {
322 k++;
323 pw.println(" }\n");
324 pw.println(" private static void _initOperationDesc" + k + "(){");
325 pw.println(" org.apache.axis.description.OperationDesc oper;");
326 }
327 BindingOperation operation = (BindingOperation) operations.get(i);
328 Parameters parameters =
329 bEntry.getParameters(operation.getOperation());
330
331
332 String opStyle = null;
333 Iterator operationExtensibilityIterator = operation.getExtensibilityElements().iterator();
334 for (; operationExtensibilityIterator.hasNext();) {
335 Object obj = operationExtensibilityIterator.next();
336 if (obj instanceof SOAPOperation) {
337 opStyle = ((SOAPOperation) obj).getStyle();
338 break;
339 } else if (obj instanceof UnknownExtensibilityElement) {
340
341 UnknownExtensibilityElement unkElement = (UnknownExtensibilityElement) obj;
342 QName name = unkElement.getElementType();
343 if (name.getNamespaceURI().equals(Constants.URI_WSDL12_SOAP) &&
344 name.getLocalPart().equals("operation")) {
345 opStyle = unkElement.getElement().getAttribute("style");
346 }
347 }
348 }
349 Operation ptOperation = operation.getOperation();
350 OperationType type = ptOperation.getStyle();
351
352
353
354 if (type == OperationType.NOTIFICATION
355 || type == OperationType.SOLICIT_RESPONSE) {
356 pw.println(parameters.signature);
357 pw.println();
358 }
359 String operName = operation.getName();
360 String indent = " ";
361 pw.println(indent + "oper = new org.apache.axis.description.OperationDesc();");
362 pw.println(indent + "oper.setName(\"" + operName + "\");");
363
364
365 for (int j = 0; j < parameters.list.size(); ++j) {
366 Parameter p = (Parameter) parameters.list.get(j);
367
368
369 QName paramType = Utils.getXSIType(p);
370
371
372 String javaType = null;
373 if (p.getMIMEInfo() != null) {
374 MimeInfo mimeInfo = p.getMIMEInfo();
375 javaType = JavaUtils.mimeToJava(mimeInfo.getType()) + mimeInfo.getDimensions() + ".class, ";
376 } else {
377 javaType = p.getType().getName();
378 if (javaType != null) {
379 javaType += ".class, ";
380 } else {
381 javaType = "null, ";
382 }
383 }
384
385
386 String paramNameText = Utils.getNewQName(p.getQName());
387 String paramTypeText = Utils.getNewQName(paramType);
388
389
390
391 boolean isInHeader = p.isInHeader();
392 boolean isOutHeader = p.isOutHeader();
393 pw.println(" oper.addParameter(" + paramNameText
394 + ", " + paramTypeText + ", "
395 + javaType + modeStrings[p.getMode()]
396 + ", " + isInHeader + ", " + isOutHeader + ");");
397 }
398
399 if (parameters.returnParam != null) {
400
401 QName returnType = Utils.getXSIType(parameters.returnParam);
402
403
404 String javaType = null;
405 if (parameters.returnParam.getMIMEInfo() != null) {
406 MimeInfo mimeInfo = parameters.returnParam.getMIMEInfo();
407 javaType = JavaUtils.mimeToJava(mimeInfo.getType()) + mimeInfo.getDimensions();
408 } else {
409 javaType = parameters.returnParam.getType().getName();
410 }
411 if (javaType == null) {
412 javaType = "";
413 } else {
414 javaType = javaType + ".class";
415 }
416 pw.println(" oper.setReturnType(" +
417 Utils.getNewQName(returnType) + ");");
418 pw.println(" oper.setReturnClass("
419 + javaType + ");");
420 QName returnQName = parameters.returnParam.getQName();
421 if (returnQName != null) {
422 pw.println(" oper.setReturnQName(" +
423 Utils.getNewQName(returnQName) + ");");
424 }
425 if (parameters.returnParam.isOutHeader()) {
426 pw.println(" oper.setReturnHeader(true);");
427 }
428 } else {
429 pw.println(" oper.setReturnType(org.apache.axis.encoding.XMLType.AXIS_VOID);");
430 }
431 boolean hasMIME = Utils.hasMIME(bEntry, operation);
432 Style style = Style.getStyle(opStyle, bEntry.getBindingStyle());
433 Use use = bEntry.getInputBodyType(operation.getOperation());
434 if (style == Style.DOCUMENT && symbolTable.isWrapped()) {
435 style = Style.WRAPPED;
436 }
437 if (!hasMIME) {
438 pw.println(" oper.setStyle(" + styles.get(style) + ");");
439 pw.println(" oper.setUse(" + uses.get(use) + ");");
440 }
441
442
443 writeFaultInfo(pw, operation);
444 pw.println(indent + "_operations[" + i + "] = oper;");
445 pw.println("");
446 }
447 pw.println(" }");
448 }
449
450 /***
451 * This method returns a set of all the TypeEntry in a given PortType.
452 * The elements of the returned HashSet are Types.
453 */
454 private HashSet getTypesInPortType(PortType portType) {
455 HashSet types = new HashSet();
456 HashSet firstPassTypes = new HashSet();
457
458
459 List operations = portType.getOperations();
460 for (int i = 0; i < operations.size(); ++i) {
461 Operation op = (Operation) operations.get(i);
462 firstPassTypes.addAll(getTypesInOperation(op));
463 }
464
465
466
467 Iterator i = firstPassTypes.iterator();
468 while (i.hasNext()) {
469 TypeEntry type = (TypeEntry) i.next();
470 if (!types.contains(type)) {
471 types.add(type);
472 types.addAll(type.getNestedTypes(symbolTable, true));
473 }
474 }
475 if (emitter.isAllWanted()) {
476 HashMap rawSymbolTable = symbolTable.getHashMap();
477 for (Iterator j = rawSymbolTable.values().iterator(); j.hasNext();) {
478 Vector typeVector = (Vector) j.next();
479 for (Iterator k = typeVector.iterator(); k.hasNext();) {
480 Object symbol = k.next();
481 if (symbol instanceof DefinedType) {
482 TypeEntry type = (TypeEntry) symbol;
483 if (!types.contains(type)) {
484 types.add(type);
485 }
486 }
487 }
488 }
489 }
490 return types;
491 }
492
493 /***
494 * This method returns a set of all the TypeEntry in a given Operation.
495 * The elements of the returned HashSet are TypeEntry.
496 */
497 private HashSet getTypesInOperation(Operation operation) {
498 HashSet types = new HashSet();
499 Vector v = new Vector();
500 Parameters params = bEntry.getParameters(operation);
501
502
503 for (int i = 0; i < params.list.size(); i++) {
504 Parameter p = (Parameter) params.list.get(i);
505 v.add(p.getType());
506 }
507
508
509 if (params.returnParam != null)
510 v.add(params.returnParam.getType());
511
512
513 Map faults = operation.getFaults();
514 if (faults != null) {
515 Iterator i = faults.values().iterator();
516 while (i.hasNext()) {
517 Fault f = (Fault) i.next();
518 partTypes(v,
519 f.getMessage().getOrderedParts(null));
520 }
521 }
522
523 for (int i = 0; i < v.size(); i++)
524 types.add(v.get(i));
525 return types;
526 }
527
528 /***
529 * This method returns a vector of TypeEntry for the parts.
530 */
531 private void partTypes(Vector v, Collection parts) {
532 Iterator i = parts.iterator();
533 while (i.hasNext()) {
534 Part part = (Part) i.next();
535 QName qType = part.getTypeName();
536 if (qType != null) {
537 v.add(symbolTable.getType(qType));
538 } else {
539 qType = part.getElementName();
540 if (qType != null) {
541 v.add(symbolTable.getElement(qType));
542 }
543 }
544 }
545 }
546
547 /***
548 * This function writes the regsiterFaultInfo API calls
549 */
550 private void writeFaultInfo(PrintWriter pw, BindingOperation bindOp) {
551 Map faultMap = bEntry.getFaults();
552
553 ArrayList faults = (ArrayList) faultMap.get(bindOp);
554
555
556 if (faults == null) {
557 return;
558 }
559
560 for (Iterator faultIt = faults.iterator(); faultIt.hasNext();) {
561 FaultInfo info = (FaultInfo) faultIt.next();
562 QName qname = info.getQName();
563 Message message = info.getMessage();
564
565
566 if (qname == null) {
567 continue;
568 }
569
570
571 String className = Utils.getFullExceptionName(message, symbolTable);
572
573
574 pw.println(" oper.addFault(new org.apache.axis.description.FaultDesc(");
575 pw.println(" " + Utils.getNewQName(qname) + ",");
576 pw.println(" \"" + className + "\",");
577 pw.println(" " + Utils.getNewQName(info.getXMLType()) + ", ");
578 pw.println(" " + Utils.isFaultComplex(message, symbolTable));
579 pw.println(" ));");
580 }
581 }
582
583 /***
584 * In the stub constructor, write the serializer code for the complex types.
585 */
586 private void writeSerializationDecls(PrintWriter pw, boolean hasMIME,
587 String namespace) {
588 pw.println(" java.lang.Class cls;");
589 pw.println(" javax.xml.namespace.QName qName;");
590 pw.println(" java.lang.Class beansf = org.apache.axis.encoding.ser.BeanSerializerFactory.class;");
591 pw.println(" java.lang.Class beandf = org.apache.axis.encoding.ser.BeanDeserializerFactory.class;");
592 pw.println(" java.lang.Class enumsf = org.apache.axis.encoding.ser.EnumSerializerFactory.class;");
593 pw.println(" java.lang.Class enumdf = org.apache.axis.encoding.ser.EnumDeserializerFactory.class;");
594 pw.println(" java.lang.Class arraysf = org.apache.axis.encoding.ser.ArraySerializerFactory.class;");
595 pw.println(" java.lang.Class arraydf = org.apache.axis.encoding.ser.ArrayDeserializerFactory.class;");
596 pw.println(" java.lang.Class simplesf = org.apache.axis.encoding.ser.SimpleSerializerFactory.class;");
597 pw.println(" java.lang.Class simpledf = org.apache.axis.encoding.ser.SimpleDeserializerFactory.class;");
598 if (hasMIME) {
599 pw.println(" java.lang.Class mimesf = org.apache.axis.encoding.ser.JAFDataHandlerSerializerFactory.class;");
600 pw.println(" java.lang.Class mimedf = org.apache.axis.encoding.ser.JAFDataHandlerDeserializerFactory.class;");
601 pw.println();
602 QName qname = new QName(namespace, "DataHandler");
603 pw.println(" qName = new javax.xml.namespace.QName(\""
604 + qname.getNamespaceURI() + "\", \"" + qname.getLocalPart()
605 + "\");");
606 pw.println(" cachedSerQNames.add(qName);");
607 pw.println(" cls = javax.activation.DataHandler.class;");
608 pw.println(" cachedSerClasses.add(cls);");
609 pw.println(" cachedSerFactories.add(mimesf);");
610 pw.println(" cachedDeserFactories.add(mimedf);");
611 pw.println();
612 }
613 }
614
615 private void writeSerializationInit(PrintWriter pw, TypeEntry type) {
616 QName qname = type.getQName();
617 pw.println(" qName = new javax.xml.namespace.QName(\""
618 + qname.getNamespaceURI() + "\", \"" + qname.getLocalPart()
619 + "\");");
620 pw.println(" cachedSerQNames.add(qName);");
621 pw.println(" cls = " + type.getName() + ".class;");
622 pw.println(" cachedSerClasses.add(cls);");
623 if (type.getName().endsWith("[]")) {
624 pw.println(" cachedSerFactories.add(arraysf);");
625 pw.println(" cachedDeserFactories.add(arraydf);");
626 } else if (type.getNode() != null &&
627 Utils.getEnumerationBaseAndValues(type.getNode(), symbolTable) != null) {
628 pw.println(" cachedSerFactories.add(enumsf);");
629 pw.println(" cachedDeserFactories.add(enumdf);");
630 } else if (type.isSimpleType()) {
631 pw.println(" cachedSerFactories.add(simplesf);");
632 pw.println(" cachedDeserFactories.add(simpledf);");
633 } else if (type.getBaseType() != null) {
634
635
636
637
638
639
640
641
642 pw.println(" cachedSerFactories.add(null);");
643 pw.println(" cachedDeserFactories.add(simpledf);");
644 } else {
645 pw.println(" cachedSerFactories.add(beansf);");
646 pw.println(" cachedDeserFactories.add(beandf);");
647 }
648 pw.println();
649 }
650
651 /***
652 * Write the stub code for the given operation.
653 */
654 private void writeOperation(PrintWriter pw,
655 BindingOperation operation,
656 Parameters parms,
657 String soapAction,
658 String opStyle,
659 boolean oneway,
660 int opIndex) {
661 writeComment(pw, operation.getDocumentationElement(), true);
662 pw.println(parms.signature + " {");
663 pw.println(" if (super.cachedEndpoint == null) {");
664 pw.println(" throw new org.apache.axis.NoEndPointException();");
665 pw.println(" }");
666 pw.println(" org.apache.axis.client.Call _call = createCall();");
667 pw.println(" _call.setOperation(_operations[" + opIndex + "]);");
668
669
670 if (soapAction != null) {
671 pw.println(" _call.setUseSOAPAction(true);");
672 pw.println(" _call.setSOAPActionURI(\"" + soapAction + "\");");
673 }
674 boolean hasMIME = Utils.hasMIME(bEntry, operation);
675
676
677 Use use = bEntry.getInputBodyType(operation.getOperation());
678 if (use == Use.LITERAL) {
679
680 pw.println(" _call.setEncodingStyle(null);");
681
682 pw.println(" _call.setProperty(org.apache.axis.client.Call.SEND_TYPE_ATTR, Boolean.FALSE);");
683 }
684 if (hasMIME || use == Use.LITERAL) {
685
686
687
688
689
690 pw.println(" _call.setProperty(org.apache.axis.AxisEngine.PROP_DOMULTIREFS, Boolean.FALSE);");
691 }
692 Style style = Style.getStyle(opStyle, bEntry.getBindingStyle());
693 if (style == Style.DOCUMENT && symbolTable.isWrapped()) {
694 style = Style.WRAPPED;
695 }
696 Iterator iterator = bEntry.getBinding().getExtensibilityElements().iterator();
697 while (iterator.hasNext()) {
698 Object obj = iterator.next();
699 if (obj instanceof SOAPBinding) {
700 pw.println(" _call.setSOAPVersion(org.apache.axis.soap.SOAPConstants.SOAP11_CONSTANTS);");
701 } else if (obj instanceof UnknownExtensibilityElement) {
702
703 UnknownExtensibilityElement unkElement = (UnknownExtensibilityElement) obj;
704 QName name = unkElement.getElementType();
705 if (name.getNamespaceURI().equals(Constants.URI_WSDL12_SOAP) &&
706 name.getLocalPart().equals("binding")) {
707 pw.println(" _call.setSOAPVersion(org.apache.axis.soap.SOAPConstants.SOAP12_CONSTANTS);");
708 }
709 }
710 }
711
712
713 if (style == Style.WRAPPED) {
714
715
716
717 Map partsMap = operation.getOperation().getInput().getMessage().getParts();
718 Part p = (Part) partsMap.values().iterator().next();
719 QName q = p.getElementName();
720 pw.println(" _call.setOperationName(" + Utils.getNewQName(q) + ");");
721 } else {
722 QName elementQName =
723 Utils.getOperationQName(operation, bEntry, symbolTable);
724 if (elementQName != null) {
725 pw.println(" _call.setOperationName(" +
726 Utils.getNewQName(elementQName) + ");");
727 }
728 }
729 pw.println();
730
731
732 pw.println(" setRequestHeaders(_call);");
733
734
735 pw.println(" setAttachments(_call);");
736
737
738 if (bEntry.isOperationDIME(operation.getOperation().getName())) {
739 pw.println(" _call.setProperty(_call.ATTACHMENT_ENCAPSULATION_FORMAT, _call.ATTACHMENT_ENCAPSULATION_FORMAT_DIME);");
740 }
741
742
743 if (oneway) {
744 pw.print(" _call.invokeOneWay(");
745 } else {
746 pw.print(" try {");
747 pw.print(" java.lang.Object _resp = _call.invoke(");
748 }
749 pw.print("new java.lang.Object[] {");
750 writeParameters(pw, parms);
751 pw.println("});");
752 pw.println();
753 if (!oneway) {
754 writeResponseHandling(pw, parms);
755 }
756 pw.println(" }");
757 pw.println();
758 }
759
760 private void writeParameters(PrintWriter pw, Parameters parms) {
761
762 boolean needComma = false;
763 for (int i = 0; i < parms.list.size(); ++i) {
764 Parameter p = (Parameter) parms.list.get(i);
765 if (p.getMode() != Parameter.OUT) {
766 if (needComma) {
767 pw.print(", ");
768 } else {
769 needComma = true;
770 }
771 String javifiedName = Utils.xmlNameToJava(p.getName());
772 if (p.getMode() != Parameter.IN) {
773 javifiedName += ".value";
774 }
775 if (p.getMIMEInfo() == null) {
776 javifiedName = Utils.wrapPrimitiveType(p.getType(), javifiedName);
777 }
778 pw.print(javifiedName);
779 }
780 }
781 }
782
783 private void writeResponseHandling(PrintWriter pw, Parameters parms) {
784 pw.println(" if (_resp instanceof java.rmi.RemoteException) {");
785 pw.println(" throw (java.rmi.RemoteException)_resp;");
786 pw.println(" }");
787 int allOuts = parms.outputs + parms.inouts;
788 if (allOuts > 0) {
789 pw.println(" else {");
790 pw.println(" extractAttachments(_call);");
791 if (allOuts == 1) {
792 if (parms.returnParam != null) {
793 writeOutputAssign(pw, "return ", parms.returnParam, "_resp");
794 } else {
795
796 int i = 0;
797 Parameter p = (Parameter) parms.list.get(i);
798 while (p.getMode() == Parameter.IN) {
799 p = (Parameter) parms.list.get(++i);
800 }
801 String javifiedName = Utils.xmlNameToJava(p.getName());
802 String qnameName = Utils.getNewQName(p.getQName());
803 pw.println(" java.util.Map _output;");
804 pw.println(" _output = _call.getOutputParams();");
805 writeOutputAssign(pw, javifiedName + ".value = ",
806 p,
807 "_output.get(" + qnameName + ")");
808 }
809 } else {
810
811 pw.println(" java.util.Map _output;");
812 pw.println(" _output = _call.getOutputParams();");
813 for (int i = 0; i < parms.list.size(); ++i) {
814 Parameter p = (Parameter) parms.list.get(i);
815 String javifiedName = Utils.xmlNameToJava(p.getName());
816 String qnameName = Utils.getNewQName(p.getQName());
817 if (p.getMode() != Parameter.IN) {
818 writeOutputAssign(pw, javifiedName + ".value = ",
819 p,
820 "_output.get(" + qnameName + ")");
821 }
822 }
823 if (parms.returnParam != null) {
824 writeOutputAssign(pw, "return ", parms.returnParam, "_resp");
825 }
826 }
827 pw.println(" }");
828 } else {
829 pw.println(" extractAttachments(_call);");
830 }
831
832
833 Map faults = parms.faults;
834
835 String[] throwsSig = parms.signature.split("throws");
836 List exceptionsThrowsList = new ArrayList();
837 if (throwsSig != null && throwsSig.length > 1) {
838 String[] thrExcep = throwsSig[1].split(",");
839 for (int i = 0; i < thrExcep.length; i++) {
840 exceptionsThrowsList.add(thrExcep[i]);
841 }
842 }
843 pw
844 .println(" } catch (org.apache.axis.AxisFault axisFaultException) {");
845 if (faults != null && faults.size() > 0) {
846 pw.println(" if (axisFaultException.detail != null) {");
847 for (Iterator faultIt = exceptionsThrowsList.iterator(); faultIt
848 .hasNext();) {
849 String exceptionFullName = (String) faultIt.next();
850 pw.println(" if (axisFaultException.detail instanceof "
851 + exceptionFullName + ") {");
852 pw.println(" throw (" + exceptionFullName
853 + ") axisFaultException.detail;");
854 pw.println(" }");
855 }
856 pw.println(" }");
857 }
858 pw.println(" throw axisFaultException;");
859 pw.println("}");
860 }
861
862 /***
863 * writeOutputAssign
864 *
865 * @param target (either "return" or "something ="
866 * @param type (source TypeEntry)
867 * @param source (source String)
868 */
869 private void writeOutputAssign(PrintWriter pw, String target,
870 Parameter param,
871 String source) {
872 TypeEntry type = param.getType();
873 if ((type != null) && (type.getName() != null)) {
874 String typeName = type.getName();
875 if (param.isOmittable()) {
876 typeName = Utils.getWrapperType(type.getName());
877 }
878
879
880
881 pw.println(" try {");
882 pw.println(" " + target
883 + Utils.getResponseString(param, source));
884 pw.println(" } catch (java.lang.Exception _exception) {");
885 pw.println(" " + target
886 + Utils.getResponseString(param,
887 "org.apache.axis.utils.JavaUtils.convert(" +
888 source + ", " + typeName + ".class)"));
889 pw.println(" }");
890 } else {
891 pw.println(" " + target
892 + Utils.getResponseString(param, source));
893 }
894 }
895
896 }