KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis > wsdl > toJava > JavaStubWriter


1 /*
2  * Copyright 2001-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.axis.wsdl.toJava;
17
18 import org.apache.axis.Constants;
19 import org.apache.axis.components.logger.LogFactory;
20 import org.apache.axis.constants.Style;
21 import org.apache.axis.constants.Use;
22 import org.apache.axis.utils.Messages;
23 import org.apache.axis.utils.JavaUtils;
24 import org.apache.axis.utils.StringUtils;
25 import org.apache.axis.wsdl.symbolTable.BindingEntry;
26 import org.apache.axis.wsdl.symbolTable.DefinedType;
27 import org.apache.axis.wsdl.symbolTable.FaultInfo;
28 import org.apache.axis.wsdl.symbolTable.Parameter;
29 import org.apache.axis.wsdl.symbolTable.Parameters;
30 import org.apache.axis.wsdl.symbolTable.SchemaUtils;
31 import org.apache.axis.wsdl.symbolTable.SymbolTable;
32 import org.apache.axis.wsdl.symbolTable.TypeEntry;
33 import org.apache.axis.wsdl.symbolTable.DefinedElement;
34 import org.apache.commons.logging.Log;
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 JavaDoc;
48 import java.io.IOException JavaDoc;
49 import java.io.PrintWriter JavaDoc;
50 import java.util.ArrayList JavaDoc;
51 import java.util.Collection JavaDoc;
52 import java.util.HashMap JavaDoc;
53 import java.util.HashSet JavaDoc;
54 import java.util.Iterator JavaDoc;
55 import java.util.List JavaDoc;
56 import java.util.Map JavaDoc;
57 import java.util.Vector JavaDoc;
58 import java.util.Arrays JavaDoc;
59 import java.util.Comparator JavaDoc;
60 import java.util.Collections JavaDoc;
61
62 /**
63  * This is Wsdl2java's stub writer. It writes the <BindingName>Stub.java
64  * file which contains the <bindingName>Stub class.
65  */

66 public class JavaStubWriter extends JavaClassWriter {
67
68     /** Field log */
69     protected static Log log = LogFactory.getLog(JavaStubWriter.class.getName());
70     
71     /** Field bEntry */
72     private BindingEntry bEntry;
73
74     /** Field binding */
75     private Binding binding;
76
77     /** Field symbolTable */
78     private SymbolTable symbolTable;
79
80     // the maximum number of java type <-> qname binding instructions we'll
81
// emit in a single method. This is important for stubs that handle
82
// a large number of schema types, as the generated source can exceed
83
// the size in a single method by the VM.
84

85     /** Field MAXIMUM_BINDINGS_PER_METHOD */
86     private static final int MAXIMUM_BINDINGS_PER_METHOD = 100;
87
88     /** Field modeStrings */
89     static String JavaDoc[] modeStrings = new String JavaDoc[]{"",
90                                                "org.apache.axis.description.ParameterDesc.IN",
91                                                "org.apache.axis.description.ParameterDesc.OUT",
92                                                "org.apache.axis.description.ParameterDesc.INOUT"};
93
94     /** Field styles */
95     static Map JavaDoc styles = new HashMap JavaDoc();
96
97     /** Field uses */
98     static Map JavaDoc uses = new HashMap JavaDoc();
99
100     static {
101         styles.put(Style.DOCUMENT, "org.apache.axis.constants.Style.DOCUMENT");
102         styles.put(Style.RPC, "org.apache.axis.constants.Style.RPC");
103         styles.put(Style.MESSAGE, "org.apache.axis.constants.Style.MESSAGE");
104         styles.put(Style.WRAPPED, "org.apache.axis.constants.Style.WRAPPED");
105         uses.put(Use.ENCODED, "org.apache.axis.constants.Use.ENCODED");
106         uses.put(Use.LITERAL, "org.apache.axis.constants.Use.LITERAL");
107     }
108
109     /** Field OPERDESC_PER_BLOCK */
110     static int OPERDESC_PER_BLOCK = 10;
111
112     /**
113      * Constructor.
114      *
115      * @param emitter
116      * @param bEntry
117      * @param symbolTable
118      */

119     public JavaStubWriter(Emitter emitter, BindingEntry bEntry,
120                              SymbolTable symbolTable) {
121
122         super(emitter, bEntry.getName() + "Stub", "stub");
123
124         this.bEntry = bEntry;
125         this.binding = bEntry.getBinding();
126         this.symbolTable = symbolTable;
127     } // ctor
128

129     /**
130      * Returns "extends org.apache.axis.client.Stub ".
131      *
132      * @return
133      */

134     protected String JavaDoc getExtendsText() {
135         return "extends org.apache.axis.client.Stub ";
136     } // getExtendsText
137

138     /**
139      * Returns "implements <SEI> ".
140      *
141      * @return
142      */

143     protected String JavaDoc getImplementsText() {
144         return "implements "
145                 + bEntry.getDynamicVar(JavaBindingWriter.INTERFACE_NAME) + " ";
146     } // getImplementsText
147

148     /**
149      * Write the body of the binding's stub file.
150      *
151      * @param pw
152      * @throws IOException
153      */

154     protected void writeFileBody(PrintWriter JavaDoc pw) throws IOException JavaDoc {
155
156         PortType portType = binding.getPortType();
157         HashSet JavaDoc types = getTypesInPortType(portType);
158         boolean hasMIME = Utils.hasMIME(bEntry);
159
160         if ((types.size() > 0) || hasMIME) {
161             pw.println(
162                     " private java.util.Vector cachedSerClasses = new java.util.Vector();");
163             pw.println(
164                     " private java.util.Vector cachedSerQNames = new java.util.Vector();");
165             pw.println(
166                     " private java.util.Vector cachedSerFactories = new java.util.Vector();");
167             pw.println(
168                     " private java.util.Vector cachedDeserFactories = new java.util.Vector();");
169         }
170
171         pw.println();
172         pw.println(
173                 " static org.apache.axis.description.OperationDesc [] _operations;");
174         pw.println();
175         writeOperationMap(pw);
176         pw.println();
177         pw.println(" public " + className
178                 + "() throws org.apache.axis.AxisFault {");
179         pw.println(" this(null);");
180         pw.println(" }");
181         pw.println();
182         pw.println(
183                 " public " + className
184                 + "(java.net.URL endpointURL, javax.xml.rpc.Service service) throws org.apache.axis.AxisFault {");
185         pw.println(" this(service);");
186         pw.println(" super.cachedEndpoint = endpointURL;");
187         pw.println(" }");
188         pw.println();
189         pw.println(
190                 " public " + className
191                 + "(javax.xml.rpc.Service service) throws org.apache.axis.AxisFault {");
192         pw.println(" if (service == null) {");
193         pw.println(
194                 " super.service = new org.apache.axis.client.Service();");
195         pw.println(" } else {");
196         pw.println(" super.service = service;");
197         pw.println(" }");
198         pw.println(" ((org.apache.axis.client.Service)super.service).setTypeMappingVersion(\"" + emitter.getTypeMappingVersion() + "\");");
199
200         List JavaDoc deferredBindings = new ArrayList JavaDoc();
201
202         // keep track of how many type mappings we write out
203
int typeMappingCount = 0;
204
205         if (types.size() > 0) {
206             Iterator JavaDoc it = types.iterator();
207
208             while (it.hasNext()) {
209                 TypeEntry type = (TypeEntry) it.next();
210
211                 if (!Utils.shouldEmit(type)) {
212                     continue;
213                 }
214
215                 // Write out serializer declarations
216
if (typeMappingCount == 0) {
217                     writeSerializationDecls(
218                             pw, hasMIME, binding.getQName().getNamespaceURI());
219                 }
220
221                 // write the type mapping for this type
222
// writeSerializationInit(pw, type);
223
deferredBindings.add(type);
224
225                 // increase the number of type mappings count
226
typeMappingCount++;
227             }
228         }
229
230         // Sort the TypeEntry's by their qname.
231
Collections.sort(deferredBindings, new Comparator JavaDoc() {
232             public int compare(Object JavaDoc a, Object JavaDoc b) {
233                 TypeEntry type1 = (TypeEntry)a;
234                 TypeEntry type2 = (TypeEntry)b;
235                 return type1.getQName().toString().compareToIgnoreCase(type2.getQName().toString());
236             }
237         });
238
239         // We need to write out the MIME mapping, even if we don't have
240
// any type mappings
241
if ((typeMappingCount == 0) && hasMIME) {
242             writeSerializationDecls(pw, hasMIME,
243                     binding.getQName().getNamespaceURI());
244
245             typeMappingCount++;
246         }
247
248         // track whether the number of bindings exceeds the threshold
249
// that we allow per method.
250
boolean needsMultipleBindingMethods = false;
251
252         if (deferredBindings.size() < MAXIMUM_BINDINGS_PER_METHOD) {
253
254             // small number of bindings, just inline them:
255
for (Iterator JavaDoc it = deferredBindings.iterator(); it.hasNext();) {
256                 writeSerializationInit(pw, (TypeEntry) it.next());
257             }
258         } else {
259             needsMultipleBindingMethods = true;
260
261             int methodCount = calculateBindingMethodCount(deferredBindings);
262
263             // invoke each of the soon-to-be generated addBindings methods
264
// from the constructor.
265
for (int i = 0; i < methodCount; i++) {
266                 pw.println(" addBindings" + i + "();");
267             }
268         }
269
270         pw.println(" }");
271         pw.println();
272
273         // emit any necessary methods for assembling binding metadata.
274
if (needsMultipleBindingMethods) {
275             writeBindingMethods(pw, deferredBindings);
276             pw.println();
277         }
278
279         pw.println(
280                 " protected org.apache.axis.client.Call createCall() throws java.rmi.RemoteException {");
281         pw.println(" try {");
282         pw.println(" org.apache.axis.client.Call _call = super._createCall();");
283         pw.println(" if (super.maintainSessionSet) {");
284         pw.println(
285                 " _call.setMaintainSession(super.maintainSession);");
286         pw.println(" }");
287         pw.println(" if (super.cachedUsername != null) {");
288         pw.println(" _call.setUsername(super.cachedUsername);");
289         pw.println(" }");
290         pw.println(" if (super.cachedPassword != null) {");
291         pw.println(" _call.setPassword(super.cachedPassword);");
292         pw.println(" }");
293         pw.println(" if (super.cachedEndpoint != null) {");
294         pw.println(
295                 " _call.setTargetEndpointAddress(super.cachedEndpoint);");
296         pw.println(" }");
297         pw.println(" if (super.cachedTimeout != null) {");
298         pw.println(" _call.setTimeout(super.cachedTimeout);");
299         pw.println(" }");
300         pw.println(" if (super.cachedPortName != null) {");
301         pw.println(" _call.setPortName(super.cachedPortName);");
302         pw.println(" }");
303         pw.println(
304                 " java.util.Enumeration keys = super.cachedProperties.keys();");
305         pw.println(" while (keys.hasMoreElements()) {");
306         pw.println(
307                 " java.lang.String key = (java.lang.String) keys.nextElement();");
308         pw.println(
309                 " _call.setProperty(key, super.cachedProperties.get(key));");
310         pw.println(" }");
311
312         if (typeMappingCount > 0) {
313             pw.println(" // " + Messages.getMessage("typeMap00"));
314             pw.println(" // " + Messages.getMessage("typeMap01"));
315             pw.println(" // " + Messages.getMessage("typeMap02"));
316             pw.println(" // " + Messages.getMessage("typeMap03"));
317             pw.println(" // " + Messages.getMessage("typeMap04"));
318             pw.println(" synchronized (this) {");
319             pw.println(" if (firstCall()) {");
320
321             // Hack alert - we need to establish the encoding style before we register type mappings due
322
// to the fact that TypeMappings key off of encoding style
323
pw.println(" // "
324                     + Messages.getMessage("mustSetStyle"));
325
326             if (bEntry.hasLiteral()) {
327                 pw.println(" _call.setEncodingStyle(null);");
328             } else {
329                 Iterator JavaDoc iterator =
330                         bEntry.getBinding().getExtensibilityElements().iterator();
331
332                 while (iterator.hasNext()) {
333                     Object JavaDoc obj = iterator.next();
334
335                     if (obj instanceof SOAPBinding) {
336                         pw.println(
337                                 " _call.setSOAPVersion(org.apache.axis.soap.SOAPConstants.SOAP11_CONSTANTS);");
338                         pw.println(
339                                 " _call.setEncodingStyle(org.apache.axis.Constants.URI_SOAP11_ENC);");
340                     } else if (obj instanceof UnknownExtensibilityElement) {
341
342                         // TODO: After WSDL4J supports soap12, change this code
343
UnknownExtensibilityElement unkElement =
344                                 (UnknownExtensibilityElement) obj;
345                         QName JavaDoc name =
346                                 unkElement.getElementType();
347
348                         if (name.getNamespaceURI().equals(
349                                 Constants.URI_WSDL12_SOAP)
350                                 && name.getLocalPart().equals("binding")) {
351                             pw.println(
352                                     " _call.setSOAPVersion(org.apache.axis.soap.SOAPConstants.SOAP12_CONSTANTS);");
353                             pw.println(
354                                     " _call.setEncodingStyle(org.apache.axis.Constants.URI_SOAP12_ENC);");
355                         }
356                     }
357                 }
358             }
359
360             pw.println(
361                     " for (int i = 0; i < cachedSerFactories.size(); ++i) {");
362             pw.println(
363                     " java.lang.Class cls = (java.lang.Class) cachedSerClasses.get(i);");
364             pw.println(
365                     " javax.xml.namespace.QName qName =");
366             pw.println(
367                     " (javax.xml.namespace.QName) cachedSerQNames.get(i);");
368             pw.println(
369                     " java.lang.Object x = cachedSerFactories.get(i);");
370             pw.println(
371                     " if (x instanceof Class) {");
372             pw.println(
373                     " java.lang.Class sf = (java.lang.Class)");
374             pw.println(
375                     " cachedSerFactories.get(i);");
376             pw.println(
377                     " java.lang.Class df = (java.lang.Class)");
378             pw.println(
379                     " cachedDeserFactories.get(i);");
380             pw.println(
381                     " _call.registerTypeMapping(cls, qName, sf, df, false);");
382
383             pw.println(" }");
384             pw.println(
385                     " else if (x instanceof javax.xml.rpc.encoding.SerializerFactory) {");
386             pw.println(
387                     " org.apache.axis.encoding.SerializerFactory sf = (org.apache.axis.encoding.SerializerFactory)");
388             pw.println(
389                     " cachedSerFactories.get(i);");
390             pw.println(
391                     " org.apache.axis.encoding.DeserializerFactory df = (org.apache.axis.encoding.DeserializerFactory)");
392             pw.println(
393                     " cachedDeserFactories.get(i);");
394             pw.println(
395                     " _call.registerTypeMapping(cls, qName, sf, df, false);");
396
397             pw.println(" }");
398             pw.println(" }");
399             pw.println(" }");
400             pw.println(" }");
401         }
402
403         pw.println(" return _call;");
404         pw.println(" }");
405         pw.println(" catch (java.lang.Throwable _t) {");
406         pw.println(" throw new org.apache.axis.AxisFault(\""
407                 + Messages.getMessage("badCall01") + "\", _t);");
408         pw.println(" }");
409         pw.println(" }");
410         pw.println();
411
412         List JavaDoc operations = binding.getBindingOperations();
413
414         for (int i = 0; i < operations.size(); ++i) {
415             BindingOperation operation = (BindingOperation) operations.get(i);
416             Parameters parameters =
417                     bEntry.getParameters(operation.getOperation());
418
419             // Get the soapAction from the <soap:operation>
420
String JavaDoc soapAction = "";
421             String JavaDoc opStyle = null;
422             Iterator JavaDoc operationExtensibilityIterator =
423                     operation.getExtensibilityElements().iterator();
424
425             for (; operationExtensibilityIterator.hasNext();) {
426                 Object JavaDoc obj = operationExtensibilityIterator.next();
427
428                 if (obj instanceof SOAPOperation) {
429                     soapAction = ((SOAPOperation) obj).getSoapActionURI();
430                     opStyle = ((SOAPOperation) obj).getStyle();
431
432                     break;
433                 } else if (obj instanceof UnknownExtensibilityElement) {
434
435                     // TODO: After WSDL4J supports soap12, change this code
436
UnknownExtensibilityElement unkElement =
437                             (UnknownExtensibilityElement) obj;
438                     QName JavaDoc name =
439                             unkElement.getElementType();
440
441                     if (name.getNamespaceURI().equals(Constants.URI_WSDL12_SOAP)
442                             && name.getLocalPart().equals("operation")) {
443                         if (unkElement.getElement().getAttribute("soapAction")
444                                 != null) {
445                             soapAction = unkElement.getElement().getAttribute(
446                                     "soapAction");
447                         }
448
449                         opStyle = unkElement.getElement().getAttribute("style");
450                     }
451                 }
452             }
453
454             Operation ptOperation = operation.getOperation();
455             OperationType type = ptOperation.getStyle();
456
457             // These operation types are not supported. The signature
458
// will be a string stating that fact.
459
if ((OperationType.NOTIFICATION.equals(type))
460                     || (OperationType.SOLICIT_RESPONSE.equals(type))) {
461                 pw.println(parameters.signature);
462                 pw.println();
463             } else {
464                 writeOperation(pw, operation, parameters, soapAction, opStyle,
465                         type == OperationType.ONE_WAY, i);
466             }
467         }
468     } // writeFileBody
469

470     /**
471      * Compute the number of addBindings methods we need to generate for the
472      * set of TypeEntries used by the generated stub.
473      *
474      * @param deferredBindings a <code>List</code> value
475      * @return an <code>int</code> value
476      */

477     private int calculateBindingMethodCount(List JavaDoc deferredBindings) {
478
479         int methodCount = deferredBindings.size() / MAXIMUM_BINDINGS_PER_METHOD;
480
481         if ((deferredBindings.size() % MAXIMUM_BINDINGS_PER_METHOD) != 0) {
482             methodCount++;
483         }
484
485         return methodCount;
486     }
487
488     /**
489      * for each of the TypeEntry objects in the deferredBindings list, we need
490      * to write code that will associate a class with a schema namespace/name.
491      * This method writes a number of private methods out that do this in
492      * batches of size MAXIMUM_BINDINGS_PER_METHOD so that generated classes
493      * do not end up with a single method that exceeds the 64K limit that the
494      * VM imposes on all methods.
495      *
496      * @param pw a <code>PrintWriter</code> value
497      * @param deferredBindings a <code>List</code> of TypeEntry objects
498      */

499     protected void writeBindingMethods(PrintWriter JavaDoc pw, List JavaDoc deferredBindings) {
500
501         int methodCount = calculateBindingMethodCount(deferredBindings);
502
503         for (int i = 0; i < methodCount; i++) {
504             pw.println(" private void addBindings" + i + "() {");
505
506             // each method gets its own local variables for use in generating
507
// the binding code
508
writeSerializationDecls(pw, false, null);
509
510             for (int j = 0; j < MAXIMUM_BINDINGS_PER_METHOD; j++) {
511                 int absolute = i * MAXIMUM_BINDINGS_PER_METHOD + j;
512
513                 if (absolute == deferredBindings.size()) {
514                     break; // last one
515
}
516
517                 writeSerializationInit(
518                         pw, (TypeEntry) deferredBindings.get(absolute));
519             }
520
521             pw.println(" }");
522         }
523     }
524
525     /**
526      * Method writeOperationMap
527      *
528      * @param pw
529      */

530     protected void writeOperationMap(PrintWriter JavaDoc pw) {
531
532         List JavaDoc operations = binding.getBindingOperations();
533
534         pw.println(" static {");
535         pw.println(
536                 " _operations = new org.apache.axis.description.OperationDesc["
537                 + operations.size() + "];");
538
539         for (int j = 0, k = 0; j < operations.size(); ++j) {
540             if ((j % OPERDESC_PER_BLOCK) == 0) {
541                 k++;
542
543                 pw.println(" _initOperationDesc" + k + "();");
544             }
545         }
546
547         for (int i = 0, k = 0; i < operations.size(); ++i) {
548             if ((i % OPERDESC_PER_BLOCK) == 0) {
549                 k++;
550
551                 pw.println(" }\n");
552                 pw.println(" private static void _initOperationDesc" + k
553                         + "(){");
554                 pw.println(
555                         " org.apache.axis.description.OperationDesc oper;");
556                 pw.println(
557                         " org.apache.axis.description.ParameterDesc param;");
558             }
559
560             BindingOperation operation = (BindingOperation) operations.get(i);
561             Parameters parameters =
562                     bEntry.getParameters(operation.getOperation());
563
564             // Get the soapAction from the <soap:operation>
565
String JavaDoc opStyle = null;
566             Iterator JavaDoc operationExtensibilityIterator =
567                     operation.getExtensibilityElements().iterator();
568
569             for (; operationExtensibilityIterator.hasNext();) {
570                 Object JavaDoc obj = operationExtensibilityIterator.next();
571
572                 if (obj instanceof SOAPOperation) {
573                     opStyle = ((SOAPOperation) obj).getStyle();
574
575                     break;
576                 } else if (obj instanceof UnknownExtensibilityElement) {
577
578                     // TODO: After WSDL4J supports soap12, change this code
579
UnknownExtensibilityElement unkElement =
580                             (UnknownExtensibilityElement) obj;
581                     QName JavaDoc name =
582                             unkElement.getElementType();
583
584                     if (name.getNamespaceURI().equals(Constants.URI_WSDL12_SOAP)
585                             && name.getLocalPart().equals("operation")) {
586                         opStyle = unkElement.getElement().getAttribute("style");
587                     }
588                 }
589             }
590
591             Operation ptOperation = operation.getOperation();
592             OperationType type = ptOperation.getStyle();
593
594             // These operation types are not supported. The signature
595
// will be a string stating that fact.
596
if ((OperationType.NOTIFICATION.equals(type))
597                     || (OperationType.SOLICIT_RESPONSE.equals(type))) {
598                 pw.println(parameters.signature);
599                 pw.println();
600             }
601
602             String JavaDoc operName = operation.getName();
603             String JavaDoc indent = " ";
604
605             pw.println(
606                     indent
607                     + "oper = new org.apache.axis.description.OperationDesc();");
608             pw.println(indent + "oper.setName(\"" + operName + "\");");
609
610             // loop over paramters and set up in/out params
611
for (int j = 0; j < parameters.list.size(); ++j) {
612                 Parameter p = (Parameter) parameters.list.get(j);
613
614                 // Get the QName representing the parameter type
615
QName JavaDoc paramType = Utils.getXSIType(p);
616
617                 // Set the javaType to the name of the type
618
String JavaDoc javaType = Utils.getParameterTypeName(p);
619                     if (javaType != null) {
620                         javaType += ".class, ";
621                     } else {
622                         javaType = "null, ";
623                     }
624
625                 // Get the text representing newing a QName for the name and type
626
String JavaDoc paramNameText = Utils.getNewQNameWithLastLocalPart(p.getQName());
627                 String JavaDoc paramTypeText = Utils.getNewQName(paramType);
628
629                 // Generate the addParameter call with the
630
// name qname, typeQName, optional javaType, and mode
631
boolean isInHeader = p.isInHeader();
632                 boolean isOutHeader = p.isOutHeader();
633
634                 pw.println(" param = new org.apache.axis.description.ParameterDesc(" +
635                            paramNameText + ", " +
636                            modeStrings[p.getMode()] + ", " +
637                            paramTypeText + ", " +
638                            javaType +
639                            isInHeader + ", " + isOutHeader + ");");
640
641                 QName JavaDoc itemQName = Utils.getItemQName(p.getType());
642                 if (itemQName != null) {
643                     pw.println(" param.setItemQName(" +
644                                Utils.getNewQName(itemQName) + ");");
645                 }
646
647                 pw.println(" oper.addParameter(param);");
648             }
649
650             // set output type
651
Parameter returnParam = parameters.returnParam;
652             if (returnParam != null) {
653
654                 // Get the QName for the return Type
655
QName JavaDoc returnType = Utils.getXSIType(returnParam);
656
657                 // Get the javaType
658
String JavaDoc javaType = Utils.getParameterTypeName(returnParam);
659
660                 if (javaType == null) {
661                     javaType = "";
662                 } else {
663                     javaType += ".class";
664                 }
665
666                 pw.println(" oper.setReturnType("
667                         + Utils.getNewQName(returnType) + ");");
668                 pw.println(" oper.setReturnClass(" + javaType + ");");
669
670                 QName JavaDoc returnQName = returnParam.getQName();
671
672                 if (returnQName != null) {
673                     pw.println(" oper.setReturnQName("
674                             + Utils.getNewQNameWithLastLocalPart(returnQName) + ");");
675                 }
676
677                 if (returnParam.isOutHeader()) {
678                     pw.println(" oper.setReturnHeader(true);");
679                 }
680
681                 QName JavaDoc itemQName = Utils.getItemQName(returnParam.getType());
682                 if (itemQName != null) {
683                     pw.println(" param = oper.getReturnParamDesc();");
684                     pw.println(" param.setItemQName(" +
685                                Utils.getNewQName(itemQName) + ");");
686                 }
687
688             } else {
689                 pw.println(
690                         " oper.setReturnType(org.apache.axis.encoding.XMLType.AXIS_VOID);");
691             }
692
693             boolean hasMIME = Utils.hasMIME(bEntry, operation);
694             Style style = Style.getStyle(opStyle, bEntry.getBindingStyle());
695             Use use = bEntry.getInputBodyType(operation.getOperation());
696
697             if ((style == Style.DOCUMENT) && symbolTable.isWrapped()) {
698                 style = Style.WRAPPED;
699             }
700
701             if (!hasMIME) {
702                 pw.println(" oper.setStyle(" + styles.get(style) + ");");
703                 pw.println(" oper.setUse(" + uses.get(use) + ");");
704             }
705
706             // Register fault/exception information for this operation
707
writeFaultInfo(pw, operation);
708             pw.println(indent + "_operations[" + i + "] = oper;");
709             pw.println("");
710         }
711
712         pw.println(" }");
713     }
714
715     /**
716      * This method returns a set of all the TypeEntry in a given PortType.
717      * The elements of the returned HashSet are Types.
718      *
719      * @param portType
720      * @return
721      */

722     private HashSet JavaDoc getTypesInPortType(PortType portType) {
723
724         HashSet JavaDoc types = new HashSet JavaDoc();
725         HashSet JavaDoc firstPassTypes = new HashSet JavaDoc();
726
727         // Get all the types from all the operations
728
List JavaDoc operations = portType.getOperations();
729
730         for (int i = 0; i < operations.size(); ++i) {
731             Operation op = (Operation) operations.get(i);
732
733             firstPassTypes.addAll(getTypesInOperation(op));
734         }
735
736         // Add all the types nested and derived from the types
737
// in the first pass.
738
Iterator JavaDoc i = firstPassTypes.iterator();
739
740         while (i.hasNext()) {
741             TypeEntry type = (TypeEntry) i.next();
742
743             if (!types.contains(type)) {
744                 types.add(type);
745                 types.addAll(type.getNestedTypes(symbolTable, true));
746             }
747         }
748
749          if(emitter.isAllWanted()) {
750              HashMap JavaDoc rawSymbolTable = symbolTable.getHashMap();
751              for(Iterator JavaDoc j = rawSymbolTable.values().iterator(); j.hasNext(); ) {
752                  Vector JavaDoc typeVector = (Vector JavaDoc)j.next();
753                  for(Iterator JavaDoc k = typeVector.iterator(); k.hasNext(); ) {
754                      Object JavaDoc symbol = k.next();
755                      if(symbol instanceof DefinedType) {
756                          TypeEntry type = (TypeEntry)symbol;
757                          if(!types.contains(type)) {
758                              types.add(type);
759                          }
760                      }
761                  }
762              }
763          }
764         return types;
765     } // getTypesInPortType
766

767     /**
768      * This method returns a set of all the TypeEntry in a given Operation.
769      * The elements of the returned HashSet are TypeEntry.
770      *
771      * @param operation
772      * @return
773      */

774     private HashSet JavaDoc getTypesInOperation(Operation operation) {
775
776         HashSet JavaDoc types = new HashSet JavaDoc();
777         Vector JavaDoc v = new Vector JavaDoc();
778         Parameters params = bEntry.getParameters(operation);
779
780         // Loop over parameter types for this operation
781
for (int i = 0; i < params.list.size(); i++) {
782             Parameter p = (Parameter) params.list.get(i);
783
784             v.add(p.getType());
785         }
786
787         // Add the return type
788
if (params.returnParam != null) {
789             v.add(params.returnParam.getType());
790         }
791
792         // Collect all the types in faults
793
Map JavaDoc faults = operation.getFaults();
794
795         if (faults != null) {
796             Iterator JavaDoc i = faults.values().iterator();
797
798             while (i.hasNext()) {
799                 Fault f = (Fault) i.next();
800
801                 partTypes(v, f.getMessage().getOrderedParts(null));
802             }
803         }
804
805         // Put all these types into a set. This operation eliminates all duplicates.
806
for (int i = 0; i < v.size(); i++) {
807             types.add(v.get(i));
808         }
809
810         return types;
811     } // getTypesInOperation
812

813     /**
814      * This method returns a vector of TypeEntry for the parts.
815      *
816      * @param v
817      * @param parts
818      */

819     private void partTypes(Vector JavaDoc v, Collection JavaDoc parts) {
820
821         Iterator JavaDoc i = parts.iterator();
822
823         while (i.hasNext()) {
824             Part part = (Part) i.next();
825             QName JavaDoc qType = part.getTypeName();
826
827             if (qType != null) {
828                 v.add(symbolTable.getType(qType));
829             } else {
830                 qType = part.getElementName();
831
832                 if (qType != null) {
833                     v.add(symbolTable.getElement(qType));
834                 }
835             }
836         } // while
837
} // partTypes
838

839     /**
840      * This function writes the regsiterFaultInfo API calls
841      *
842      * @param pw
843      * @param bindOp
844      */

845     protected void writeFaultInfo(PrintWriter JavaDoc pw, BindingOperation bindOp) {
846
847         Map JavaDoc faultMap = bEntry.getFaults();
848
849         // Get the list of faults for this operation
850
ArrayList JavaDoc faults = (ArrayList JavaDoc) faultMap.get(bindOp);
851
852         // check for no faults
853
if (faults == null) {
854             return;
855         }
856
857         // For each fault, register its information
858
for (Iterator JavaDoc faultIt = faults.iterator(); faultIt.hasNext();) {
859             FaultInfo info = (FaultInfo) faultIt.next();
860             QName JavaDoc qname = info.getQName();
861             Message message = info.getMessage();
862
863             // if no parts in fault, skip it!
864
if (qname == null) {
865                 continue;
866             }
867
868             // Get the Exception class name
869
String JavaDoc className = Utils.getFullExceptionName(message, symbolTable);
870
871             // output the registration API call
872
pw.println(
873                     " oper.addFault(new org.apache.axis.description.FaultDesc(");
874             pw.println(" " + Utils.getNewQName(qname)
875                     + ",");
876             pw.println(" \"" + className + "\",");
877             pw.println(" "
878                     + Utils.getNewQName(info.getXMLType()) + ", ");
879             pw.println(" "
880                     + Utils.isFaultComplex(message, symbolTable));
881             pw.println(" ));");
882         }
883     }
884
885     /**
886      * In the stub constructor, write the serializer code for the complex types.
887      *
888      * @param pw
889      * @param hasMIME
890      * @param namespace
891      */

892     protected void writeSerializationDecls(PrintWriter JavaDoc pw, boolean hasMIME,
893                                          String JavaDoc namespace) {
894
895         pw.println(" java.lang.Class cls;");
896         pw.println(" javax.xml.namespace.QName qName;");
897         pw.println(" javax.xml.namespace.QName qName2;");
898         pw.println(
899                 " java.lang.Class beansf = org.apache.axis.encoding.ser.BeanSerializerFactory.class;");
900         pw.println(
901                 " java.lang.Class beandf = org.apache.axis.encoding.ser.BeanDeserializerFactory.class;");
902         pw.println(
903                 " java.lang.Class enumsf = org.apache.axis.encoding.ser.EnumSerializerFactory.class;");
904         pw.println(
905                 " java.lang.Class enumdf = org.apache.axis.encoding.ser.EnumDeserializerFactory.class;");
906         pw.println(
907                 " java.lang.Class arraysf = org.apache.axis.encoding.ser.ArraySerializerFactory.class;");
908         pw.println(
909                 " java.lang.Class arraydf = org.apache.axis.encoding.ser.ArrayDeserializerFactory.class;");
910         pw.println(
911                 " java.lang.Class simplesf = org.apache.axis.encoding.ser.SimpleSerializerFactory.class;");
912         pw.println(
913                 " java.lang.Class simpledf = org.apache.axis.encoding.ser.SimpleDeserializerFactory.class;");
914         pw.println(
915                 " java.lang.Class simplelistsf = org.apache.axis.encoding.ser.SimpleListSerializerFactory.class;");
916         pw.println(
917                 " java.lang.Class simplelistdf = org.apache.axis.encoding.ser.SimpleListDeserializerFactory.class;");
918         
919         if (hasMIME) {
920             pw.println(
921                     " java.lang.Class mimesf = org.apache.axis.encoding.ser.JAFDataHandlerSerializerFactory.class;");
922             pw.println(
923                     " java.lang.Class mimedf = org.apache.axis.encoding.ser.JAFDataHandlerDeserializerFactory.class;");
924             pw.println();
925
926             QName JavaDoc qname = new QName JavaDoc(namespace, "DataHandler");
927
928             pw.println(" qName = new javax.xml.namespace.QName(\""
929                     + qname.getNamespaceURI() + "\", \""
930                     + qname.getLocalPart() + "\");");
931             pw.println(" cachedSerQNames.add(qName);");
932             pw.println(" cls = javax.activation.DataHandler.class;");
933             pw.println(" cachedSerClasses.add(cls);");
934             pw.println(" cachedSerFactories.add(mimesf);");
935             pw.println(" cachedDeserFactories.add(mimedf);");
936             pw.println();
937         }
938     } // writeSerializationDecls
939

940     /**
941      * Method writeSerializationInit
942      *
943      * @param pw
944      * @param type
945      */

946     protected void writeSerializationInit(PrintWriter JavaDoc pw, TypeEntry type) {
947
948         QName JavaDoc qname = type.getQName();
949
950         pw.println(" qName = new javax.xml.namespace.QName(\""
951                 + qname.getNamespaceURI() + "\", \"" + qname.getLocalPart()
952                 + "\");");
953         pw.println(" cachedSerQNames.add(qName);");
954         pw.println(" cls = " + type.getName() + ".class;");
955         pw.println(" cachedSerClasses.add(cls);");
956
957         if (type.getName().endsWith("[]")) {
958             if (SchemaUtils.isListWithItemType(type.getNode())) {
959                 pw.println(" cachedSerFactories.add(simplelistsf);");
960                 pw.println(" cachedDeserFactories.add(simplelistdf);");
961             } else {
962                 // We use a custom serializer if WSDL told us the component type of the array.
963
// Both factories must be an instance, so we create a ArrayDeserializerFactory
964
if (type.getComponentType() != null) {
965                     QName JavaDoc ct = type.getComponentType();
966                     QName JavaDoc name = type.getItemQName();
967                     pw.println(" qName = new javax.xml.namespace.QName(\""
968                             + ct.getNamespaceURI() + "\", \"" + ct.getLocalPart()
969                             + "\");");
970                     if(name != null) {
971                         pw.println(" qName2 = new javax.xml.namespace.QName(\""
972                                 + name.getNamespaceURI() + "\", \"" + name.getLocalPart()
973                                 + "\");");
974                     } else {
975                         pw.println(" qName2 = null;");
976                     }
977                     pw.println(" cachedSerFactories.add(new org.apache.axis.encoding.ser.ArraySerializerFactory(qName, qName2));");
978                     pw.println(" cachedDeserFactories.add(new org.apache.axis.encoding.ser.ArrayDeserializerFactory());");
979                 } else {
980                     pw.println(" cachedSerFactories.add(arraysf);");
981                     pw.println(" cachedDeserFactories.add(arraydf);");
982                 }
983             }
984         } else if ((type.getNode() != null) && (Utils.getEnumerationBaseAndValues(
985                 type.getNode(), symbolTable) != null)) {
986             pw.println(" cachedSerFactories.add(enumsf);");
987             pw.println(" cachedDeserFactories.add(enumdf);");
988         } else if (type.isSimpleType()) {
989             pw.println(" cachedSerFactories.add(simplesf);");
990             pw.println(" cachedDeserFactories.add(simpledf);");
991         } else if (type.getBaseType() != null) {
992
993             // serializers are not required for types derived from base types
994
// java type to qname mapping is anyway established by default
995
// note that we have to add null to the serfactories vector to
996
// keep the order of other entries, this is not going to screw
997
// up because if type mapping returns null for a serialization
998
// factory, it is assumed to be not-defined and the delegate
999
// will be checked, the end delegate is DefaultTypeMappingImpl
1000
// that'll get it right with the base type name
1001
pw.println(" cachedSerFactories.add(null);");
1002            pw.println(" cachedDeserFactories.add(simpledf);");
1003        } else {
1004            pw.println(" cachedSerFactories.add(beansf);");
1005            pw.println(" cachedDeserFactories.add(beandf);");
1006        }
1007
1008        pw.println();
1009    } // writeSerializationInit
1010

1011    /**
1012     * Write the stub code for the given operation.
1013     *
1014     * @param pw
1015     * @param operation
1016     * @param parms
1017     * @param soapAction
1018     * @param opStyle
1019     * @param oneway
1020     * @param opIndex
1021     */

1022    protected void writeOperation(PrintWriter JavaDoc pw, BindingOperation operation,
1023                                Parameters parms, String JavaDoc soapAction,
1024                                String JavaDoc opStyle, boolean oneway, int opIndex) {
1025
1026        writeComment(pw, operation.getDocumentationElement(), true);
1027        pw.println(parms.signature + " {");
1028        pw.println(" if (super.cachedEndpoint == null) {");
1029        pw.println(
1030                " throw new org.apache.axis.NoEndPointException();");
1031        pw.println(" }");
1032        pw.println(" org.apache.axis.client.Call _call = createCall();");
1033        pw.println(" _call.setOperation(_operations[" + opIndex + "]);");
1034
1035        // SoapAction
1036
if (soapAction != null) {
1037            pw.println(" _call.setUseSOAPAction(true);");
1038            pw.println(" _call.setSOAPActionURI(\"" + soapAction
1039                    + "\");");
1040        }
1041
1042        boolean hasMIME = Utils.hasMIME(bEntry, operation);
1043
1044        // Encoding: literal or encoded use.
1045
Use use = bEntry.getInputBodyType(operation.getOperation());
1046
1047        if (use == Use.LITERAL) {
1048
1049            // Turn off encoding
1050
pw.println(" _call.setEncodingStyle(null);");
1051
1052            // turn off XSI types
1053
pw.println(
1054                    " _call.setProperty(org.apache.axis.client.Call.SEND_TYPE_ATTR, Boolean.FALSE);");
1055        }
1056
1057        if (hasMIME || (use == Use.LITERAL)) {
1058
1059            // If it is literal, turn off multirefs.
1060
//
1061
// If there are any MIME types, turn off multirefs.
1062
// I don't know enough about the guts to know why
1063
// attachments don't work with multirefs, but they don't.
1064
pw.println(
1065                    " _call.setProperty(org.apache.axis.AxisEngine.PROP_DOMULTIREFS, Boolean.FALSE);");
1066        }
1067
1068        Style style = Style.getStyle(opStyle, bEntry.getBindingStyle());
1069
1070        if ((style == Style.DOCUMENT) && symbolTable.isWrapped()) {
1071            style = Style.WRAPPED;
1072        }
1073
1074        Iterator JavaDoc iterator =
1075                bEntry.getBinding().getExtensibilityElements().iterator();
1076
1077        while (iterator.hasNext()) {
1078            Object JavaDoc obj = iterator.next();
1079
1080            if (obj instanceof SOAPBinding) {
1081                pw.println(
1082                        " _call.setSOAPVersion(org.apache.axis.soap.SOAPConstants.SOAP11_CONSTANTS);");
1083            } else if (obj instanceof UnknownExtensibilityElement) {
1084
1085                // TODO: After WSDL4J supports soap12, change this code
1086
UnknownExtensibilityElement unkElement =
1087                        (UnknownExtensibilityElement) obj;
1088                QName JavaDoc name =
1089                        unkElement.getElementType();
1090
1091                if (name.getNamespaceURI().equals(Constants.URI_WSDL12_SOAP)
1092                        && name.getLocalPart().equals("binding")) {
1093                    pw.println(
1094                            " _call.setSOAPVersion(org.apache.axis.soap.SOAPConstants.SOAP12_CONSTANTS);");
1095                }
1096            }
1097        }
1098
1099        // Operation name
1100
if (style == Style.WRAPPED) {
1101
1102            // We need to make sure the operation name, which is what we
1103
// wrap the elements in, matches the Qname of the parameter
1104
// element.
1105
Map JavaDoc partsMap =
1106                    operation.getOperation().getInput().getMessage().getParts();
1107            Iterator JavaDoc i = partsMap.values().iterator();
1108            if(i.hasNext()) {
1109                Part p = (Part) partsMap.values().iterator().next();
1110                QName JavaDoc q = p.getElementName();
1111    
1112                pw.println(" _call.setOperationName(" + Utils.getNewQName(q)
1113                        + ");");
1114            } else {
1115                log.warn(Messages.getMessage("missingPartsForMessage00",operation.getOperation().getInput().getMessage().getQName().toString()));
1116            }
1117        } else {
1118            QName JavaDoc elementQName = Utils.getOperationQName(operation, bEntry,
1119                    symbolTable);
1120
1121            if (elementQName != null) {
1122                pw.println(" _call.setOperationName("
1123                        + Utils.getNewQName(elementQName) + ");");
1124            }
1125        }
1126
1127        pw.println();
1128
1129        // Set the headers
1130
pw.println(" setRequestHeaders(_call);");
1131
1132        // Set the attachments
1133
pw.println(" setAttachments(_call);");
1134
1135        // Set DIME flag if needed
1136
if (bEntry.isOperationDIME(operation.getOperation().getName())) {
1137            pw.println(
1138                    " _call.setProperty(_call.ATTACHMENT_ENCAPSULATION_FORMAT, _call.ATTACHMENT_ENCAPSULATION_FORMAT_DIME);");
1139        }
1140
1141        // Invoke the operation
1142
if (oneway) {
1143            pw.print(" _call.invokeOneWay(");
1144        } else {
1145            pw.print(" try {");
1146            pw.print(" java.lang.Object _resp = _call.invoke(");
1147        }
1148
1149        pw.print("new java.lang.Object[] {");
1150        writeParameters(pw, parms);
1151        pw.println("});");
1152        pw.println();
1153
1154        if (!oneway) {
1155            writeResponseHandling(pw, parms);
1156        }
1157
1158        pw.println(" }");
1159        pw.println();
1160    } // writeOperation
1161

1162    /**
1163     * Method writeParameters
1164     *
1165     * @param pw
1166     * @param parms
1167     */

1168    protected void writeParameters(PrintWriter JavaDoc pw, Parameters parms) {
1169
1170        // Write the input and inout parameter list
1171
boolean needComma = false;
1172
1173        for (int i = 0; i < parms.list.size(); ++i) {
1174            Parameter p = (Parameter) parms.list.get(i);
1175
1176            if (p.getMode() != Parameter.OUT) {
1177                if (needComma) {
1178                    pw.print(", ");
1179                } else {
1180                    needComma = true;
1181                }
1182
1183                String JavaDoc javifiedName = Utils.xmlNameToJava(p.getName());
1184
1185                if (p.getMode() != Parameter.IN) {
1186                    javifiedName += ".value";
1187                }
1188
1189                if (p.getMIMEInfo() == null && !p.isOmittable()) {
1190                    javifiedName = Utils.wrapPrimitiveType(p.getType(),
1191                            javifiedName);
1192                }
1193
1194                pw.print(javifiedName);
1195            }
1196        }
1197    } // writeParamters
1198

1199    /**
1200     * Method writeResponseHandling
1201     *
1202     * @param pw
1203     * @param parms
1204     */

1205    protected void writeResponseHandling(PrintWriter JavaDoc pw, Parameters parms) {
1206
1207        pw.println(" if (_resp instanceof java.rmi.RemoteException) {");
1208        pw.println(" throw (java.rmi.RemoteException)_resp;");
1209        pw.println(" }");
1210
1211        int allOuts = parms.outputs + parms.inouts;
1212
1213        if (allOuts > 0) {
1214            pw.println(" else {");
1215            pw.println(" extractAttachments(_call);");
1216
1217            if (allOuts == 1) {
1218                if (parms.returnParam != null) {
1219                    writeOutputAssign(pw, "return ",
1220                            parms.returnParam, "_resp");
1221                } else {
1222
1223                    // The resp object must go into a holder
1224
int i = 0;
1225                    Parameter p = (Parameter) parms.list.get(i);
1226
1227                    while (p.getMode() == Parameter.IN) {
1228                        p = (Parameter) parms.list.get(++i);
1229                    }
1230
1231                    String JavaDoc javifiedName = Utils.xmlNameToJava(p.getName());
1232                    String JavaDoc qnameName = Utils.getNewQNameWithLastLocalPart(p.getQName());
1233
1234                    pw.println(" java.util.Map _output;");
1235                    pw.println(
1236                            " _output = _call.getOutputParams();");
1237                    writeOutputAssign(pw,
1238                                      javifiedName + ".value = ",
1239                                      p,
1240                                      "_output.get(" + qnameName + ")");
1241                }
1242            } else {
1243
1244                // There is more than 1 output. Get the outputs from getOutputParams.
1245
pw.println(" java.util.Map _output;");
1246                pw.println(" _output = _call.getOutputParams();");
1247
1248                for (int i = 0; i < parms.list.size(); ++i) {
1249                    Parameter p = (Parameter) parms.list.get(i);
1250                    String JavaDoc javifiedName = Utils.xmlNameToJava(p.getName());
1251                    String JavaDoc qnameName =
1252                            Utils.getNewQNameWithLastLocalPart(p.getQName());
1253
1254                    if (p.getMode() != Parameter.IN) {
1255                        writeOutputAssign(pw,
1256                                          javifiedName + ".value = ",
1257                                          p,
1258                                          "_output.get(" + qnameName + ")");
1259                    }
1260                }
1261
1262                if (parms.returnParam != null) {
1263                    writeOutputAssign(pw,
1264                                      "return ",
1265                                      parms.returnParam,
1266                                      "_resp");
1267                }
1268            }
1269
1270            pw.println(" }");
1271        } else {
1272            pw.println(" extractAttachments(_call);");
1273        }
1274        // End catch
1275
// Get faults
1276
Map JavaDoc faults = parms.faults;
1277        // Get faults of signature
1278
List JavaDoc exceptionsThrowsList = new ArrayList JavaDoc();
1279        int index = parms.signature.indexOf("throws");
1280        if (index != -1) {
1281            String JavaDoc[] thrExcep = StringUtils.split(parms.signature.substring(index+6),',');
1282            for (int i = 0; i < thrExcep.length; i++) {
1283                exceptionsThrowsList.add(thrExcep[i].trim());
1284            }
1285        }
1286        pw.println(" } catch (org.apache.axis.AxisFault axisFaultException) {");
1287        if (faults != null && faults.size() > 0) {
1288            pw.println(" if (axisFaultException.detail != null) {");
1289            for (Iterator JavaDoc faultIt = exceptionsThrowsList.iterator(); faultIt
1290                    .hasNext();) {
1291                String JavaDoc exceptionFullName = (String JavaDoc) faultIt.next();
1292                pw.println(" if (axisFaultException.detail instanceof "
1293                        + exceptionFullName + ") {");
1294                pw.println(" throw (" + exceptionFullName
1295                        + ") axisFaultException.detail;");
1296                pw.println(" }");
1297            }
1298            pw.println(" }");
1299        }
1300        pw.println(" throw axisFaultException;");
1301        pw.println("}");
1302    } // writeResponseHandling
1303

1304    /**
1305     * writeOutputAssign
1306     *
1307     * @param pw
1308     * @param target (either "return" or "something ="
1309     * @param source (source String)
1310     */

1311    protected void writeOutputAssign(PrintWriter JavaDoc pw, String JavaDoc target,
1312                                   Parameter param,
1313                                   String JavaDoc source) {
1314
1315        TypeEntry type = param.getType();
1316        
1317        if ((type != null) && (type.getName() != null)) {
1318
1319            String JavaDoc typeName = type.getName();
1320            // If minOccurs="0" and singular or array with nillable underlying
1321
// type get the corresponding wrapper type.
1322
if ((param.isOmittable() && param.getType().getDimensions().equals(""))
1323                || param.getType().getUnderlTypeNillable()) {
1324
1325                typeName = Utils.getWrapperType(type);
1326            }
1327
1328            // Try casting the output to the expected output.
1329
// If that fails, use JavaUtils.convert()
1330
pw.println(" try {");
1331            pw.println(" " + target
1332                    + Utils.getResponseString(param, source));
1333            pw.println(
1334                    " } catch (java.lang.Exception _exception) {");
1335            pw.println(
1336                    " " + target
1337                    + Utils.getResponseString(param,
1338                            "org.apache.axis.utils.JavaUtils.convert(" +
1339                            source + ", " + typeName + ".class)"));
1340            pw.println(" }");
1341        } else {
1342            pw.println(" " + target
1343                    + Utils.getResponseString(param, source));
1344        }
1345    }
1346} // class JavaStubWriter
1347
Popular Tags