KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis > wsdl > fromJava > Emitter


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.fromJava;
17
18 import com.ibm.wsdl.extensions.soap.SOAPAddressImpl;
19 import com.ibm.wsdl.extensions.soap.SOAPBindingImpl;
20 import com.ibm.wsdl.extensions.soap.SOAPBodyImpl;
21 import com.ibm.wsdl.extensions.soap.SOAPHeaderImpl;
22 import com.ibm.wsdl.extensions.soap.SOAPOperationImpl;
23 import org.apache.axis.AxisFault;
24 import org.apache.axis.Constants;
25 import org.apache.axis.InternalException;
26 import org.apache.axis.Version;
27 import org.apache.axis.components.logger.LogFactory;
28 import org.apache.axis.constants.Style;
29 import org.apache.axis.constants.Use;
30 import org.apache.axis.description.FaultDesc;
31 import org.apache.axis.description.JavaServiceDesc;
32 import org.apache.axis.description.OperationDesc;
33 import org.apache.axis.description.ParameterDesc;
34 import org.apache.axis.description.ServiceDesc;
35 import org.apache.axis.encoding.TypeMapping;
36 import org.apache.axis.encoding.TypeMappingRegistry;
37 import org.apache.axis.encoding.TypeMappingRegistryImpl;
38 import org.apache.axis.utils.ClassUtils;
39 import org.apache.axis.utils.JavaUtils;
40 import org.apache.axis.utils.Messages;
41 import org.apache.axis.utils.XMLUtils;
42 import org.apache.axis.wsdl.symbolTable.SymbolTable;
43 import org.apache.commons.logging.Log;
44 import org.w3c.dom.Comment JavaDoc;
45 import org.w3c.dom.Document JavaDoc;
46 import org.w3c.dom.Element JavaDoc;
47 import org.w3c.dom.Text JavaDoc;
48 import org.xml.sax.SAXException JavaDoc;
49
50 import javax.wsdl.Binding;
51 import javax.wsdl.BindingFault;
52 import javax.wsdl.BindingInput;
53 import javax.wsdl.BindingOperation;
54 import javax.wsdl.BindingOutput;
55 import javax.wsdl.Definition;
56 import javax.wsdl.Fault;
57 import javax.wsdl.Import;
58 import javax.wsdl.Input;
59 import javax.wsdl.Message;
60 import javax.wsdl.Operation;
61 import javax.wsdl.OperationType;
62 import javax.wsdl.Output;
63 import javax.wsdl.Part;
64 import javax.wsdl.Port;
65 import javax.wsdl.PortType;
66 import javax.wsdl.Service;
67 import javax.wsdl.WSDLException;
68 import javax.wsdl.extensions.ExtensibilityElement;
69 import javax.wsdl.extensions.soap.SOAPAddress;
70 import javax.wsdl.extensions.soap.SOAPBinding;
71 import javax.wsdl.extensions.soap.SOAPBody;
72 import javax.wsdl.extensions.soap.SOAPFault;
73 import javax.wsdl.extensions.soap.SOAPHeader;
74 import javax.wsdl.extensions.soap.SOAPOperation;
75 import javax.wsdl.factory.WSDLFactory;
76 import javax.xml.namespace.QName JavaDoc;
77 import javax.xml.parsers.ParserConfigurationException JavaDoc;
78 import java.io.File JavaDoc;
79 import java.io.FileOutputStream JavaDoc;
80 import java.io.IOException JavaDoc;
81 import java.io.StringWriter JavaDoc;
82 import java.util.ArrayList JavaDoc;
83 import java.util.HashMap JavaDoc;
84 import java.util.Iterator JavaDoc;
85 import java.util.List JavaDoc;
86 import java.util.Map JavaDoc;
87 import java.util.StringTokenizer JavaDoc;
88 import java.util.Vector JavaDoc;
89
90 /**
91  * This class emits WSDL from Java classes. It is used by the ?WSDL
92  * Axis browser function and Java2WSDL commandline utility.
93  * See Java2WSDL and Java2WSDLFactory for more information.
94  *
95  * @author Glen Daniels (gdaniels@apache.org)
96  * @author Rich Scheuerle (scheu@us.ibm.com)
97  */

98 public class Emitter {
99
100     /** Field log */
101     protected static Log log = LogFactory.getLog(Emitter.class.getName());
102     // Generated WSDL Modes
103

104     /** Field MODE_ALL */
105     public static final int MODE_ALL = 0;
106
107     /** Field MODE_INTERFACE */
108     public static final int MODE_INTERFACE = 1;
109
110     /** Field MODE_IMPLEMENTATION */
111     public static final int MODE_IMPLEMENTATION = 2;
112
113     /** Field cls */
114     private Class JavaDoc cls;
115
116     /** Field extraClasses */
117     private Class JavaDoc[] extraClasses; // Extra classes to emit WSDL for
118

119     /** Field implCls */
120     private Class JavaDoc implCls; // Optional implementation class
121

122     /** Field allowedMethods */
123     private Vector JavaDoc allowedMethods = null; // Names of methods to consider
124

125     /** Field disallowedMethods */
126     private Vector JavaDoc disallowedMethods = null; // Names of methods to exclude
127

128     /** Field stopClasses */
129     private ArrayList JavaDoc stopClasses =
130             new ArrayList JavaDoc(); // class names which halt inheritace searches
131

132     /** Field useInheritedMethods */
133     private boolean useInheritedMethods = false;
134
135     /** Field intfNS */
136     private String JavaDoc intfNS;
137
138     /** Field implNS */
139     private String JavaDoc implNS;
140
141     /** Field inputSchema */
142     private String JavaDoc inputSchema;
143
144     /** Field inputWSDL */
145     private String JavaDoc inputWSDL;
146
147     /** Field locationUrl */
148     private String JavaDoc locationUrl;
149
150     /** Field importUrl */
151     private String JavaDoc importUrl;
152
153     /** Field servicePortName */
154     private String JavaDoc servicePortName;
155
156     /** Field serviceElementName */
157     private String JavaDoc serviceElementName;
158
159     /** Field targetService */
160     private String JavaDoc targetService = null;
161
162     /** Field description */
163     private String JavaDoc description;
164
165     /** Field style */
166     private Style style = Style.RPC;
167
168     /** Field use */
169     private Use use = null; // Default depends on style setting
170

171     /** Field tm */
172     private TypeMapping tm = null; // Registered type mapping
173

174     /** Field tmr */
175     private TypeMappingRegistry tmr = new TypeMappingRegistryImpl();
176
177     /** Field namespaces */
178     private Namespaces namespaces;
179
180     /** Field exceptionMsg */
181     private Map JavaDoc exceptionMsg = null;
182
183     /** Global element names already in use */
184     private Map JavaDoc usedElementNames;
185
186     /** Field encodingList */
187     private ArrayList JavaDoc encodingList;
188
189     /** Field types */
190     protected Types types;
191
192     /** Field clsName */
193     private String JavaDoc clsName;
194
195     /** Field portTypeName */
196     private String JavaDoc portTypeName;
197
198     /** Field bindingName */
199     private String JavaDoc bindingName;
200
201     /** Field serviceDesc */
202     private ServiceDesc serviceDesc;
203
204     /** Field serviceDesc2 */
205     private JavaServiceDesc serviceDesc2;
206
207     /** Field soapAction */
208     private String JavaDoc soapAction = "DEFAULT";
209     
210     /** Should we emit all mapped types in every WSDL? */
211     private boolean emitAllTypes = false;
212
213     /** Version string to put at top of WSDL */
214     private String JavaDoc versionMessage = null;
215     
216     /** The mapping of generated type qname to its corresponding java type. For use with java<-->wsdl roundtripping */
217     private HashMap JavaDoc qName2ClassMap;
218
219     // Style Modes
220

221     /** DEPRECATED - Indicates style=rpc use=encoded */
222     public static final int MODE_RPC = 0;
223
224     /** DEPRECATED - Indicates style=document use=literal */
225     public static final int MODE_DOCUMENT = 1;
226
227     /** DEPRECATED - Indicates style=wrapped use=literal */
228     public static final int MODE_DOC_WRAPPED = 2;
229
230     /**
231      * Construct Emitter.
232      * Set the contextual information using set* methods
233      * Invoke emit to emit the code
234      */

235     public Emitter() {
236
237         createDocumentFragment();
238
239         namespaces = new Namespaces();
240         exceptionMsg = new HashMap JavaDoc();
241         usedElementNames = new HashMap JavaDoc();
242         qName2ClassMap = new HashMap JavaDoc();
243     }
244
245     /**
246      * Generates WSDL documents for a given <code>Class</code>
247      *
248      * @param filename1 interface WSDL
249      * @param filename2 implementation WSDL
250      * @throws IOException
251      * @throws WSDLException
252      * @throws SAXException
253      * @throws ParserConfigurationException
254      */

255     public void emit(String JavaDoc filename1, String JavaDoc filename2)
256             throws IOException JavaDoc, WSDLException, SAXException JavaDoc,
257             ParserConfigurationException JavaDoc {
258
259         // Get interface and implementation defs
260
Definition intf = getIntfWSDL();
261         Definition impl = getImplWSDL();
262
263         // Supply reasonable file names if not supplied
264
if (filename1 == null) {
265             filename1 = getServicePortName() + "_interface.wsdl";
266         }
267
268         if (filename2 == null) {
269             filename2 = getServicePortName() + "_implementation.wsdl";
270         }
271
272         for (int i = 0; (extraClasses != null) && (i < extraClasses.length);
273              i++) {
274             types.writeTypeForPart(extraClasses[i], null);
275         }
276
277         // types.updateNamespaces();
278
// Write out the interface def
279
Document JavaDoc doc =
280                 WSDLFactory.newInstance().newWSDLWriter().getDocument(intf);
281
282         types.insertTypesFragment(doc);
283         prettyDocumentToFile(doc, filename1);
284
285         // Write out the implementation def
286
doc = WSDLFactory.newInstance().newWSDLWriter().getDocument(impl);
287
288         prettyDocumentToFile(doc, filename2);
289     }
290
291     /**
292      * Generates a complete WSDL document for a given <code>Class</code>
293      *
294      * @param filename WSDL
295      * @throws IOException
296      * @throws WSDLException
297      * @throws SAXException
298      * @throws ParserConfigurationException
299      */

300     public void emit(String JavaDoc filename)
301             throws IOException JavaDoc, WSDLException, SAXException JavaDoc,
302             ParserConfigurationException JavaDoc {
303         emit(filename, MODE_ALL);
304     }
305
306     /**
307      * Generates a WSDL document for a given <code>Class</code>.
308      * The WSDL generated is controlled by the mode parameter
309      * mode 0: All
310      * mode 1: Interface
311      * mode 2: Implementation
312      *
313      * @param mode generation mode - all, interface, implementation
314      * @return Document
315      * @throws IOException
316      * @throws WSDLException
317      * @throws SAXException
318      * @throws ParserConfigurationException
319      */

320     public Document JavaDoc emit(int mode)
321             throws IOException JavaDoc, WSDLException, SAXException JavaDoc,
322             ParserConfigurationException JavaDoc {
323
324         Document JavaDoc doc;
325         Definition def;
326
327         switch (mode) {
328
329             default:
330             case MODE_ALL:
331                 def = getWSDL();
332
333                 for (int i = 0;
334                      (extraClasses != null) && (i < extraClasses.length);
335                      i++) {
336                     types.writeTypeForPart(extraClasses[i], null);
337                 }
338
339                 // types.updateNamespaces();
340
doc = WSDLFactory.newInstance().newWSDLWriter().getDocument(
341                         def);
342
343                 types.insertTypesFragment(doc);
344                 break;
345
346             case MODE_INTERFACE:
347                 def = getIntfWSDL();
348
349                 for (int i = 0;
350                      (extraClasses != null) && (i < extraClasses.length);
351                      i++) {
352                     types.writeTypeForPart(extraClasses[i], null);
353                 }
354
355                 // types.updateNamespaces();
356
doc = WSDLFactory.newInstance().newWSDLWriter().getDocument(
357                         def);
358
359                 types.insertTypesFragment(doc);
360                 break;
361
362             case MODE_IMPLEMENTATION:
363                 def = getImplWSDL();
364                 doc = WSDLFactory.newInstance().newWSDLWriter().getDocument(
365                         def);
366                 break;
367         }
368
369         // Add Axis version info as comment to beginnning of generated WSDL
370
if (versionMessage == null) {
371             versionMessage = Messages.getMessage(
372                     "wsdlCreated00",
373                     XMLUtils.xmlEncodeString(Version.getVersion()));
374         }
375         // If version is empty string, don't emit one
376
if (versionMessage != null && versionMessage.length() > 0) {
377             Comment JavaDoc wsdlVersion = doc.createComment(versionMessage);
378             doc.getDocumentElement().insertBefore(
379                     wsdlVersion, doc.getDocumentElement().getFirstChild());
380         }
381
382         // Return the document
383
return doc;
384     }
385
386     /**
387      * Generates a String containing the WSDL for a given <code>Class</code>.
388      * The WSDL generated is controlled by the mode parameter
389      * mode 0: All
390      * mode 1: Interface
391      * mode 2: Implementation
392      *
393      * @param mode generation mode - all, interface, implementation
394      * @return String
395      * @throws IOException
396      * @throws WSDLException
397      * @throws SAXException
398      * @throws ParserConfigurationException
399      */

400     public String JavaDoc emitToString(int mode)
401             throws IOException JavaDoc, WSDLException, SAXException JavaDoc,
402             ParserConfigurationException JavaDoc {
403
404         Document JavaDoc doc = emit(mode);
405         StringWriter JavaDoc sw = new StringWriter JavaDoc();
406
407         XMLUtils.PrettyDocumentToWriter(doc, sw);
408
409         return sw.toString();
410     }
411
412     /**
413      * Generates a WSDL document for a given <code>Class</code>.
414      * The WSDL generated is controlled by the mode parameter
415      * mode 0: All
416      * mode 1: Interface
417      * mode 2: Implementation
418      *
419      * @param filename WSDL
420      * @param mode generation mode - all, interface, implementation
421      * @throws IOException
422      * @throws WSDLException
423      * @throws SAXException
424      * @throws ParserConfigurationException
425      */

426     public void emit(String JavaDoc filename, int mode)
427             throws IOException JavaDoc, WSDLException, SAXException JavaDoc,
428             ParserConfigurationException JavaDoc {
429
430         Document JavaDoc doc = emit(mode);
431
432         // Supply a reasonable file name if not supplied
433
if (filename == null) {
434             filename = getServicePortName();
435
436             switch (mode) {
437
438                 case MODE_ALL:
439                     filename += ".wsdl";
440                     break;
441
442                 case MODE_INTERFACE:
443                     filename += "_interface.wsdl";
444                     break;
445
446                 case MODE_IMPLEMENTATION:
447                     filename += "_implementation.wsdl";
448                     break;
449             }
450         }
451
452         prettyDocumentToFile(doc, filename);
453     }
454
455     /**
456      * Get a Full WSDL <code>Definition</code> for the current
457      * configuration parameters
458      *
459      * @return WSDL <code>Definition</code>
460      * @throws IOException
461      * @throws WSDLException
462      * @throws SAXException
463      * @throws ParserConfigurationException
464      */

465     public Definition getWSDL()
466             throws IOException JavaDoc, WSDLException, SAXException JavaDoc,
467             ParserConfigurationException JavaDoc {
468
469         // Invoke the init() method to ensure configuration is setup
470
init(MODE_ALL);
471
472         // Create a Definition for the output wsdl
473
Definition def = createDefinition();
474
475         // Write interface header
476
writeDefinitions(def, intfNS);
477
478         // Create Types
479
types = createTypes(def);
480
481         // Write the WSDL constructs and return full Definition
482
Binding binding = writeBinding(def, true);
483
484         writePortType(def, binding);
485         writeService(def, binding);
486
487         return def;
488     }
489
490     /**
491      * Get a interface WSDL <code>Definition</code> for the
492      * current configuration parameters
493      *
494      * @return WSDL <code>Definition</code>
495      * @throws IOException
496      * @throws WSDLException
497      * @throws SAXException
498      * @throws ParserConfigurationException
499      */

500     public Definition getIntfWSDL()
501             throws IOException JavaDoc, WSDLException, SAXException JavaDoc,
502             ParserConfigurationException JavaDoc {
503
504         // Invoke the init() method to ensure configuration is setup
505
init(MODE_INTERFACE);
506
507         // Create a definition for the output wsdl
508
Definition def = createDefinition();
509
510         // Write interface header
511
writeDefinitions(def, intfNS);
512
513         // Create Types
514
types = createTypes(def);
515
516         // Write the interface WSDL constructs and return the Definition
517
Binding binding = writeBinding(def, true);
518
519         writePortType(def, binding);
520
521         return def;
522     }
523
524     /**
525      * Get implementation WSDL <code>Definition</code> for the
526      * current configuration parameters
527      *
528      * @return WSDL <code>Definition</code>
529      * @throws IOException
530      * @throws WSDLException
531      * @throws SAXException
532      * @throws ParserConfigurationException
533      */

534     public Definition getImplWSDL()
535             throws IOException JavaDoc, WSDLException, SAXException JavaDoc,
536             ParserConfigurationException JavaDoc {
537
538         // Invoke the init() method to ensure configuration is setup
539
init(MODE_IMPLEMENTATION);
540
541         // Create a Definition for the output wsdl
542
Definition def = createDefinition();
543
544         // Write implementation header and import
545
writeDefinitions(def, implNS);
546         writeImport(def, intfNS, importUrl);
547
548         // Write the implementation WSDL constructs and return Definition
549
Binding binding = writeBinding(def, false); // Don't add binding to def
550

551         writeService(def, binding);
552
553         return def;
554     }
555
556     /**
557      * Invoked prior to building a definition to ensure parms
558      * and data are set up.
559      *
560      * @param mode
561      */

562     protected void init(int mode) {
563
564         // Default use depending on setting of style
565
if (use == null) {
566             if (style == Style.RPC) {
567                 use = Use.ENCODED;
568             } else {
569                 use = Use.LITERAL;
570             }
571         }
572
573         if (tm == null) {
574             String JavaDoc encodingStyle = "";
575             if (use == Use.ENCODED) {
576                 encodingStyle = Constants.URI_SOAP11_ENC;
577                 /** TODO : Set this correctly if we do SOAP 1.2 support here */
578             }
579             tm = (TypeMapping)tmr.getTypeMapping(encodingStyle);
580         }
581
582         // Set up a ServiceDesc to use to introspect the Service
583
if (serviceDesc == null) {
584             JavaServiceDesc javaServiceDesc = new JavaServiceDesc();
585             serviceDesc = javaServiceDesc;
586
587             javaServiceDesc.setImplClass(cls);
588
589             // Set the typeMapping to the one provided.
590
serviceDesc.setTypeMapping(tm);
591
592             javaServiceDesc.setStopClasses(stopClasses);
593             serviceDesc.setAllowedMethods(allowedMethods);
594             javaServiceDesc.setDisallowedMethods(disallowedMethods);
595             serviceDesc.setStyle(style);
596             serviceDesc.setUse(use);
597
598             // If the class passed in is a portType,
599
// there may be an implClass that is used to
600
// obtain the method parameter names. In this case,
601
// a serviceDesc2 is built to get the method parameter names.
602
if ((implCls != null) && (implCls != cls)
603                     && (serviceDesc2 == null)) {
604                 serviceDesc2 = new JavaServiceDesc();
605
606                 serviceDesc2.setImplClass(implCls);
607
608                 // Set the typeMapping to the one provided.
609
serviceDesc2.setTypeMapping(tm);
610
611                 serviceDesc2.setStopClasses(stopClasses);
612                 serviceDesc2.setAllowedMethods(allowedMethods);
613                 serviceDesc2.setDisallowedMethods(disallowedMethods);
614                 serviceDesc2.setStyle(style);
615             }
616         }
617
618         if (encodingList == null) {
619
620             // if cls contains a Class object with the service implementation use the Name of the
621
// class else use the service name
622
if (cls != null) {
623                 clsName = cls.getName();
624                 clsName = clsName.substring(clsName.lastIndexOf('.') + 1);
625             } else {
626                 clsName = getServiceDesc().getName();
627             }
628
629             // Default the portType name
630
if (getPortTypeName() == null) {
631                 setPortTypeName(clsName);
632             }
633
634             // Default the serviceElementName
635
if (getServiceElementName() == null) {
636                 setServiceElementName(getPortTypeName() + "Service");
637             }
638
639             // If service port name is null, construct it from location or className
640
if (getServicePortName() == null) {
641                 String JavaDoc name = getLocationUrl();
642
643                 if (name != null) {
644                     if (name.lastIndexOf('/') > 0) {
645                         name = name.substring(name.lastIndexOf('/') + 1);
646                     } else if (name.lastIndexOf('\\') > 0) {
647                         name = name.substring(name.lastIndexOf('\\') + 1);
648                     } else {
649                         name = null;
650                     }
651
652                     // if we got the name from the location, strip .jws from it
653
if ((name != null) && name.endsWith(".jws")) {
654                         name = name.substring(0, (name.length()
655                                 - ".jws".length()));
656                     }
657                 }
658
659                 if ((name == null) || name.equals("")) {
660                     name = clsName;
661                 }
662
663                 setServicePortName(name);
664             }
665
666             // Default the bindingName
667
if (getBindingName() == null) {
668                 setBindingName(getServicePortName() + "SoapBinding");
669             }
670
671             encodingList = new ArrayList JavaDoc();
672
673             encodingList.add(Constants.URI_DEFAULT_SOAP_ENC);
674
675             if (intfNS == null) {
676                 Package JavaDoc pkg = cls.getPackage();
677
678                 intfNS = namespaces.getCreate((pkg == null)
679                         ? null
680                         : pkg.getName());
681             }
682
683             // Default the implementation namespace to the interface
684
// namespace if not split wsdl mode.
685
if (implNS == null) {
686                 if (mode == MODE_ALL) {
687                     implNS = intfNS;
688                 } else {
689                     implNS = intfNS + "-impl";
690                 }
691             }
692
693             // set the namespaces in the serviceDesc(s)
694
serviceDesc.setDefaultNamespace(intfNS);
695
696             if (serviceDesc2 != null) {
697                 serviceDesc2.setDefaultNamespace(implNS);
698             }
699
700             if (cls != null) {
701                 String JavaDoc clsName = cls.getName();
702                 int idx = clsName.lastIndexOf(".");
703                 if (idx > 0) {
704                     String JavaDoc pkgName = clsName.substring(0, idx);
705                     namespaces.put(pkgName, intfNS, "intf");
706                 }
707             }
708
709             namespaces.putPrefix(implNS, "impl");
710         }
711     }
712
713     /**
714      * Build a Definition from the input wsdl file or create
715      * a new Definition
716      *
717      * @return WSDL Definition
718      * @throws WSDLException
719      * @throws SAXException
720      * @throws IOException
721      * @throws ParserConfigurationException
722      */

723     protected Definition createDefinition()
724             throws WSDLException, SAXException JavaDoc, IOException JavaDoc,
725             ParserConfigurationException JavaDoc {
726
727         Definition def;
728
729         if (inputWSDL == null) {
730             def = WSDLFactory.newInstance().newDefinition();
731         } else {
732             javax.wsdl.xml.WSDLReader reader =
733                     WSDLFactory.newInstance().newWSDLReader();
734             Document JavaDoc doc = XMLUtils.newDocument(inputWSDL);
735
736             def = reader.readWSDL(null, doc);
737
738             // The input wsdl types section is deleted. The
739
// types will be added back in at the end of processing.
740
def.setTypes(null);
741         }
742
743         return def;
744     }
745
746     /** Field standardTypes */
747     protected static TypeMapping standardTypes =
748             (TypeMapping) new org.apache.axis.encoding.TypeMappingRegistryImpl().getTypeMapping(
749                     null);
750
751     /**
752      * Build a Types object and load the input wsdl types
753      *
754      * @param def Corresponding wsdl Definition
755      * @return Types object
756      * @throws IOException
757      * @throws WSDLException
758      * @throws SAXException
759      * @throws ParserConfigurationException
760      */

761     protected Types createTypes(Definition def)
762             throws IOException JavaDoc, WSDLException, SAXException JavaDoc,
763             ParserConfigurationException JavaDoc {
764
765         types = new Types(def, tm, (TypeMapping)tmr.getDefaultTypeMapping(),
766                           namespaces, intfNS, stopClasses, serviceDesc, this);
767
768         if (inputWSDL != null) {
769             types.loadInputTypes(inputWSDL);
770         }
771
772         if (inputSchema != null) {
773             StringTokenizer JavaDoc tokenizer = new StringTokenizer JavaDoc(inputSchema, ", ");
774
775             while (tokenizer.hasMoreTokens()) {
776                 String JavaDoc token = tokenizer.nextToken();
777
778                 types.loadInputSchema(token);
779             }
780         }
781         
782         // If we're supposed to emit all mapped types, do it now.
783
if (emitAllTypes && tm != null) {
784             Class JavaDoc[] mappedTypes = tm.getAllClasses();
785             
786             for (int i = 0; i < mappedTypes.length; i++) {
787                 Class JavaDoc mappedType = mappedTypes[i];
788                 QName JavaDoc name = tm.getTypeQName(mappedType);
789                 if (name.getLocalPart().indexOf(SymbolTable.ANON_TOKEN) != -1) {
790                     // If this is an anonymous type, it doesn't need to be
791
// written out here (and trying to do so will generate an
792
// error). Skip it.
793
continue;
794                 }
795                 
796                 /**
797                  * If it's a non-standard type, make sure it shows up in
798                  * our WSDL
799                  */

800                 if (standardTypes.getSerializer(mappedType) == null) {
801                     types.writeTypeForPart(mappedType, name);
802                 }
803             }
804             
805             // Don't bother checking for subtypes, since we already wrote
806
// all the possibilities.
807
types.mappedTypes = null;
808         }
809         
810         return types;
811     }
812     
813     /**
814      * Create a documentation element
815      *
816      * @param documentation
817      * @return
818      */

819     protected Element JavaDoc createDocumentationElement(String JavaDoc documentation) {
820         Element JavaDoc element = docHolder.createElementNS(Constants.NS_URI_WSDL11, "documentation");
821         element.setPrefix(Constants.NS_PREFIX_WSDL);
822         Text JavaDoc textNode =
823                 docHolder.createTextNode(documentation);
824
825         element.appendChild(textNode);
826         return element;
827     }
828     
829     /**
830      * Create the definition header information.
831      *
832      * @param def <code>Definition</code>
833      * @param tns target namespace
834      */

835     protected void writeDefinitions(Definition def, String JavaDoc tns) {
836
837         def.setTargetNamespace(tns);
838         def.addNamespace("intf", intfNS);
839         def.addNamespace("impl", implNS);
840         def.addNamespace(Constants.NS_PREFIX_WSDL_SOAP,
841                 Constants.URI_WSDL11_SOAP);
842         namespaces.putPrefix(Constants.URI_WSDL11_SOAP,
843                 Constants.NS_PREFIX_WSDL_SOAP);
844         def.addNamespace(Constants.NS_PREFIX_WSDL, Constants.NS_URI_WSDL11);
845         namespaces.putPrefix(Constants.NS_URI_WSDL11, Constants.NS_PREFIX_WSDL);
846
847         if (use == Use.ENCODED) {
848             def.addNamespace(Constants.NS_PREFIX_SOAP_ENC,
849                     Constants.URI_DEFAULT_SOAP_ENC);
850             namespaces.putPrefix(Constants.URI_DEFAULT_SOAP_ENC,
851                     Constants.NS_PREFIX_SOAP_ENC);
852         }
853
854         def.addNamespace(Constants.NS_PREFIX_SCHEMA_XSD,
855                 Constants.URI_DEFAULT_SCHEMA_XSD);
856         namespaces.putPrefix(Constants.URI_DEFAULT_SCHEMA_XSD,
857                 Constants.NS_PREFIX_SCHEMA_XSD);
858         def.addNamespace(Constants.NS_PREFIX_XMLSOAP, Constants.NS_URI_XMLSOAP);
859         namespaces.putPrefix(Constants.NS_URI_XMLSOAP,
860                 Constants.NS_PREFIX_XMLSOAP);
861     }
862
863     /**
864      * Create and add an import
865      *
866      * @param def <code>Definition</code>
867      * @param tns target namespace
868      * @param loc target location
869      */

870     protected void writeImport(Definition def, String JavaDoc tns, String JavaDoc loc) {
871
872         Import imp = def.createImport();
873
874         imp.setNamespaceURI(tns);
875
876         if ((loc != null) && !loc.equals("")) {
877             imp.setLocationURI(loc);
878         }
879
880         def.addImport(imp);
881     }
882
883     /**
884      * Create the binding.
885      *
886      * @param def <code>Definition</code>
887      * @param add true if binding should be added to the def
888      * @return
889      */

890     protected Binding writeBinding(Definition def, boolean add) {
891
892         QName JavaDoc bindingQName = new QName JavaDoc(intfNS, getBindingName());
893
894         // If a binding already exists, don't replace it.
895
Binding binding = def.getBinding(bindingQName);
896
897         if (binding != null) {
898             return binding;
899         }
900
901         // Create a binding
902
binding = def.createBinding();
903
904         binding.setUndefined(false);
905         binding.setQName(bindingQName);
906
907         SOAPBinding soapBinding = new SOAPBindingImpl();
908         String JavaDoc styleStr = (style == Style.RPC)
909                 ? "rpc"
910                 : "document";
911
912         soapBinding.setStyle(styleStr);
913         soapBinding.setTransportURI(Constants.URI_SOAP11_HTTP);
914         binding.addExtensibilityElement(soapBinding);
915
916         if (add) {
917             def.addBinding(binding);
918         }
919
920         return binding;
921     }
922
923     /** Field docHolder */
924     Document JavaDoc docHolder;
925
926     /**
927      * Method createDocumentFragment
928      */

929     private void createDocumentFragment() {
930
931         try {
932             this.docHolder = XMLUtils.newDocument();
933         } catch (ParserConfigurationException JavaDoc e) {
934
935             // This should not occur
936
throw new InternalException(e);
937         }
938     }
939
940     /**
941      * Create the service.
942      *
943      * @param def
944      * @param binding
945      */

946     protected void writeService(Definition def, Binding binding) {
947
948         QName JavaDoc serviceElementQName = new QName JavaDoc(implNS, getServiceElementName());
949
950         // Locate an existing service, or get a new service
951
Service service = def.getService(serviceElementQName);
952
953         if (service == null) {
954             service = def.createService();
955
956             service.setQName(serviceElementQName);
957             def.addService(service);
958         }
959
960         if (description != null) {
961             service.setDocumentationElement(
962                     createDocumentationElement(description));
963         } else if (serviceDesc.getDocumentation() != null) {
964             service.setDocumentationElement(
965                     createDocumentationElement(
966                             serviceDesc.getDocumentation()));
967         }
968
969         // Add the port
970
Port port = def.createPort();
971
972         port.setBinding(binding);
973
974         // Probably should use the end of the location Url
975
port.setName(getServicePortName());
976
977         SOAPAddress addr = new SOAPAddressImpl();
978
979         addr.setLocationURI(locationUrl);
980         port.addExtensibilityElement(addr);
981         service.addPort(port);
982     }
983
984     /**
985      * Create a PortType
986      *
987      * @param def
988      * @param binding
989      * @throws WSDLException
990      * @throws AxisFault
991      */

992     protected void writePortType(Definition def, Binding binding)
993             throws WSDLException, AxisFault {
994
995         QName JavaDoc portTypeQName = new QName JavaDoc(intfNS, getPortTypeName());
996
997         // Get or create a portType
998
PortType portType = def.getPortType(portTypeQName);
999         boolean newPortType = false;
1000
1001        if (portType == null) {
1002            portType = def.createPortType();
1003
1004            portType.setUndefined(false);
1005            portType.setQName(portTypeQName);
1006
1007            newPortType = true;
1008        } else if (binding.getBindingOperations().size() > 0) {
1009
1010            // If both portType and binding already exist,
1011
// no additional processing is needed.
1012
return;
1013        }
1014
1015        // Add the port and binding operations.
1016
ArrayList JavaDoc operations = serviceDesc.getOperations();
1017
1018        for (Iterator JavaDoc i = operations.iterator(); i.hasNext();) {
1019            OperationDesc thisOper = (OperationDesc) i.next();
1020            BindingOperation bindingOper = writeOperation(def, binding,
1021                    thisOper);
1022            Operation oper = bindingOper.getOperation();
1023            OperationDesc messageOper = thisOper;
1024
1025            // add the documentation to oper
1026
if (messageOper.getDocumentation() != null) {
1027                oper.setDocumentationElement(
1028                        createDocumentationElement(
1029                                messageOper.getDocumentation()));
1030            }
1031
1032            if (serviceDesc2 != null) {
1033
1034                // If a serviceDesc containing an impl class is provided,
1035
// try and locate the corresponding operation
1036
// (same name, same parm types and modes). If a
1037
// corresponding operation is found, it is sent
1038
// to the writeMessages method so that its parameter
1039
// names will be used in the wsdl file.
1040
OperationDesc[] operArray =
1041                        serviceDesc2.getOperationsByName(thisOper.getName());
1042                boolean found = false;
1043
1044                if (operArray != null) {
1045                    for (int j = 0; (j < operArray.length) && !found; j++) {
1046                        OperationDesc tryOper = operArray[j];
1047
1048                        if (tryOper.getParameters().size()
1049                                == thisOper.getParameters().size()) {
1050                            boolean parmsMatch = true;
1051
1052                            for (int k =
1053                                    0; (k < thisOper.getParameters().size())
1054                                    && parmsMatch; k++) {
1055                                if ((tryOper.getParameter(
1056                                        k).getMode() != thisOper.getParameter(
1057                                                k).getMode())
1058                                        || (!tryOper.getParameter(
1059                                                k).getJavaType().equals(
1060                                                        thisOper.getParameter(
1061                                                                k).getJavaType()))) {
1062                                    parmsMatch = false;
1063                                }
1064                            }
1065
1066                            if (parmsMatch) {
1067                                messageOper = tryOper;
1068                                found = true;
1069                            }
1070                        }
1071                    }
1072                }
1073            }
1074
1075            writeMessages(def, oper, messageOper, bindingOper);
1076
1077            if (newPortType) {
1078                portType.addOperation(oper);
1079            }
1080        }
1081
1082        if (newPortType) {
1083            def.addPortType(portType);
1084        }
1085
1086        binding.setPortType(portType);
1087    }
1088
1089    /**
1090     * Create a Message
1091     *
1092     * @param def Definition, the WSDL definition
1093     * @param oper Operation, the wsdl operation
1094     * @param desc OperationDesc, the Operation Description
1095     * @param bindingOper BindingOperation, corresponding Binding Operation
1096     * @throws WSDLException
1097     * @throws AxisFault
1098     */

1099    protected void writeMessages(Definition def,
1100                                 Operation oper,
1101                                 OperationDesc desc,
1102                                 BindingOperation bindingOper)
1103            throws WSDLException, AxisFault {
1104
1105        Input input = def.createInput();
1106        Message msg = writeRequestMessage(def, desc, bindingOper);
1107
1108        input.setMessage(msg);
1109
1110        // Give the input element a name that matches the
1111
// message. This is necessary for overloading.
1112
// The msg QName is unique.
1113
String JavaDoc name = msg.getQName().getLocalPart();
1114
1115        input.setName(name);
1116        bindingOper.getBindingInput().setName(name);
1117        oper.setInput(input);
1118        def.addMessage(msg);
1119        
1120        if (OperationType.REQUEST_RESPONSE.equals(desc.getMep())) {
1121            msg = writeResponseMessage(def, desc, bindingOper);
1122            
1123            Output output = def.createOutput();
1124            
1125            output.setMessage(msg);
1126            
1127            // Give the output element a name that matches the
1128
// message. This is necessary for overloading.
1129
// The message QName is unique.
1130
name = msg.getQName().getLocalPart();
1131            
1132            output.setName(name);
1133            bindingOper.getBindingOutput().setName(name);
1134            oper.setOutput(output);
1135            def.addMessage(msg);
1136        }
1137        
1138        ArrayList JavaDoc exceptions = desc.getFaults();
1139
1140        for (int i = 0; (exceptions != null) && (i < exceptions.size()); i++) {
1141            FaultDesc faultDesc = (FaultDesc) exceptions.get(i);
1142
1143            msg = writeFaultMessage(def, faultDesc);
1144
1145            // Add the fault to the portType
1146
Fault fault = def.createFault();
1147
1148            fault.setMessage(msg);
1149            fault.setName(faultDesc.getName());
1150            oper.addFault(fault);
1151
1152            // Add the fault to the binding
1153
BindingFault bFault = def.createBindingFault();
1154
1155            bFault.setName(faultDesc.getName());
1156
1157            SOAPFault soapFault = writeSOAPFault(faultDesc);
1158
1159            bFault.addExtensibilityElement(soapFault);
1160            bindingOper.addBindingFault(bFault);
1161
1162            // Add the fault message
1163
if (def.getMessage(msg.getQName()) == null) {
1164                def.addMessage(msg);
1165            }
1166        }
1167
1168        // Set the parameter ordering using the parameter names
1169
ArrayList JavaDoc parameters = desc.getParameters();
1170        Vector JavaDoc names = new Vector JavaDoc();
1171
1172        for (int i = 0; i < parameters.size(); i++) {
1173            ParameterDesc param = (ParameterDesc) parameters.get(i);
1174
1175            names.add(param.getName());
1176        }
1177
1178        if (names.size() > 0) {
1179            if (style == Style.WRAPPED) {
1180                names.clear();
1181            } else {
1182                oper.setParameterOrdering(names);
1183            }
1184        }
1185    }
1186
1187    /**
1188     * Create a Operation
1189     *
1190     * @param def
1191     * @param binding
1192     * @param desc
1193     * @return
1194     */

1195    protected BindingOperation writeOperation(Definition def, Binding binding,
1196                                              OperationDesc desc) {
1197
1198        Operation oper = def.createOperation();
1199
1200        QName JavaDoc elementQName = desc.getElementQName();
1201        if(elementQName != null && elementQName.getLocalPart() != null) {
1202            oper.setName(elementQName.getLocalPart());
1203        } else {
1204            oper.setName(desc.getName());
1205        }
1206        oper.setUndefined(false);
1207
1208        return writeBindingOperation(def, binding, oper, desc);
1209    }
1210
1211    /**
1212     * Create a Binding Operation
1213     *
1214     * @param def
1215     * @param binding
1216     * @param oper
1217     * @param desc
1218     * @return
1219     */

1220    protected BindingOperation writeBindingOperation(Definition def,
1221                                                     Binding binding,
1222                                                     Operation oper,
1223                                                     OperationDesc desc) {
1224
1225        BindingOperation bindingOper = def.createBindingOperation();
1226        BindingInput bindingInput = def.createBindingInput();
1227        BindingOutput bindingOutput = null;
1228        
1229        // TODO : Make this deal with all MEPs
1230
if (OperationType.REQUEST_RESPONSE.equals(desc.getMep()))
1231            bindingOutput = def.createBindingOutput();
1232
1233        bindingOper.setName(oper.getName());
1234        bindingOper.setOperation(oper);
1235
1236        SOAPOperation soapOper = new SOAPOperationImpl();
1237
1238        // If the soapAction option is OPERATION, force
1239
// soapAction to the name of the operation. If NONE,
1240
// force soapAction to "".
1241
// Otherwise use the information in the operationDesc.
1242
String JavaDoc soapAction;
1243        if (getSoapAction().equalsIgnoreCase("OPERATION")) {
1244            soapAction = oper.getName();
1245        } else if (getSoapAction().equalsIgnoreCase("NONE")) {
1246            soapAction = "";
1247        } else {
1248            soapAction = desc.getSoapAction();
1249
1250            if (soapAction == null) {
1251                soapAction = "";
1252            }
1253        }
1254
1255        soapOper.setSoapActionURI(soapAction);
1256
1257        // Until we have per-operation configuration, this will always be
1258
// the same as the binding default.
1259
// soapOper.setStyle("rpc");
1260
bindingOper.addExtensibilityElement(soapOper);
1261
1262        // Add soap:body element to the binding <input> element
1263
ExtensibilityElement inputBody = writeSOAPBody(desc.getElementQName());
1264        bindingInput.addExtensibilityElement(inputBody);
1265
1266        // add soap:headers, if any, to binding <input> element
1267
// only when we write the Message and parts.
1268

1269        // Add soap:body element to the binding <output> element
1270
if (bindingOutput != null) {
1271            ExtensibilityElement outputBody = writeSOAPBody(desc.getReturnQName());
1272            bindingOutput.addExtensibilityElement(outputBody);
1273            bindingOper.setBindingOutput(bindingOutput);
1274
1275            // add soap:headers, if any, to binding <output> element
1276
// only when we write the Message and parts.
1277
}
1278        
1279        // Add input to operation
1280
bindingOper.setBindingInput(bindingInput);
1281
1282        // Faults clause
1283
// Comment out the following part
1284
// because it actually does the same thing as in writeMessages.
1285
/*
1286        ArrayList faultList = desc.getFaults();
1287
1288        if (faultList != null) {
1289            for (Iterator it = faultList.iterator(); it.hasNext();) {
1290                FaultDesc faultDesc = (FaultDesc) it.next();
1291
1292                // Get a soap:fault
1293                ExtensibilityElement soapFault = writeSOAPFault(faultDesc);
1294
1295                // Get a wsdl:fault to put the soap:fault in
1296                BindingFault bindingFault = new BindingFaultImpl();
1297
1298                bindingFault.setName(faultDesc.getName());
1299                bindingFault.addExtensibilityElement(soapFault);
1300                bindingOper.addBindingFault(bindingFault);
1301            }
1302        }
1303        */

1304
1305        binding.addBindingOperation(bindingOper);
1306
1307        return bindingOper;
1308    }
1309
1310    /**
1311     * Create a SOAPHeader element
1312     */

1313    protected SOAPHeader writeSOAPHeader(ParameterDesc p, QName JavaDoc messageQName, String JavaDoc partName)
1314    {
1315        SOAPHeaderImpl soapHeader = new SOAPHeaderImpl();
1316
1317        // for now, if its document, it is literal use.
1318
if (use == Use.ENCODED) {
1319            soapHeader.setUse("encoded");
1320            soapHeader.setEncodingStyles(encodingList);
1321        } else {
1322            soapHeader.setUse("literal");
1323        }
1324
1325        // Set namespace
1326
if (targetService == null) {
1327            soapHeader.setNamespaceURI(intfNS);
1328        } else {
1329            soapHeader.setNamespaceURI(targetService);
1330        }
1331        QName JavaDoc headerQName = p.getQName();
1332        if ((headerQName != null) && !headerQName.getNamespaceURI().equals("")) {
1333            soapHeader.setNamespaceURI(headerQName.getNamespaceURI());
1334        }
1335
1336        // Set the Message and Part information
1337
soapHeader.setMessage(messageQName);
1338         soapHeader.setPart(partName);
1339
1340        return soapHeader;
1341    }
1342
1343    /**
1344     * Method writeSOAPBody
1345     *
1346     * @param operQName
1347     * @return
1348     */

1349    protected ExtensibilityElement writeSOAPBody(QName JavaDoc operQName) {
1350
1351        SOAPBody soapBody = new SOAPBodyImpl();
1352
1353        // for now, if its document, it is literal use.
1354
if (use == Use.ENCODED) {
1355            soapBody.setUse("encoded");
1356            soapBody.setEncodingStyles(encodingList);
1357        } else {
1358            soapBody.setUse("literal");
1359        }
1360
1361        if (style == Style.RPC) {
1362            if (targetService == null) {
1363                soapBody.setNamespaceURI(intfNS);
1364            } else {
1365                soapBody.setNamespaceURI(targetService);
1366            }
1367    
1368            if ((operQName != null) && !operQName.getNamespaceURI().equals("")) {
1369                soapBody.setNamespaceURI(operQName.getNamespaceURI());
1370            }
1371        }
1372
1373        // The parts attribute will get set if we have headers.
1374
// This gets done when the Message & parts are generated
1375
// soapBody.setParts(...);
1376

1377        return soapBody;
1378    } // writeSOAPBody
1379

1380    /**
1381     * Method writeSOAPFault
1382     *
1383     * @param faultDesc
1384     * @return
1385     */

1386    protected SOAPFault writeSOAPFault(FaultDesc faultDesc) {
1387
1388        SOAPFault soapFault = new com.ibm.wsdl.extensions.soap.SOAPFaultImpl();
1389
1390        soapFault.setName(faultDesc.getName());
1391
1392        if (use != Use.ENCODED) {
1393            soapFault.setUse("literal");
1394
1395            // no namespace for literal, gets it from the element
1396
} else {
1397            soapFault.setUse("encoded");
1398            soapFault.setEncodingStyles(encodingList);
1399
1400            // Set the namespace from the fault QName if it exists
1401
// otherwise use the target (or interface) namespace
1402
QName JavaDoc faultQName = faultDesc.getQName();
1403
1404            if ((faultQName != null)
1405                    && !faultQName.getNamespaceURI().equals("")) {
1406                soapFault.setNamespaceURI(faultQName.getNamespaceURI());
1407            } else {
1408                if (targetService == null) {
1409                    soapFault.setNamespaceURI(intfNS);
1410                } else {
1411                    soapFault.setNamespaceURI(targetService);
1412                }
1413            }
1414        }
1415
1416        return soapFault;
1417    } // writeSOAPFault
1418

1419    /**
1420     * Create a Request Message
1421     *
1422     * @param def
1423     * @param oper
1424     * @return
1425     * @throws WSDLException
1426     * @throws AxisFault
1427     */

1428    protected Message writeRequestMessage(Definition def, OperationDesc oper, BindingOperation bindop)
1429            throws WSDLException, AxisFault
1430    {
1431
1432        String JavaDoc partName;
1433        ArrayList JavaDoc bodyParts = new ArrayList JavaDoc();
1434        ArrayList JavaDoc parameters = oper.getAllInParams();
1435
1436        Message msg = def.createMessage();
1437        QName JavaDoc qName = createMessageName(def,
1438                getRequestQName(oper).getLocalPart() + "Request");
1439
1440        msg.setQName(qName);
1441        msg.setUndefined(false);
1442
1443        // output all the parts for headers
1444
boolean headers = writeHeaderParts(def, parameters, bindop, msg, true);
1445
1446        if (oper.getStyle() == Style.MESSAGE) {
1447
1448            // If this is a MESSAGE-style operation, just write out
1449
// <xsd:any> for now.
1450
// TODO: Support custom schema in WSDD for these operations
1451
QName JavaDoc qname = oper.getElementQName();
1452            types.writeElementDecl(qname, Object JavaDoc.class,
1453                                   Constants.XSD_ANYTYPE, false, null);
1454
1455            Part part = def.createPart();
1456
1457            part.setName("part");
1458            part.setElementName(qname);
1459            msg.addPart(part);
1460            bodyParts.add(part.getName());
1461
1462        } else if (oper.getStyle() == Style.WRAPPED) {
1463
1464            // If we're WRAPPED, write the wrapper element first, and then
1465
// fill in any params. If there aren't any params, we'll see
1466
// an empty <complexType/> for the wrapper element.
1467
partName = writeWrapperPart(def, msg, oper, true);
1468            bodyParts.add(partName);
1469
1470        } else {
1471            //Now we're either DOCUMENT or RPC. If we're doing doc/lit, and in the
1472
//case of mulitple input params, we would warn user saying request
1473
//message's type information is being written out as multiple parts
1474
//than one single complexType and to interop with other soap stacks
1475
//that do doc/lit by default, user might want to publish his service
1476
//as a WRAPPED-LITERAL service instead.
1477
//see http://issues.apache.org/jira/browse/AXIS-2017
1478
if(oper.getStyle() == Style.DOCUMENT && parameters.size()>1 ) {
1479                System.out.println(Messages.getMessage("warnDocLitInteropMultipleInputParts"));
1480            }
1481
1482            // write a part for each non-header parameter
1483
for (int i = 0; i < parameters.size(); i++) {
1484                ParameterDesc parameter = (ParameterDesc) parameters.get(i);
1485                if (!parameter.isInHeader() && !parameter.isOutHeader()) {
1486                    partName = writePartToMessage(def, msg, true, parameter);
1487                    bodyParts.add(partName);
1488                }
1489            }
1490        }
1491
1492        // If we have headers, we must fill in the parts attribute of soap:body
1493
// if not, we just leave it out (which means all parts)
1494
if (headers) {
1495            // Find soap:body in binding
1496
List JavaDoc extensibilityElements = bindop.getBindingInput().getExtensibilityElements();
1497            for (int i = 0; i < extensibilityElements.size(); i++)
1498            {
1499                Object JavaDoc ele = extensibilityElements.get(i);
1500                if (ele instanceof SOAPBodyImpl)
1501                {
1502                    SOAPBodyImpl soapBody = (SOAPBodyImpl) ele;
1503                    soapBody.setParts(bodyParts);
1504                }
1505            }
1506        }
1507
1508        return msg;
1509    }
1510
1511    /**
1512     * Create parts of a Message for header parameters and write then in
1513     * to the provided Message element. Also create a soap:header element
1514     * in the binding
1515     *
1516     * @param parameters the list of parameters for the current operation
1517     * @param bindop the current bindingOperation
1518     * @param msg the message to add the parts to
1519     * @param request true if we are do an input message, false if it is output
1520     * @return true if we wrote any header parts
1521     */

1522    private boolean writeHeaderParts(Definition def,
1523                                     ArrayList JavaDoc parameters,
1524                                     BindingOperation bindop,
1525                                     Message msg,
1526                                     boolean request) throws WSDLException, AxisFault
1527    {
1528        boolean wroteHeaderParts = false;
1529        String JavaDoc partName;
1530
1531        // Loop over all the parameters for this operation
1532
for (int i = 0; i < parameters.size(); i++) {
1533            ParameterDesc parameter = (ParameterDesc) parameters.get(i);
1534
1535            // write the input or output header parts in to the Message
1536
if (request && parameter.isInHeader()) {
1537                // put part in message
1538
partName = writePartToMessage(def, msg, request, parameter);
1539                // Create a soap:header element
1540
SOAPHeader hdr = writeSOAPHeader(parameter, msg.getQName(), partName);
1541                // put it in the binding <input> element
1542
bindop.getBindingInput().addExtensibilityElement(hdr);
1543                wroteHeaderParts = true;
1544            }
1545            else if (!request && parameter.isOutHeader()) {
1546                // put part in message
1547
partName = writePartToMessage(def, msg, request, parameter);
1548                // Create a soap:header element
1549
SOAPHeader hdr = writeSOAPHeader(parameter, msg.getQName(), partName);
1550                // put it in the binding <output> element
1551
bindop.getBindingOutput().addExtensibilityElement(hdr);
1552                wroteHeaderParts = true;
1553            }
1554            else {
1555                continue; // body part
1556
}
1557        }
1558        return wroteHeaderParts;
1559    }
1560
1561    /**
1562     * Method getRequestQName
1563     *
1564     * @param oper
1565     * @return
1566     */

1567    protected QName JavaDoc getRequestQName(OperationDesc oper) {
1568
1569        qualifyOperation(oper);
1570
1571        QName JavaDoc qname = oper.getElementQName();
1572
1573        if (qname == null) {
1574            qname = new QName JavaDoc(oper.getName());
1575        }
1576
1577        return qname;
1578    }
1579
1580    /**
1581     * Method qualifyOperation
1582     *
1583     * @param oper
1584     */

1585    private void qualifyOperation(OperationDesc oper) {
1586
1587        if ((style == Style.WRAPPED) && (use == Use.LITERAL)) {
1588            QName JavaDoc qname = oper.getElementQName();
1589
1590            if (qname == null) {
1591                qname = new QName JavaDoc(intfNS, oper.getName());
1592            } else if (qname.getNamespaceURI().equals("")) {
1593                qname = new QName JavaDoc(intfNS, qname.getLocalPart());
1594            }
1595
1596            oper.setElementQName(qname);
1597        }
1598    }
1599
1600    /**
1601     * Method getResponseQName
1602     *
1603     * @param oper
1604     * @return
1605     */

1606    protected QName JavaDoc getResponseQName(OperationDesc oper) {
1607
1608        qualifyOperation(oper);
1609
1610        QName JavaDoc qname = oper.getElementQName();
1611
1612        if (qname == null) {
1613            return new QName JavaDoc(oper.getName() + "Response");
1614        }
1615
1616        return new QName JavaDoc(qname.getNamespaceURI(),
1617                qname.getLocalPart() + "Response");
1618    }
1619
1620    /**
1621     * Write out the schema definition for a WRAPPED operation request or
1622     * response.
1623     *
1624     * @param def
1625     * @param msg
1626     * @param oper
1627     * @param request
1628     * @return the name of the part the was written
1629     * @throws AxisFault
1630     */

1631    public String JavaDoc writeWrapperPart(
1632            Definition def, Message msg, OperationDesc oper, boolean request)
1633            throws AxisFault {
1634
1635        QName JavaDoc qname = request
1636                ? getRequestQName(oper)
1637                : getResponseQName(oper);
1638
1639        boolean hasParams;
1640        if (request) {
1641            hasParams = (oper.getNumInParams() > 0);
1642        } else {
1643            if (oper.getReturnClass() != void.class) {
1644                hasParams = true;
1645            } else {
1646                hasParams = (oper.getNumOutParams() > 0);
1647            }
1648        }
1649
1650        // First write the wrapper element itself.
1651
Element JavaDoc sequence = types.writeWrapperElement(qname, request, hasParams);
1652
1653        // If we got anything back above, there must be parameters in the
1654
// operation, and it's a <sequence> node in which to write them...
1655
if (sequence != null) {
1656            ArrayList JavaDoc parameters = request
1657                    ? oper.getAllInParams()
1658                    : oper.getAllOutParams();
1659
1660            if (!request) {
1661                String JavaDoc retName;
1662                
1663                if (oper.getReturnQName() == null) {
1664                    retName = oper.getName() + "Return";
1665                } else {
1666                    retName = oper.getReturnQName().getLocalPart();
1667                }
1668
1669                types.writeWrappedParameter(sequence, retName,
1670                        oper.getReturnType(),
1671                        oper.getReturnClass());
1672            }
1673
1674            for (int i = 0; i < parameters.size(); i++) {
1675                ParameterDesc parameter = (ParameterDesc) parameters.get(i);
1676
1677                // avoid headers
1678
if (!parameter.isInHeader() && !parameter.isOutHeader())
1679                {
1680                    types.writeWrappedParameter(sequence,
1681                                                parameter.getName(),
1682                                                parameter.getTypeQName(),
1683                                                parameter.getJavaType());
1684                }
1685            }
1686        }
1687
1688        // Finally write the part itself
1689
Part part = def.createPart();
1690
1691        part.setName("parameters"); // We always use "parameters"
1692
part.setElementName(qname);
1693        msg.addPart(part);
1694
1695        return part.getName();
1696    }
1697
1698    /**
1699     * Create a Response Message
1700     *
1701     * @param def
1702     * @param desc
1703     * @return
1704     * @throws WSDLException
1705     * @throws AxisFault
1706     */

1707    protected Message writeResponseMessage(Definition def, OperationDesc desc, BindingOperation bindop)
1708            throws WSDLException, AxisFault
1709    {
1710        String JavaDoc partName;
1711        ArrayList JavaDoc bodyParts = new ArrayList JavaDoc();
1712        ArrayList JavaDoc parameters = desc.getAllOutParams();
1713
1714        Message msg = def.createMessage();
1715        QName JavaDoc qName =
1716                createMessageName(def, getResponseQName(desc).getLocalPart());
1717
1718        msg.setQName(qName);
1719        msg.setUndefined(false);
1720
1721        // output all the parts for headers
1722
boolean headers = writeHeaderParts(def, parameters, bindop, msg, false);
1723
1724        if (desc.getStyle() == Style.WRAPPED) {
1725            partName = writeWrapperPart(def, msg, desc, false);
1726            bodyParts.add(partName);
1727        } else {
1728
1729            // Write the return value part
1730
ParameterDesc retParam = new ParameterDesc();
1731
1732            if (desc.getReturnQName() == null) {
1733                String JavaDoc ns = "";
1734
1735                if (desc.getStyle() != Style.RPC) {
1736                    ns = getServiceDesc().getDefaultNamespace();
1737
1738                    if ((ns == null) || "".equals(ns)) {
1739                        ns = "http://ws.apache.org/axis/defaultNS";
1740                    }
1741                }
1742
1743                retParam.setQName(new QName JavaDoc(ns, desc.getName() + "Return"));
1744            } else {
1745                retParam.setQName(desc.getReturnQName());
1746            }
1747
1748            retParam.setTypeQName(desc.getReturnType());
1749            retParam.setMode(ParameterDesc.OUT);
1750            retParam.setIsReturn(true);
1751            retParam.setJavaType(desc.getReturnClass());
1752            String JavaDoc returnPartName = writePartToMessage(def, msg, false, retParam);
1753            bodyParts.add(returnPartName);
1754
1755            // write a part for each non-header parameter
1756
for (int i = 0; i < parameters.size(); i++) {
1757                ParameterDesc parameter = (ParameterDesc) parameters.get(i);
1758                if (!parameter.isInHeader() && !parameter.isOutHeader()) {
1759                    partName = writePartToMessage(def, msg, false, parameter);
1760                    bodyParts.add(partName);
1761                }
1762            }
1763
1764        }
1765        // If we have headers, we must fill in the parts attribute of soap:body
1766
// if not, we just leave it out (which means all parts)
1767
if (headers) {
1768            // Find soap:body in binding
1769
List JavaDoc extensibilityElements = bindop.getBindingOutput().getExtensibilityElements();
1770            for (int i = 0; i < extensibilityElements.size(); i++)
1771            {
1772                Object JavaDoc ele = extensibilityElements.get(i);
1773                if (ele instanceof SOAPBodyImpl)
1774                {
1775                    SOAPBodyImpl soapBody = (SOAPBodyImpl) ele;
1776                    soapBody.setParts(bodyParts);
1777                }
1778            }
1779        }
1780
1781        return msg;
1782    }
1783
1784    /**
1785     * Create a Fault Message
1786     *
1787     * @param def
1788     * @param exception (an ExceptionRep object)
1789     * @return
1790     * @throws WSDLException
1791     * @throws AxisFault
1792     */

1793    protected Message writeFaultMessage(Definition def, FaultDesc exception)
1794            throws WSDLException, AxisFault {
1795
1796        String JavaDoc pkgAndClsName = exception.getClassName();
1797        String JavaDoc clsName =
1798                pkgAndClsName.substring(pkgAndClsName.lastIndexOf('.') + 1,
1799                        pkgAndClsName.length());
1800
1801        // Do this to cover the complex type case with no meta data
1802
exception.setName(clsName);
1803
1804        // The following code uses the class name for both the name= attribute
1805
// and the message= attribute.
1806
Message msg = (Message) exceptionMsg.get(pkgAndClsName);
1807
1808        if (msg == null) {
1809            msg = def.createMessage();
1810
1811            QName JavaDoc qName = createMessageName(def, clsName);
1812
1813            msg.setQName(qName);
1814            msg.setUndefined(false);
1815
1816            ArrayList JavaDoc parameters = exception.getParameters();
1817
1818            if (parameters != null) {
1819                for (int i = 0; i < parameters.size(); i++) {
1820                    ParameterDesc parameter = (ParameterDesc) parameters.get(i);
1821
1822                    writePartToMessage(def, msg, true, parameter);
1823                }
1824            }
1825
1826            exceptionMsg.put(pkgAndClsName, msg);
1827        }
1828
1829        return msg;
1830    }
1831
1832    /**
1833     * Create a Part
1834     *
1835     * @param def
1836     * @param msg
1837     * @param request message is for a request
1838     * @param param ParamRep object
1839     * @return The parameter name added or null
1840     * @throws WSDLException
1841     * @throws AxisFault
1842     */

1843    public String JavaDoc writePartToMessage(
1844            Definition def, Message msg, boolean request, ParameterDesc param)
1845            throws WSDLException, AxisFault {
1846
1847        // Return if this is a void type
1848
if ((param == null) || (param.getJavaType() == java.lang.Void.TYPE)) {
1849            return null;
1850        }
1851
1852        // If Request message, only continue if IN or INOUT
1853
// If Response message, only continue if OUT or INOUT
1854
if (request && (param.getMode() == ParameterDesc.OUT)) {
1855            return null;
1856        }
1857
1858        if (!request && (param.getMode() == ParameterDesc.IN)) {
1859            return null;
1860        }
1861
1862        // Create the Part
1863
Part part = def.createPart();
1864
1865        if (param.getDocumentation() != null) {
1866            part.setDocumentationElement(
1867                    createDocumentationElement(
1868                            param.getDocumentation()));
1869        }
1870
1871        // Get the java type to represent in the wsdl
1872
// (if the mode is OUT or INOUT and this
1873
// parameter does not represent the return type,
1874
// the type held in the Holder is the one that should
1875
// be written.)
1876
Class JavaDoc javaType = param.getJavaType();
1877
1878        if ((param.getMode() != ParameterDesc.IN)
1879                && (param.getIsReturn() == false)) {
1880            javaType = JavaUtils.getHolderValueType(javaType);
1881        }
1882
1883        if ((use == Use.ENCODED) || (style == Style.RPC)) {
1884
1885            // Add the type representing the param
1886
// Write <part name=param_name type=param_type>
1887
QName JavaDoc typeQName = param.getTypeQName();
1888
1889            if (javaType != null) {
1890                typeQName = types.writeTypeAndSubTypeForPart(javaType, typeQName);
1891            }
1892
1893            // types.writeElementForPart(javaType, param.getTypeQName());
1894
if (typeQName != null) {
1895                part.setName(param.getName());
1896                part.setTypeName(typeQName);
1897                msg.addPart(part);
1898            }
1899        } else if (use == Use.LITERAL) {
1900
1901            // This is doc/lit. So we should write out an element
1902
// declaration whose name and type may be found in the
1903
// ParameterDesc.
1904
QName JavaDoc qname = param.getQName();
1905
1906            if (param.getTypeQName() == null) {
1907                log.warn(Messages.getMessage("registerTypeMappingFor01",
1908                        param.getJavaType().getName()));
1909                QName JavaDoc qName = types.writeTypeForPart(param.getJavaType(),null);
1910                if (qName != null) {
1911                    param.setTypeQName(qName);
1912                } else {
1913                    param.setTypeQName(Constants.XSD_ANYTYPE);
1914                }
1915            }
1916
1917            if (param.getTypeQName().getNamespaceURI().equals("")) {
1918                param.setTypeQName(
1919                        new QName JavaDoc(intfNS, param.getTypeQName().getLocalPart()));
1920            }
1921
1922            if (param.getQName().getNamespaceURI().equals("")) {
1923                qname = new QName JavaDoc(intfNS, param.getQName().getLocalPart());
1924
1925                param.setQName(qname);
1926            }
1927
1928            // Make sure qname's value is unique.
1929
ArrayList JavaDoc names = (ArrayList JavaDoc)
1930                    usedElementNames.get(qname.getNamespaceURI());
1931            if (names == null) {
1932                names = new ArrayList JavaDoc(1);
1933                usedElementNames.put(qname.getNamespaceURI(), names);
1934            }
1935            else if (names.contains(qname.getLocalPart())) {
1936                qname = new QName JavaDoc(qname.getNamespaceURI(),
1937                    JavaUtils.getUniqueValue(names, qname.getLocalPart()));
1938            }
1939            names.add(qname.getLocalPart());
1940
1941            types.writeElementDecl(qname,
1942                                   param.getJavaType(),
1943                                   param.getTypeQName(),
1944                                   false,
1945                                   param.getItemQName());
1946
1947            part.setName(param.getName());
1948            part.setElementName(qname);
1949            msg.addPart(part);
1950        }
1951
1952        // return the name of the parameter added
1953
return param.getName();
1954    }
1955
1956    /*
1957     * Return a message QName which has not already been defined in the WSDL
1958     */

1959
1960    /**
1961     * Method createMessageName
1962     *
1963     * @param def
1964     * @param methodName
1965     * @return
1966     */

1967    protected QName JavaDoc createMessageName(Definition def, String JavaDoc methodName) {
1968
1969        QName JavaDoc qName = new QName JavaDoc(intfNS, methodName);
1970
1971        // Check the make sure there isn't a message with this name already
1972
int messageNumber = 1;
1973
1974        while (def.getMessage(qName) != null) {
1975            StringBuffer JavaDoc namebuf = new StringBuffer JavaDoc(methodName);
1976
1977            namebuf.append(messageNumber);
1978
1979            qName = new QName JavaDoc(intfNS, namebuf.toString());
1980
1981            messageNumber++;
1982        }
1983
1984        return qName;
1985    }
1986
1987    /**
1988     * Write a prettified document to a file.
1989     *
1990     * @param doc the Document to write
1991     * @param filename the name of the file to be written
1992     * @throws IOException various file i/o exceptions
1993     */

1994    protected void prettyDocumentToFile(Document JavaDoc doc, String JavaDoc filename)
1995            throws IOException JavaDoc {
1996
1997        FileOutputStream JavaDoc fos = new FileOutputStream JavaDoc(new File JavaDoc(filename));
1998
1999        XMLUtils.PrettyDocumentToStream(doc, fos);
2000        fos.close();
2001    }
2002
2003    // -------------------- Parameter Query Methods ----------------------------//
2004

2005    /**
2006     * Returns the <code>Class</code> to export
2007     *
2008     * @return the <code>Class</code> to export
2009     */

2010    public Class JavaDoc getCls() {
2011        return cls;
2012    }
2013
2014    /**
2015     * Sets the <code>Class</code> to export
2016     *
2017     * @param cls the <code>Class</code> to export
2018     */

2019    public void setCls(Class JavaDoc cls) {
2020        this.cls = cls;
2021    }
2022
2023    /**
2024     * Sets the <code>Class</code> to export.
2025     *
2026     * @param cls the <code>Class</code> to export
2027     * @param location
2028     */

2029    public void setClsSmart(Class JavaDoc cls, String JavaDoc location) {
2030
2031        if ((cls == null) || (location == null)) {
2032            return;
2033        }
2034
2035        // Strip off \ and / from location
2036
if (location.lastIndexOf('/') > 0) {
2037            location = location.substring(location.lastIndexOf('/') + 1);
2038        } else if (location.lastIndexOf('\\') > 0) {
2039            location = location.substring(location.lastIndexOf('\\') + 1);
2040        }
2041
2042        // Get the constructors of the class
2043
java.lang.reflect.Constructor JavaDoc[] constructors =
2044                cls.getDeclaredConstructors();
2045        Class JavaDoc intf = null;
2046
2047        for (int i = 0; (i < constructors.length) && (intf == null); i++) {
2048            Class JavaDoc[] parms = constructors[i].getParameterTypes();
2049
2050            // If the constructor has a single parameter
2051
// that is an interface which
2052
// matches the location, then use this as the interface class.
2053
if ((parms.length == 1) && parms[0].isInterface()
2054                    && (parms[0].getName() != null)
2055                    && Types.getLocalNameFromFullName(
2056                            parms[0].getName()).equals(location)) {
2057                intf = parms[0];
2058            }
2059        }
2060
2061        if (intf != null) {
2062            setCls(intf);
2063
2064            if (implCls == null) {
2065                setImplCls(cls);
2066            }
2067        } else {
2068            setCls(cls);
2069        }
2070    }
2071
2072    /**
2073     * Sets the <code>Class</code> to export
2074     *
2075     * @param className the name of the <code>Class</code> to export
2076     * @throws ClassNotFoundException
2077     */

2078    public void setCls(String JavaDoc className) throws ClassNotFoundException JavaDoc {
2079        cls = ClassUtils.forName(className);
2080    }
2081
2082    /**
2083     * Returns the implementation <code>Class</code> if set
2084     *
2085     * @return the implementation Class or null
2086     */

2087    public Class JavaDoc getImplCls() {
2088        return implCls;
2089    }
2090
2091    /**
2092     * Sets the implementation <code>Class</code>
2093     *
2094     * @param implCls the <code>Class</code> to export
2095     */

2096    public void setImplCls(Class JavaDoc implCls) {
2097        this.implCls = implCls;
2098    }
2099
2100    /**
2101     * Sets the implementation <code>Class</code>
2102     *
2103     * @param className the name of the implementation <code>Class</code>
2104     */

2105    public void setImplCls(String JavaDoc className) {
2106
2107        try {
2108            implCls = ClassUtils.forName(className);
2109        } catch (Exception JavaDoc ex) {
2110            ex.printStackTrace();
2111        }
2112    }
2113
2114    /**
2115     * Returns the interface namespace
2116     *
2117     * @return interface target namespace
2118     */

2119    public String JavaDoc getIntfNamespace() {
2120        return intfNS;
2121    }
2122
2123    /**
2124     * Set the interface namespace
2125     *
2126     * @param ns interface target namespace
2127     */

2128    public void setIntfNamespace(String JavaDoc ns) {
2129        this.intfNS = ns;
2130    }
2131
2132    /**
2133     * Returns the implementation namespace
2134     *
2135     * @return implementation target namespace
2136     */

2137    public String JavaDoc getImplNamespace() {
2138        return implNS;
2139    }
2140
2141    /**
2142     * Set the implementation namespace
2143     *
2144     * @param ns implementation target namespace
2145     */

2146    public void setImplNamespace(String JavaDoc ns) {
2147        this.implNS = ns;
2148    }
2149
2150    /**
2151     * Returns a vector of methods to export
2152     *
2153     * @return a space separated list of methods to export
2154     */

2155    public Vector JavaDoc getAllowedMethods() {
2156        return allowedMethods;
2157    }
2158
2159    /**
2160     * Add a list of methods to export
2161     *
2162     * @param text
2163     */

2164    public void setAllowedMethods(String JavaDoc text) {
2165
2166        if (text != null) {
2167            StringTokenizer JavaDoc tokenizer = new StringTokenizer JavaDoc(text, " ,+");
2168
2169            if (allowedMethods == null) {
2170                allowedMethods = new Vector JavaDoc();
2171            }
2172
2173            while (tokenizer.hasMoreTokens()) {
2174                allowedMethods.add(tokenizer.nextToken());
2175            }
2176        }
2177    }
2178
2179    /**
2180     * Add a Vector of methods to export
2181     *
2182     * @param allowedMethods a vector of methods to export
2183     */

2184    public void setAllowedMethods(Vector JavaDoc allowedMethods) {
2185
2186        if (this.allowedMethods == null) {
2187            this.allowedMethods = new Vector JavaDoc();
2188        }
2189
2190        this.allowedMethods.addAll(allowedMethods);
2191    }
2192
2193    /**
2194     * Indicates if the emitter will search classes for inherited methods
2195     *
2196     * @return
2197     */

2198    public boolean getUseInheritedMethods() {
2199        return useInheritedMethods;
2200    }
2201
2202    /**
2203     * Turn on or off inherited method WSDL generation.
2204     *
2205     * @param useInheritedMethods
2206     */

2207    public void setUseInheritedMethods(boolean useInheritedMethods) {
2208        this.useInheritedMethods = useInheritedMethods;
2209    }
2210
2211    /**
2212     * Add a list of methods NOT to export
2213     *
2214     * @param disallowedMethods vector of method name strings
2215     */

2216    public void setDisallowedMethods(Vector JavaDoc disallowedMethods) {
2217
2218        if (this.disallowedMethods == null) {
2219            this.disallowedMethods = new Vector JavaDoc();
2220        }
2221
2222        this.disallowedMethods.addAll(disallowedMethods);
2223    }
2224
2225    /**
2226     * Add a list of methods NOT to export
2227     *
2228     * @param text space separated list of method names
2229     */

2230    public void setDisallowedMethods(String JavaDoc text) {
2231
2232        if (text != null) {
2233            StringTokenizer JavaDoc tokenizer = new StringTokenizer JavaDoc(text, " ,+");
2234
2235            if (disallowedMethods == null) {
2236                disallowedMethods = new Vector JavaDoc();
2237            }
2238
2239            disallowedMethods = new Vector JavaDoc();
2240
2241            while (tokenizer.hasMoreTokens()) {
2242                disallowedMethods.add(tokenizer.nextToken());
2243            }
2244        }
2245    }
2246
2247    /**
2248     * Return list of methods that should not be exported
2249     *
2250     * @return
2251     */

2252    public Vector JavaDoc getDisallowedMethods() {
2253        return disallowedMethods;
2254    }
2255
2256    /**
2257     * Adds a list of classes (fully qualified) that will stop the traversal
2258     * of the inheritance tree if encounter in method or complex type generation
2259     *
2260     * @param stopClasses vector of class name strings
2261     */

2262    public void setStopClasses(ArrayList JavaDoc stopClasses) {
2263
2264        if (this.stopClasses == null) {
2265            this.stopClasses = new ArrayList JavaDoc();
2266        }
2267
2268        this.stopClasses.addAll(stopClasses);
2269    }
2270
2271    /**
2272     * Add a list of classes (fully qualified) that will stop the traversal
2273     * of the inheritance tree if encounter in method or complex type generation
2274     *
2275     * @param text space separated list of class names
2276     */

2277    public void setStopClasses(String JavaDoc text) {
2278
2279        if (text != null) {
2280            StringTokenizer JavaDoc tokenizer = new StringTokenizer JavaDoc(text, " ,+");
2281
2282            if (stopClasses == null) {
2283                stopClasses = new ArrayList JavaDoc();
2284            }
2285
2286            while (tokenizer.hasMoreTokens()) {
2287                stopClasses.add(tokenizer.nextToken());
2288            }
2289        }
2290    }
2291
2292    /**
2293     * Return the list of classes which stop inhertance searches
2294     *
2295     * @return
2296     */

2297    public ArrayList JavaDoc getStopClasses() {
2298        return stopClasses;
2299    }
2300
2301    /**
2302     * get the packagename to namespace map
2303     *
2304     * @return <code>Map</code>
2305     */

2306    public Map JavaDoc getNamespaceMap() {
2307        return namespaces;
2308    }
2309
2310    /**
2311     * Set the packagename to namespace map with the given map
2312     *
2313     * @param map packagename/namespace <code>Map</code>
2314     */

2315    public void setNamespaceMap(Map JavaDoc map) {
2316
2317        if (map != null) {
2318            namespaces.putAll(map);
2319        }
2320    }
2321
2322    /**
2323     * Get the name of the input WSDL
2324     *
2325     * @return name of the input wsdl or null
2326     */

2327    public String JavaDoc getInputWSDL() {
2328        return inputWSDL;
2329    }
2330
2331    /**
2332     * Set the name of the input WSDL
2333     *
2334     * @param inputWSDL the name of the input WSDL
2335     */

2336    public void setInputWSDL(String JavaDoc inputWSDL) {
2337        this.inputWSDL = inputWSDL;
2338    }
2339
2340    /**
2341     * @return the name of the input schema, or null
2342     */

2343    public String JavaDoc getInputSchema() {
2344        return inputSchema;
2345    }
2346
2347    /**
2348     * Set the name of the input schema
2349     *
2350     * @param inputSchema the name of the input schema
2351     */

2352    public void setInputSchema(String JavaDoc inputSchema) {
2353        this.inputSchema = inputSchema;
2354    }
2355
2356    /**
2357     * Returns the String representation of the service endpoint URL
2358     *
2359     * @return String representation of the service endpoint URL
2360     */

2361    public String JavaDoc getLocationUrl() {
2362        return locationUrl;
2363    }
2364
2365    /**
2366     * Set the String representation of the service endpoint URL
2367     *
2368     * @param locationUrl the String representation of the service endpoint URL
2369     */

2370    public void setLocationUrl(String JavaDoc locationUrl) {
2371        this.locationUrl = locationUrl;
2372    }
2373
2374    /**
2375     * Returns the String representation of the interface import location URL
2376     *
2377     * @return String representation of the interface import location URL
2378     */

2379    public String JavaDoc getImportUrl() {
2380        return importUrl;
2381    }
2382
2383    /**
2384     * Set the String representation of the interface location URL
2385     * for importing
2386     *
2387     * @param importUrl the String representation of the interface
2388     * location URL for importing
2389     */

2390    public void setImportUrl(String JavaDoc importUrl) {
2391        this.importUrl = importUrl;
2392    }
2393
2394    /**
2395     * Returns the String representation of the service port name
2396     *
2397     * @return String representation of the service port name
2398     */

2399    public String JavaDoc getServicePortName() {
2400        return servicePortName;
2401    }
2402
2403    /**
2404     * Set the String representation of the service port name
2405     *
2406     * @param servicePortName the String representation of the service port name
2407     */

2408    public void setServicePortName(String JavaDoc servicePortName) {
2409        this.servicePortName = servicePortName;
2410    }
2411
2412    /**
2413     * Returns the String representation of the service element name
2414     *
2415     * @return String representation of the service element name
2416     */

2417    public String JavaDoc getServiceElementName() {
2418        return serviceElementName;
2419    }
2420
2421    /**
2422     * Set the String representation of the service element name
2423     *
2424     * @param serviceElementName the String representation of the service element name
2425     */

2426    public void setServiceElementName(String JavaDoc serviceElementName) {
2427        this.serviceElementName = serviceElementName;
2428    }
2429
2430    /**
2431     * Returns the String representation of the portType name
2432     *
2433     * @return String representation of the portType name
2434     */

2435    public String JavaDoc getPortTypeName() {
2436        return portTypeName;
2437    }
2438
2439    /**
2440     * Set the String representation of the portType name
2441     *
2442     * @param portTypeName the String representation of the portType name
2443     */

2444    public void setPortTypeName(String JavaDoc portTypeName) {
2445        this.portTypeName = portTypeName;
2446    }
2447
2448    /**
2449     * Returns the String representation of the binding name
2450     *
2451     * @return String representation of the binding name
2452     */

2453    public String JavaDoc getBindingName() {
2454        return bindingName;
2455    }
2456
2457    /**
2458     * Set the String representation of the binding name
2459     *
2460     * @param bindingName the String representation of the binding name
2461     */

2462    public void setBindingName(String JavaDoc bindingName) {
2463        this.bindingName = bindingName;
2464    }
2465
2466    /**
2467     * Returns the target service name
2468     *
2469     * @return the target service name
2470     */

2471    public String JavaDoc getTargetService() {
2472        return targetService;
2473    }
2474
2475    /**
2476     * Set the target service name
2477     *
2478     * @param targetService the target service name
2479     */

2480    public void setTargetService(String JavaDoc targetService) {
2481        this.targetService = targetService;
2482    }
2483
2484    /**
2485     * Returns the service description
2486     *
2487     * @return service description String
2488     */

2489    public String JavaDoc getDescription() {
2490        return description;
2491    }
2492
2493    /**
2494     * Set the service description
2495     *
2496     * @param description service description String
2497     */

2498    public void setDescription(String JavaDoc description) {
2499        this.description = description;
2500    }
2501
2502    /**
2503     * Returns the soapAction option value
2504     *
2505     * @return the String DEFAULT, NONE or OPERATION
2506     */

2507    public String JavaDoc getSoapAction() {
2508        return soapAction;
2509    }
2510
2511    /**
2512     * Sets the soapAction option value
2513     *
2514     * @param value must be DEFAULT, NONE, or OPERATION
2515     */

2516    public void setSoapAction(String JavaDoc value) {
2517        soapAction = value;
2518    }
2519
2520    /**
2521     * Returns the <code>TypeMapping</code> used by the service
2522     *
2523     * @return the <code>TypeMapping</code> used by the service
2524     */

2525    public TypeMapping getTypeMapping() {
2526        return tm;
2527    }
2528
2529    /**
2530     * Sets the <code>TypeMapping</code> used by the service
2531     *
2532     * @param tm the <code>TypeMapping</code> used by the service
2533     */

2534    public void setTypeMapping(TypeMapping tm) {
2535        this.tm = tm;
2536    }
2537
2538    /**
2539     * Returns the <code>defaultTypeMapping</code> used by the service
2540     * @return the <code>defaultTypeMapping</code> used by the service
2541     * @deprecated Use getTypeMappingRegistry instead
2542     */

2543    public TypeMapping getDefaultTypeMapping() {
2544        return (TypeMapping) tmr.getDefaultTypeMapping();
2545    }
2546
2547    /**
2548     * Sets the <code>defaultTypeMapping</code> used by the service
2549     * @param tm the <code>defaultTypeMapping</code> used by the service
2550     * @deprecated Use setTypeMappingRegistry instead
2551     */

2552    public void setDefaultTypeMapping(TypeMapping tm) {
2553        tmr.registerDefault(tm);
2554    }
2555
2556    /**
2557     * Set the TypeMappingRegistry for this Emitter.
2558     */

2559    public void setTypeMappingRegistry(TypeMappingRegistry tmr) {
2560        this.tmr = tmr;
2561    }
2562    /**
2563     * getStyle
2564     *
2565     * @return Style setting (Style.RPC, Style.DOCUMENT, Style.WRAPPED, etc.)
2566     */

2567    public Style getStyle() {
2568        return style;
2569    }
2570
2571    /**
2572     * setStyle
2573     *
2574     * @param value String representing a style ("document", "rpc", "wrapped")
2575     * Note that the case of the string is not important. "document" and "DOCUMENT"
2576     * are both treated as document style.
2577     * If the value is not a know style, the default setting is used.
2578     * See org.apache.axis.constants.Style for a description of the interaction between
2579     * Style/Use
2580     * <br>NOTE: If style is specified as "wrapped", use is set to literal.
2581     */

2582    public void setStyle(String JavaDoc value) {
2583        setStyle(Style.getStyle(value));
2584    }
2585
2586    /**
2587     * setStyle
2588     *
2589     * @param value Style setting
2590     */

2591    public void setStyle(Style value) {
2592
2593        style = value;
2594
2595        if (style.equals(Style.WRAPPED)) {
2596            setUse(Use.LITERAL);
2597        }
2598    }
2599
2600    /**
2601     * getUse
2602     *
2603     * @return Use setting (Use.ENCODED, Use.LITERAL)
2604     */

2605    public Use getUse() {
2606        return use;
2607    }
2608
2609    /**
2610     * setUse
2611     *
2612     * @param value String representing a use ("literal", "encoded")
2613     * Note that the case of the string is not important. "literal" and "LITERAL"
2614     * are both treated as literal use.
2615     * If the value is not a know use, the default setting is used.
2616     * See org.apache.axis.constants.Style for a description of the interaction between
2617     * Style/Use
2618     */

2619    public void setUse(String JavaDoc value) {
2620        use = Use.getUse(value);
2621    }
2622
2623    /**
2624     * setUse
2625     *
2626     * @param value Use setting
2627     */

2628    public void setUse(Use value) {
2629        use = value;
2630    }
2631
2632    /**
2633     * setMode (sets style and use)
2634     *
2635     * @param mode
2636     * @deprecated (use setStyle and setUse)
2637     */

2638    public void setMode(int mode) {
2639
2640        if (mode == MODE_RPC) {
2641            setStyle(Style.RPC);
2642            setUse(Use.ENCODED);
2643        } else if (mode == MODE_DOCUMENT) {
2644            setStyle(Style.DOCUMENT);
2645            setUse(Use.LITERAL);
2646        } else if (mode == MODE_DOC_WRAPPED) {
2647            setStyle(Style.WRAPPED);
2648            setUse(Use.LITERAL);
2649        }
2650    }
2651
2652    /**
2653     * getMode (gets the mode based on the style setting)
2654     *
2655     * @return returns the mode (-1 if invalid)
2656     * @deprecated (use getStyle and getUse)
2657     */

2658    public int getMode() {
2659
2660        if (style == Style.RPC) {
2661            return MODE_RPC;
2662        } else if (style == Style.DOCUMENT) {
2663            return MODE_DOCUMENT;
2664        } else if (style == Style.WRAPPED) {
2665            return MODE_DOC_WRAPPED;
2666        }
2667
2668        return -1;
2669    }
2670
2671    /**
2672     * Method getServiceDesc
2673     *
2674     * @return
2675     */

2676    public ServiceDesc getServiceDesc() {
2677        return serviceDesc;
2678    }
2679
2680    /**
2681     * Method setServiceDesc
2682     *
2683     * @param serviceDesc
2684     */

2685    public void setServiceDesc(ServiceDesc serviceDesc) {
2686        this.serviceDesc = serviceDesc;
2687    }
2688
2689    /**
2690     * Return the list of extra classes that the emitter will produce WSDL for.
2691     *
2692     * @return
2693     */

2694    public Class JavaDoc[] getExtraClasses() {
2695        return extraClasses;
2696    }
2697
2698    /**
2699     * Provide a list of classes which the emitter will produce WSDL
2700     * type definitions for.
2701     *
2702     * @param extraClasses
2703     */

2704    public void setExtraClasses(Class JavaDoc[] extraClasses) {
2705        this.extraClasses = extraClasses;
2706    }
2707
2708    /**
2709     * Provide a comma or space seperated list of classes which
2710     * the emitter will produce WSDL type definitions for.
2711     * The classes will be added to the current list.
2712     *
2713     * @param text
2714     * @throws ClassNotFoundException
2715     */

2716    public void setExtraClasses(String JavaDoc text) throws ClassNotFoundException JavaDoc {
2717
2718        ArrayList JavaDoc clsList = new ArrayList JavaDoc();
2719
2720        if (text != null) {
2721            StringTokenizer JavaDoc tokenizer = new StringTokenizer JavaDoc(text, " ,");
2722
2723            while (tokenizer.hasMoreTokens()) {
2724                String JavaDoc clsName = tokenizer.nextToken();
2725
2726                // Let the caller handler ClassNotFoundException
2727
Class JavaDoc cls = ClassUtils.forName(clsName);
2728
2729                clsList.add(cls);
2730            }
2731        }
2732
2733        // Allocate the new array
2734
Class JavaDoc[] ec;
2735
2736        if (extraClasses != null) {
2737            ec = new Class JavaDoc[clsList.size() + extraClasses.length];
2738
2739            // copy existing elements
2740
for (int i = 0; i < extraClasses.length; i++) {
2741                Class JavaDoc c = extraClasses[i];
2742
2743                ec[i] = c;
2744            }
2745        } else {
2746            ec = new Class JavaDoc[clsList.size()];
2747        }
2748
2749        // copy the new classes
2750
for (int i = 0; i < clsList.size(); i++) {
2751            Class JavaDoc c = (Class JavaDoc) clsList.get(i);
2752
2753            ec[i] = c;
2754        }
2755
2756        // set the member variable
2757
this.extraClasses = ec;
2758    }
2759
2760    public void setEmitAllTypes(boolean emitAllTypes) {
2761        this.emitAllTypes = emitAllTypes;
2762    }
2763
2764    /**
2765     * Return the version message
2766     * @return message or null if emitter will use the default
2767     */

2768    public String JavaDoc getVersionMessage()
2769    {
2770        return versionMessage;
2771    }
2772
2773    /**
2774     * Set the version message that appears at the top of the WSDL
2775     * If not set, we use the default version message.
2776     * If set to an empty string, no version message will be emitted
2777     * @param versionMessage the message to emit
2778     */

2779    public void setVersionMessage(String JavaDoc versionMessage)
2780    {
2781        this.versionMessage = versionMessage;
2782    }
2783
2784    /**
2785     * Return the type qname to java type mapping
2786     * @return mapping of type qname to its corresponding java type
2787     */

2788    public HashMap JavaDoc getQName2ClassMap() {
2789        return qName2ClassMap;
2790    }
2791}
2792
Popular Tags