KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * The Apache Software License, Version 1.1
3  *
4  *
5  * Copyright (c) 2001-2003 The Apache Software Foundation. All rights
6  * reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in
17  * the documentation and/or other materials provided with the
18  * distribution.
19  *
20  * 3. The end-user documentation included with the redistribution,
21  * if any, must include the following acknowledgment:
22  * "This product includes software developed by the
23  * Apache Software Foundation (http://www.apache.org/)."
24  * Alternately, this acknowledgment may appear in the software itself,
25  * if and wherever such third-party acknowledgments normally appear.
26  *
27  * 4. The names "Axis" and "Apache Software Foundation" must
28  * not be used to endorse or promote products derived from this
29  * software without prior written permission. For written
30  * permission, please contact apache@apache.org.
31  *
32  * 5. Products derived from this software may not be called "Apache",
33  * nor may "Apache" appear in their name, without prior written
34  * permission of the Apache Software Foundation.
35  *
36  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
37  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
38  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
39  * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
40  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
42  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
43  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
44  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
45  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
46  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
47  * SUCH DAMAGE.
48  * ====================================================================
49  *
50  * This software consists of voluntary contributions made by many
51  * individuals on behalf of the Apache Software Foundation. For more
52  * information on the Apache Software Foundation, please see
53  * <http://www.apache.org/>.
54  */

55
56 package org.jboss.axis.wsdl.fromJava;
57
58 import com.ibm.wsdl.BindingFaultImpl;
59 import com.ibm.wsdl.extensions.soap.SOAPAddressImpl;
60 import com.ibm.wsdl.extensions.soap.SOAPBindingImpl;
61 import com.ibm.wsdl.extensions.soap.SOAPBodyImpl;
62 import com.ibm.wsdl.extensions.soap.SOAPOperationImpl;
63 import org.jboss.axis.AxisFault;
64 import org.jboss.axis.Constants;
65 import org.jboss.axis.description.FaultDesc;
66 import org.jboss.axis.description.OperationDesc;
67 import org.jboss.axis.description.ParameterDesc;
68 import org.jboss.axis.description.ServiceDesc;
69 import org.jboss.axis.encoding.DefaultTypeMappingImpl;
70 import org.jboss.axis.encoding.TypeMapping;
71 import org.jboss.axis.enums.Style;
72 import org.jboss.axis.enums.Use;
73 import org.jboss.axis.utils.ClassUtils;
74 import org.jboss.axis.utils.JavaUtils;
75 import org.jboss.axis.utils.XMLUtils;
76 import org.w3c.dom.Document JavaDoc;
77 import org.w3c.dom.Element JavaDoc;
78 import org.xml.sax.SAXException JavaDoc;
79
80 import javax.wsdl.Binding;
81 import javax.wsdl.BindingFault;
82 import javax.wsdl.BindingInput;
83 import javax.wsdl.BindingOperation;
84 import javax.wsdl.BindingOutput;
85 import javax.wsdl.Definition;
86 import javax.wsdl.Fault;
87 import javax.wsdl.Import;
88 import javax.wsdl.Input;
89 import javax.wsdl.Message;
90 import javax.wsdl.Operation;
91 import javax.wsdl.Output;
92 import javax.wsdl.Part;
93 import javax.wsdl.Port;
94 import javax.wsdl.PortType;
95 import javax.wsdl.Service;
96 import javax.wsdl.WSDLException;
97 import javax.wsdl.extensions.ExtensibilityElement;
98 import javax.wsdl.extensions.soap.SOAPAddress;
99 import javax.wsdl.extensions.soap.SOAPBinding;
100 import javax.wsdl.extensions.soap.SOAPBody;
101 import javax.wsdl.extensions.soap.SOAPFault;
102 import javax.wsdl.extensions.soap.SOAPOperation;
103 import javax.wsdl.factory.WSDLFactory;
104 import javax.xml.namespace.QName JavaDoc;
105 import javax.xml.parsers.ParserConfigurationException JavaDoc;
106 import java.io.File JavaDoc;
107 import java.io.FileOutputStream JavaDoc;
108 import java.io.IOException JavaDoc;
109 import java.io.StringWriter JavaDoc;
110 import java.util.ArrayList JavaDoc;
111 import java.util.HashMap JavaDoc;
112 import java.util.Iterator JavaDoc;
113 import java.util.Map JavaDoc;
114 import java.util.StringTokenizer JavaDoc;
115 import java.util.Vector JavaDoc;
116
117 /**
118  * This class emits WSDL from Java classes. It is used by the ?WSDL
119  * Axis browser function and Java2WSDL commandline utility.
120  * See Java2WSDL and Java2WSDLFactory for more information.
121  *
122  * @author Glen Daniels (gdaniels@macromedia.com)
123  * @author Rich Scheuerle (scheu@us.ibm.com)
124  */

125 public class Emitter
126 {
127    // Generated WSDL Modes
128
public static final int MODE_ALL = 0;
129    public static final int MODE_INTERFACE = 1;
130    public static final int MODE_IMPLEMENTATION = 2;
131
132    private Class JavaDoc cls;
133    private Class JavaDoc[] extraClasses; // Extra classes to emit WSDL for
134
private Class JavaDoc implCls; // Optional implementation class
135
private Vector JavaDoc allowedMethods = null; // Names of methods to consider
136
private Vector JavaDoc disallowedMethods = null; // Names of methods to exclude
137
private ArrayList JavaDoc stopClasses = new ArrayList JavaDoc();// class names which halt inheritace searches
138
private boolean useInheritedMethods = false;
139    private String JavaDoc intfNS;
140    private String JavaDoc implNS;
141    private String JavaDoc inputSchema;
142    private String JavaDoc inputWSDL;
143    private String JavaDoc locationUrl;
144    private String JavaDoc importUrl;
145    private String JavaDoc servicePortName;
146    private String JavaDoc serviceElementName;
147    private String JavaDoc targetService = null;
148    private String JavaDoc description;
149    private Style style = Style.RPC;
150    private Use use = null; // Default depends on style setting
151
private TypeMapping tm = null; // Registered type mapping
152
private TypeMapping defaultTM = null; // Default TM
153
private Namespaces namespaces;
154    private Map JavaDoc exceptionMsg = null;
155
156    private ArrayList JavaDoc encodingList;
157    protected Types types;
158    private String JavaDoc clsName;
159    private String JavaDoc portTypeName;
160    private String JavaDoc bindingName;
161
162    private ServiceDesc serviceDesc;
163    private ServiceDesc serviceDesc2;
164    private String JavaDoc soapAction = "DEFAULT";
165
166    // Style Modes
167
/**
168     * DEPRECATED - Indicates style=rpc use=encoded
169     */

170    public static final int MODE_RPC = 0;
171    /**
172     * DEPRECATED - Indicates style=document use=literal
173     */

174    public static final int MODE_DOCUMENT = 1;
175    /**
176     * DEPRECATED - Indicates style=wrapped use=literal
177     */

178    public static final int MODE_DOC_WRAPPED = 2;
179
180    /**
181     * Construct Emitter.
182     * Set the contextual information using set* methods
183     * Invoke emit to emit the code
184     */

185    public Emitter()
186    {
187       namespaces = new Namespaces();
188       exceptionMsg = new HashMap JavaDoc();
189    }
190
191    /**
192     * Generates WSDL documents for a given <code>Class</code>
193     *
194     * @param filename1 interface WSDL
195     * @param filename2 implementation WSDL
196     * @throws IOException
197     * @throws WSDLException
198     * @throws SAXException
199     * @throws ParserConfigurationException
200     */

201    public void emit(String JavaDoc filename1, String JavaDoc filename2)
202            throws IOException JavaDoc, WSDLException,
203            SAXException JavaDoc, ParserConfigurationException JavaDoc
204    {
205       // Get interface and implementation defs
206
Definition intf = getIntfWSDL();
207       Definition impl = getImplWSDL();
208
209       // Supply reasonable file names if not supplied
210
if (filename1 == null)
211       {
212          filename1 = getServicePortName() + "_interface.wsdl";
213       }
214       if (filename2 == null)
215       {
216          filename2 = getServicePortName() + "_implementation.wsdl";
217       }
218
219       for (int i = 0; extraClasses != null && i < extraClasses.length; i++)
220       {
221          types.writeTypeForPart(extraClasses[i], null);
222       }
223       //types.updateNamespaces();
224
// Write out the interface def
225
Document JavaDoc doc = WSDLFactory.newInstance().
226               newWSDLWriter().getDocument(intf);
227       types.insertTypesFragment(doc);
228       prettyDocumentToFile(doc, filename1);
229
230       // Write out the implementation def
231
doc = WSDLFactory.newInstance().newWSDLWriter().getDocument(impl);
232       prettyDocumentToFile(doc, filename2);
233    }
234
235    /**
236     * Generates a complete WSDL document for a given <code>Class</code>
237     *
238     * @param filename WSDL
239     * @throws IOException
240     * @throws WSDLException
241     * @throws SAXException
242     * @throws ParserConfigurationException
243     */

244    public void emit(String JavaDoc filename)
245            throws IOException JavaDoc, WSDLException,
246            SAXException JavaDoc, ParserConfigurationException JavaDoc
247    {
248       emit(filename, MODE_ALL);
249    }
250
251    /**
252     * Generates a WSDL document for a given <code>Class</code>.
253     * The WSDL generated is controlled by the mode parameter
254     * mode 0: All
255     * mode 1: Interface
256     * mode 2: Implementation
257     *
258     * @param mode generation mode - all, interface, implementation
259     * @return Document
260     * @throws IOException
261     * @throws WSDLException
262     * @throws SAXException
263     * @throws ParserConfigurationException
264     */

265    public Document JavaDoc emit(int mode)
266            throws IOException JavaDoc, WSDLException,
267            SAXException JavaDoc, ParserConfigurationException JavaDoc
268    {
269       Document JavaDoc doc = null;
270       Definition def = null;
271       switch (mode)
272       {
273          case MODE_ALL:
274             def = getWSDL();
275             for (int i = 0; extraClasses != null && i < extraClasses.length; i++)
276             {
277                types.writeTypeForPart(extraClasses[i], null);
278             }
279             //types.updateNamespaces();
280
doc = WSDLFactory.newInstance().
281                     newWSDLWriter().getDocument(def);
282             types.insertTypesFragment(doc);
283             break;
284          case MODE_INTERFACE:
285             def = getIntfWSDL();
286             for (int i = 0; extraClasses != null && i < extraClasses.length; i++)
287             {
288                types.writeTypeForPart(extraClasses[i], null);
289             }
290             //types.updateNamespaces();
291
doc = WSDLFactory.newInstance().
292                     newWSDLWriter().getDocument(def);
293             types.insertTypesFragment(doc);
294             break;
295          case MODE_IMPLEMENTATION:
296             def = getImplWSDL();
297             doc = WSDLFactory.newInstance().
298                     newWSDLWriter().getDocument(def);
299             break;
300       }
301
302       // Return the document
303
return doc;
304    }
305
306    /**
307     * Generates a String containing the WSDL 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 String
315     * @throws IOException
316     * @throws WSDLException
317     * @throws SAXException
318     * @throws ParserConfigurationException
319     */

320    public String JavaDoc emitToString(int mode)
321            throws IOException JavaDoc, WSDLException,
322            SAXException JavaDoc, ParserConfigurationException JavaDoc
323    {
324       Document JavaDoc doc = emit(mode);
325       StringWriter JavaDoc sw = new StringWriter JavaDoc();
326       XMLUtils.PrettyDocumentToWriter(doc, sw);
327       return sw.toString();
328    }
329
330    /**
331     * Generates a WSDL document for a given <code>Class</code>.
332     * The WSDL generated is controlled by the mode parameter
333     * mode 0: All
334     * mode 1: Interface
335     * mode 2: Implementation
336     *
337     * @param filename WSDL
338     * @param mode generation mode - all, interface, implementation
339     * @throws IOException
340     * @throws WSDLException
341     * @throws SAXException
342     * @throws ParserConfigurationException
343     */

344    public void emit(String JavaDoc filename, int mode)
345            throws IOException JavaDoc, WSDLException,
346            SAXException JavaDoc, ParserConfigurationException JavaDoc
347    {
348       Document JavaDoc doc = emit(mode);
349
350       // Supply a reasonable file name if not supplied
351
if (filename == null)
352       {
353          filename = getServicePortName();
354          switch (mode)
355          {
356             case MODE_ALL:
357                filename += ".wsdl";
358                break;
359             case MODE_INTERFACE:
360                filename += "_interface.wsdl";
361                break;
362             case MODE_IMPLEMENTATION:
363                filename += "_implementation.wsdl";
364                break;
365          }
366       }
367
368       prettyDocumentToFile(doc, filename);
369    }
370
371    /**
372     * Get a Full WSDL <code>Definition</code> for the current
373     * configuration parameters
374     *
375     * @return WSDL <code>Definition</code>
376     * @throws IOException
377     * @throws WSDLException
378     * @throws SAXException
379     * @throws ParserConfigurationException
380     */

381    public Definition getWSDL()
382            throws IOException JavaDoc, WSDLException,
383            SAXException JavaDoc, ParserConfigurationException JavaDoc
384    {
385       // Invoke the init() method to ensure configuration is setup
386
init(MODE_ALL);
387
388       // Create a Definition for the output wsdl
389
Definition def = createDefinition();
390
391       // Write interface header
392
writeDefinitions(def, intfNS);
393
394       // Create Types
395
types = createTypes(def);
396
397       // Write the WSDL constructs and return full Definition
398
Binding binding = writeBinding(def, true);
399       writePortType(def, binding);
400       writeService(def, binding);
401       return def;
402    }
403
404    /**
405     * Get a interface WSDL <code>Definition</code> for the
406     * current configuration parameters
407     *
408     * @return WSDL <code>Definition</code>
409     * @throws IOException
410     * @throws WSDLException
411     * @throws SAXException
412     * @throws ParserConfigurationException
413     */

414    public Definition getIntfWSDL()
415            throws IOException JavaDoc, WSDLException,
416            SAXException JavaDoc, ParserConfigurationException JavaDoc
417    {
418       // Invoke the init() method to ensure configuration is setup
419
init(MODE_INTERFACE);
420
421       // Create a definition for the output wsdl
422
Definition def = createDefinition();
423
424       // Write interface header
425
writeDefinitions(def, intfNS);
426
427       // Create Types
428
types = createTypes(def);
429
430       // Write the interface WSDL constructs and return the Definition
431
Binding binding = writeBinding(def, true);
432       writePortType(def, binding);
433       return def;
434    }
435
436    /**
437     * Get implementation WSDL <code>Definition</code> for the
438     * current configuration parameters
439     *
440     * @return WSDL <code>Definition</code>
441     * @throws IOException
442     * @throws WSDLException
443     * @throws SAXException
444     * @throws ParserConfigurationException
445     */

446    public Definition getImplWSDL()
447            throws IOException JavaDoc, WSDLException,
448            SAXException JavaDoc, ParserConfigurationException JavaDoc
449    {
450       // Invoke the init() method to ensure configuration is setup
451
init(MODE_IMPLEMENTATION);
452
453       // Create a Definition for the output wsdl
454
Definition def = createDefinition();
455
456       // Write implementation header and import
457
writeDefinitions(def, implNS);
458       writeImport(def, intfNS, importUrl);
459
460       // Write the implementation WSDL constructs and return Definition
461
Binding binding = writeBinding(def, false); // Don't add binding to def
462
writeService(def, binding);
463       return def;
464    }
465
466    /**
467     * Invoked prior to building a definition to ensure parms
468     * and data are set up.
469     */

470    protected void init(int mode)
471    {
472
473       // Default use depending on setting of style
474
if (use == null)
475       {
476          if (style == Style.RPC)
477          {
478             use = Use.ENCODED;
479          }
480          else
481          {
482             use = Use.LITERAL;
483          }
484       }
485
486       // Get a default TM if not specified.
487
if (defaultTM == null)
488       {
489          defaultTM = DefaultTypeMappingImpl.getSingleton();
490       }
491
492       // Set up a ServiceDesc to use to introspect the Service
493
if (serviceDesc == null)
494       {
495          serviceDesc = new ServiceDesc();
496          serviceDesc.setImplClass(cls);
497
498          // Set the typeMapping to the one provided.
499
// If not available use the default TM
500
if (tm != null)
501          {
502             serviceDesc.setTypeMapping(tm);
503          }
504          else
505          {
506             serviceDesc.setTypeMapping(defaultTM);
507          }
508
509          serviceDesc.setStopClasses(stopClasses);
510          serviceDesc.setAllowedMethods(allowedMethods);
511          serviceDesc.setDisallowedMethods(disallowedMethods);
512          serviceDesc.setStyle(style);
513
514          // If the class passed in is a portType,
515
// there may be an implClass that is used to
516
// obtain the method parameter names. In this case,
517
// a serviceDesc2 is built to get the method parameter names.
518
if (implCls != null &&
519                  implCls != cls &&
520                  serviceDesc2 == null)
521          {
522             serviceDesc2 = new ServiceDesc();
523             serviceDesc2.setImplClass(implCls);
524
525             // Set the typeMapping to the one provided.
526
// If not available use the default TM
527
if (tm != null)
528             {
529                serviceDesc2.setTypeMapping(tm);
530             }
531             else
532             {
533                serviceDesc2.setTypeMapping(defaultTM);
534             }
535             serviceDesc2.setStopClasses(stopClasses);
536             serviceDesc2.setAllowedMethods(allowedMethods);
537             serviceDesc2.setDisallowedMethods(disallowedMethods);
538             serviceDesc2.setStyle(style);
539          }
540       }
541
542       if (encodingList == null)
543       {
544          clsName = cls.getName();
545          clsName = clsName.substring(clsName.lastIndexOf('.') + 1);
546
547          // Default the portType name
548
if (getPortTypeName() == null)
549          {
550             setPortTypeName(clsName);
551          }
552
553          // Default the serviceElementName
554
if (getServiceElementName() == null)
555          {
556             setServiceElementName(getPortTypeName() + "Service");
557          }
558
559          // If service port name is null, construct it from location or className
560
if (getServicePortName() == null)
561          {
562             String JavaDoc name = getLocationUrl();
563             if (name != null)
564             {
565                if (name.lastIndexOf('/') > 0)
566                {
567                   name = name.substring(name.lastIndexOf('/') + 1);
568                }
569                else if (name.lastIndexOf('\\') > 0)
570                {
571                   name = name.substring(name.lastIndexOf('\\') + 1);
572                }
573                else
574                {
575                   name = null;
576                }
577                // if we got the name from the location, strip .jws from it
578
if (name != null && name.endsWith(".jws"))
579                {
580                   name = name.substring(0,
581                           (name.length() - ".jws".length()));
582                }
583             }
584             if (name == null || name.equals(""))
585             {
586                name = clsName;
587             }
588             setServicePortName(name);
589          }
590
591          // Default the bindingName
592
if (getBindingName() == null)
593          {
594             setBindingName(getServicePortName() + "SoapBinding");
595          }
596
597          encodingList = new ArrayList JavaDoc();
598          encodingList.add(Constants.URI_DEFAULT_SOAP_ENC);
599
600          if (intfNS == null)
601          {
602             Package JavaDoc pkg = cls.getPackage();
603             intfNS = namespaces.getCreate(pkg == null ? null : pkg.getName());
604          }
605          // Default the implementation namespace to the interface
606
// namespace if not split wsdl mode.
607
if (implNS == null)
608          {
609             if (mode == MODE_ALL)
610             {
611                implNS = intfNS;
612             }
613             else
614             {
615                implNS = intfNS + "-impl";
616             }
617          }
618
619          // set the namespaces in the serviceDesc(s)
620
serviceDesc.setDefaultNamespace(intfNS);
621          if (serviceDesc2 != null)
622          {
623             serviceDesc2.setDefaultNamespace(implNS);
624          }
625
626          if (cls != null)
627          {
628             namespaces.put(cls.getName(), intfNS, "intf");
629          }
630          namespaces.putPrefix(implNS, "impl");
631       }
632    }
633
634
635    /**
636     * Build a Definition from the input wsdl file or create
637     * a new Definition
638     *
639     * @return WSDL Definition
640     */

641    protected Definition createDefinition()
642            throws WSDLException, SAXException JavaDoc, IOException JavaDoc,
643            ParserConfigurationException JavaDoc
644    {
645       Definition def;
646       if (inputWSDL == null)
647       {
648          def = WSDLFactory.newInstance().newDefinition();
649       }
650       else
651       {
652          javax.wsdl.xml.WSDLReader reader =
653                  WSDLFactory.newInstance().newWSDLReader();
654          Document JavaDoc doc = XMLUtils.newDocument(inputWSDL);
655          def = reader.readWSDL(null, doc);
656          // The input wsdl types section is deleted. The
657
// types will be added back in at the end of processing.
658
def.setTypes(null);
659       }
660       return def;
661    }
662
663    protected static TypeMapping standardTypes =
664            (TypeMapping)new org.jboss.axis.encoding.TypeMappingRegistryImpl().getTypeMapping(null);
665
666
667    /**
668     * Build a Types object and load the input wsdl types
669     *
670     * @param def Corresponding wsdl Definition
671     * @return Types object
672     */

673    protected Types createTypes(Definition def)
674            throws IOException JavaDoc, WSDLException, SAXException JavaDoc,
675            ParserConfigurationException JavaDoc
676    {
677       types = new Types(def, tm, defaultTM, namespaces,
678               intfNS, stopClasses, serviceDesc);
679       if (inputWSDL != null)
680       {
681          types.loadInputTypes(inputWSDL);
682       }
683       if (inputSchema != null)
684       {
685          types.loadInputSchema(inputSchema);
686       }
687
688       if (tm != null)
689       {
690          Class JavaDoc[] mappedTypes = tm.getAllClasses();
691          for (int i = 0; i < mappedTypes.length; i++)
692          {
693             Class JavaDoc mappedType = mappedTypes[i];
694             QName JavaDoc name = tm.getTypeQName(mappedType);
695             /**
696              * If it's a non-standard type, make sure it shows up in
697              * our WSDL
698              */

699             if (standardTypes.getSerializer(mappedType) == null)
700             {
701                types.writeTypeForPart(mappedType, name);
702             }
703          }
704       }
705
706       return types;
707    }
708
709
710    /**
711     * Create the definition header information.
712     *
713     * @param def <code>Definition</code>
714     * @param tns target namespace
715     */

716    protected void writeDefinitions(Definition def, String JavaDoc tns)
717    {
718       def.setTargetNamespace(tns);
719
720       def.addNamespace("intf", intfNS);
721       def.addNamespace("impl", implNS);
722
723       def.addNamespace(Constants.NS_PREFIX_WSDL_SOAP,
724               Constants.URI_WSDL11_SOAP);
725       namespaces.putPrefix(Constants.URI_WSDL11_SOAP,
726               Constants.NS_PREFIX_WSDL_SOAP);
727
728       def.addNamespace(Constants.NS_PREFIX_WSDL,
729               Constants.NS_URI_WSDL11);
730       namespaces.putPrefix(Constants.NS_URI_WSDL11,
731               Constants.NS_PREFIX_WSDL);
732
733       def.addNamespace(Constants.NS_PREFIX_SOAP_ENC,
734               Constants.URI_DEFAULT_SOAP_ENC);
735       namespaces.putPrefix(Constants.URI_DEFAULT_SOAP_ENC,
736               Constants.NS_PREFIX_SOAP_ENC);
737
738       def.addNamespace(Constants.NS_PREFIX_SCHEMA_XSD,
739               Constants.URI_DEFAULT_SCHEMA_XSD);
740       namespaces.putPrefix(Constants.URI_DEFAULT_SCHEMA_XSD,
741               Constants.NS_PREFIX_SCHEMA_XSD);
742
743       def.addNamespace(Constants.NS_PREFIX_XMLSOAP,
744               Constants.NS_URI_XMLSOAP);
745       namespaces.putPrefix(Constants.NS_URI_XMLSOAP,
746               Constants.NS_PREFIX_XMLSOAP);
747    }
748
749    /**
750     * Create and add an import
751     *
752     * @param def <code>Definition</code>
753     * @param tns target namespace
754     * @param loc target location
755     */

756    protected void writeImport(Definition def, String JavaDoc tns, String JavaDoc loc)
757    {
758       Import imp = def.createImport();
759
760       imp.setNamespaceURI(tns);
761       if (loc != null && !loc.equals(""))
762          imp.setLocationURI(loc);
763       def.addImport(imp);
764    }
765
766    /**
767     * Create the binding.
768     *
769     * @param def <code>Definition</code>
770     * @param add true if binding should be added to the def
771     */

772    protected Binding writeBinding(Definition def, boolean add)
773    {
774       QName JavaDoc bindingQName =
775               new QName JavaDoc(intfNS, getBindingName());
776
777       // If a binding already exists, don't replace it.
778
Binding binding = def.getBinding(bindingQName);
779       if (binding != null)
780       {
781          return binding;
782       }
783
784       // Create a binding
785
binding = def.createBinding();
786       binding.setUndefined(false);
787       binding.setQName(bindingQName);
788
789       SOAPBinding soapBinding = new SOAPBindingImpl();
790       String JavaDoc styleStr = (style == Style.RPC) ? "rpc" : "document";
791       soapBinding.setStyle(styleStr);
792       soapBinding.setTransportURI(Constants.URI_SOAP11_HTTP);
793
794       binding.addExtensibilityElement(soapBinding);
795
796       if (add)
797       {
798          def.addBinding(binding);
799       }
800       return binding;
801    }
802
803    /**
804     * Create the service.
805     *
806     * @param def
807     * @param binding
808     */

809    protected void writeService(Definition def, Binding binding)
810    {
811
812       QName JavaDoc serviceElementQName =
813               new QName JavaDoc(implNS,
814                       getServiceElementName());
815
816       // Locate an existing service, or get a new service
817
Service service = def.getService(serviceElementQName);
818       if (service == null)
819       {
820          service = def.createService();
821          service.setQName(serviceElementQName);
822          def.addService(service);
823       }
824
825       // Add the port
826
Port port = def.createPort();
827       port.setBinding(binding);
828       // Probably should use the end of the location Url
829
port.setName(getServicePortName());
830
831       SOAPAddress addr = new SOAPAddressImpl();
832       addr.setLocationURI(locationUrl);
833
834       port.addExtensibilityElement(addr);
835
836       service.addPort(port);
837    }
838
839    /**
840     * Create a PortType
841     *
842     * @param def
843     * @param binding
844     * @throws WSDLException
845     * @throws AxisFault
846     */

847    protected void writePortType(Definition def, Binding binding)
848            throws WSDLException, AxisFault
849    {
850
851       QName JavaDoc portTypeQName = new QName JavaDoc(intfNS, getPortTypeName());
852
853       // Get or create a portType
854
PortType portType = def.getPortType(portTypeQName);
855       boolean newPortType = false;
856       if (portType == null)
857       {
858          portType = def.createPortType();
859          portType.setUndefined(false);
860          portType.setQName(portTypeQName);
861          newPortType = true;
862       }
863       else if (binding.getBindingOperations().size() > 0)
864       {
865          // If both portType and binding already exist,
866
// no additional processing is needed.
867
return;
868       }
869
870       // Add the port and binding operations.
871
ArrayList JavaDoc operations = serviceDesc.getOperations();
872       for (Iterator JavaDoc i = operations.iterator(); i.hasNext();)
873       {
874          OperationDesc thisOper = (OperationDesc)i.next();
875
876          BindingOperation bindingOper = writeOperation(def,
877                  binding,
878                  thisOper);
879          Operation oper = bindingOper.getOperation();
880
881          OperationDesc messageOper = thisOper;
882          if (serviceDesc2 != null)
883          {
884             // If a serviceDesc containing an impl class is provided,
885
// try and locate the corresponding operation
886
// (same name, same parm types and modes). If a
887
// corresponding operation is found, it is sent
888
// to the writeMessages method so that its parameter
889
// names will be used in the wsdl file.
890
OperationDesc[] operArray =
891                     serviceDesc2.getOperationsByName(thisOper.getName());
892             boolean found = false;
893             if (operArray != null)
894             {
895                for (int j = 0;
896                     j < operArray.length && !found;
897                     j++)
898                {
899                   OperationDesc tryOper = operArray[j];
900                   if (tryOper.getParameters().size() ==
901                           thisOper.getParameters().size())
902                   {
903                      boolean parmsMatch = true;
904                      for (int k = 0;
905                           k < thisOper.getParameters().size() && parmsMatch;
906                           k++)
907                      {
908                         if (tryOper.getParameter(k).getMode() !=
909                                 thisOper.getParameter(k).getMode() ||
910                                 (!tryOper.getParameter(k).getJavaType().
911                                 equals(thisOper.getParameter(k).getJavaType())))
912                         {
913                            parmsMatch = false;
914                         }
915                      }
916                      if (parmsMatch)
917                      {
918                         messageOper = tryOper;
919                         found = true;
920                      }
921                   }
922                }
923             }
924          }
925
926          writeMessages(def, oper, messageOper,
927                  bindingOper);
928          if (newPortType)
929          {
930             portType.addOperation(oper);
931          }
932       }
933
934       if (newPortType)
935       {
936          def.addPortType(portType);
937       }
938
939       binding.setPortType(portType);
940    }
941
942    /**
943     * Create a Message
944     *
945     * @param def Definition, the WSDL definition
946     * @param oper Operation, the wsdl operation
947     * @param desc OperationDesc, the Operation Description
948     * @param bindingOper BindingOperation, corresponding Binding Operation
949     * @throws WSDLException
950     * @throws AxisFault
951     */

952    protected void writeMessages(Definition def,
953                                 Operation oper,
954                                 OperationDesc desc,
955                                 BindingOperation bindingOper)
956            throws WSDLException, AxisFault
957    {
958       Input input = def.createInput();
959
960       Message msg = writeRequestMessage(def, desc);
961       input.setMessage(msg);
962
963       // Give the input element a name that matches the
964
// message. This is necessary for overloading.
965
// The msg QName is unique.
966
String JavaDoc name = msg.getQName().getLocalPart();
967       input.setName(name);
968       bindingOper.getBindingInput().setName(name);
969
970       oper.setInput(input);
971       def.addMessage(msg);
972
973       msg = writeResponseMessage(def, desc);
974       Output output = def.createOutput();
975       output.setMessage(msg);
976
977       // Give the output element a name that matches the
978
// message. This is necessary for overloading.
979
// The message QName is unique.
980
name = msg.getQName().getLocalPart();
981       output.setName(name);
982       bindingOper.getBindingOutput().setName(name);
983
984       oper.setOutput(output);
985       def.addMessage(msg);
986
987       ArrayList JavaDoc exceptions = desc.getFaults();
988
989       for (int i = 0; exceptions != null && i < exceptions.size(); i++)
990       {
991          FaultDesc faultDesc = (FaultDesc)exceptions.get(i);
992          msg = writeFaultMessage(def, faultDesc);
993
994          // Add the fault to the portType
995
Fault fault = def.createFault();
996          fault.setMessage(msg);
997          fault.setName(faultDesc.getName());
998          oper.addFault(fault);
999
1000         // Add the fault to the binding
1001
BindingFault bFault = def.createBindingFault();
1002         bFault.setName(faultDesc.getName());
1003         SOAPFault soapFault = writeSOAPFault(faultDesc);
1004         bFault.addExtensibilityElement(soapFault);
1005         bindingOper.addBindingFault(bFault);
1006
1007         // Add the fault message
1008
if (def.getMessage(msg.getQName()) == null)
1009         {
1010            def.addMessage(msg);
1011         }
1012      }
1013
1014      // Set the parameter ordering using the parameter names
1015
ArrayList JavaDoc parameters = desc.getParameters();
1016      Vector JavaDoc names = new Vector JavaDoc();
1017      for (int i = 0; i < parameters.size(); i++)
1018      {
1019         ParameterDesc param = (ParameterDesc)parameters.get(i);
1020         names.add(param.getName());
1021      }
1022
1023      if (names.size() > 0)
1024      {
1025         if (style == Style.WRAPPED)
1026         {
1027            names.clear();
1028         }
1029         oper.setParameterOrdering(names);
1030      }
1031   }
1032
1033   /**
1034    * Create a Operation
1035    *
1036    * @param def
1037    * @param binding
1038    */

1039   protected BindingOperation writeOperation(Definition def,
1040                                             Binding binding,
1041                                             OperationDesc desc)
1042   {
1043      Operation oper = def.createOperation();
1044      oper.setName(desc.getName());
1045      oper.setUndefined(false);
1046      return writeBindingOperation(def, binding, oper, desc);
1047   }
1048
1049   /**
1050    * Create a Binding Operation
1051    *
1052    * @param def
1053    * @param binding
1054    * @param oper
1055    */

1056   protected BindingOperation writeBindingOperation(Definition def,
1057                                                    Binding binding,
1058                                                    Operation oper,
1059                                                    OperationDesc desc)
1060   {
1061      BindingOperation bindingOper = def.createBindingOperation();
1062      BindingInput bindingInput = def.createBindingInput();
1063      BindingOutput bindingOutput = def.createBindingOutput();
1064
1065      bindingOper.setName(oper.getName());
1066      bindingOper.setOperation(oper);
1067
1068      SOAPOperation soapOper = new SOAPOperationImpl();
1069
1070
1071      // If the soapAction option is OPERATION, force
1072
// soapAction to the name of the operation. If NONE,
1073
// force soapAction to "".
1074
// Otherwise use the information in the operationDesc.
1075
String JavaDoc soapAction = "";
1076      if (getSoapAction().equals("OPERATION"))
1077      {
1078         soapAction = oper.getName();
1079      }
1080      else if (getSoapAction().equals("NONE"))
1081      {
1082         soapAction = "";
1083      }
1084      else
1085      {
1086         soapAction = desc.getSoapAction();
1087         if (soapAction == null)
1088         {
1089            soapAction = "";
1090         }
1091      }
1092      soapOper.setSoapActionURI(soapAction);
1093
1094      // Until we have per-operation configuration, this will always be
1095
// the same as the binding default.
1096
// soapOper.setStyle("rpc");
1097

1098      bindingOper.addExtensibilityElement(soapOper);
1099
1100      // Input clause
1101
ExtensibilityElement input = null;
1102      input = writeSOAPBody(desc.getElementQName());
1103      bindingInput.addExtensibilityElement(input);
1104
1105      //Output clause
1106
ExtensibilityElement output = null;
1107      output = writeSOAPBody(desc.getReturnQName());
1108
1109      bindingOutput.addExtensibilityElement(output);
1110
1111      // Ad input and output to operation
1112
bindingOper.setBindingInput(bindingInput);
1113      bindingOper.setBindingOutput(bindingOutput);
1114
1115      // Faults clause
1116
ArrayList JavaDoc faultList = desc.getFaults();
1117      if (faultList != null)
1118      {
1119         for (Iterator JavaDoc it = faultList.iterator(); it.hasNext();)
1120         {
1121            FaultDesc faultDesc = (FaultDesc)it.next();
1122            // Get a soap:fault
1123
ExtensibilityElement soapFault = writeSOAPFault(faultDesc);
1124            // Get a wsdl:fault to put the soap:fault in
1125
BindingFault bindingFault = new BindingFaultImpl();
1126            bindingFault.setName(faultDesc.getName());
1127            bindingFault.addExtensibilityElement(soapFault);
1128            bindingOper.addBindingFault(bindingFault);
1129         }
1130      }
1131
1132      binding.addBindingOperation(bindingOper);
1133
1134      return bindingOper;
1135   }
1136
1137   protected ExtensibilityElement writeSOAPBody(QName JavaDoc operQName)
1138   {
1139      SOAPBody soapBody = new SOAPBodyImpl();
1140      // for now, if its document, it is literal use.
1141
if (use == Use.ENCODED)
1142      {
1143         soapBody.setUse("encoded");
1144         soapBody.setEncodingStyles(encodingList);
1145      }
1146      else
1147      {
1148         soapBody.setUse("literal");
1149      }
1150      if (targetService == null)
1151         soapBody.setNamespaceURI(intfNS);
1152      else
1153         soapBody.setNamespaceURI(targetService);
1154      if (operQName != null &&
1155              !operQName.getNamespaceURI().equals(""))
1156      {
1157         soapBody.setNamespaceURI(operQName.getNamespaceURI());
1158      }
1159      return soapBody;
1160   } // writeSOAPBody
1161

1162   protected SOAPFault writeSOAPFault(FaultDesc faultDesc)
1163   {
1164      SOAPFault soapFault = new com.ibm.wsdl.extensions.soap.SOAPFaultImpl();
1165      if (use != Use.ENCODED)
1166      {
1167         soapFault.setUse("literal");
1168         // no namespace for literal, gets it from the element
1169
}
1170      else
1171      {
1172         soapFault.setUse("encoded");
1173         soapFault.setEncodingStyles(encodingList);
1174
1175         // Set the namespace from the fault QName if it exists
1176
// otherwise use the target (or interface) namespace
1177
QName JavaDoc faultQName = faultDesc.getQName();
1178         if (faultQName != null &&
1179                 !faultQName.getNamespaceURI().equals(""))
1180         {
1181            soapFault.setNamespaceURI(faultQName.getNamespaceURI());
1182         }
1183         else
1184         {
1185            if (targetService == null)
1186            {
1187               soapFault.setNamespaceURI(intfNS);
1188            }
1189            else
1190            {
1191               soapFault.setNamespaceURI(targetService);
1192            }
1193         }
1194      }
1195      return soapFault;
1196   } // writeSOAPFault
1197

1198
1199   /**
1200    * Create a Request Message
1201    *
1202    * @param def
1203    * @throws WSDLException
1204    * @throws AxisFault
1205    */

1206   protected Message writeRequestMessage(Definition def,
1207                                         OperationDesc oper)
1208           throws WSDLException, AxisFault
1209   {
1210      Message msg = def.createMessage();
1211
1212      QName JavaDoc qName = createMessageName(def, oper.getName() + "Request");
1213
1214      msg.setQName(qName);
1215      msg.setUndefined(false);
1216
1217      if (oper.getStyle() == Style.MESSAGE)
1218      {
1219         // If this is a MESSAGE-style operation, just write out
1220
// <xsd:any> for now.
1221
// TODO: Support custom schema in WSDD for these operations
1222
QName JavaDoc qname = oper.getElementQName();
1223         Element JavaDoc el = types.createElementDecl(qname.getLocalPart(),
1224                 Object JavaDoc.class,
1225                 Constants.XSD_ANYTYPE,
1226                 false, false);
1227         types.writeSchemaElement(qname, el);
1228
1229         Part part = def.createPart();
1230         part.setName("part");
1231         part.setElementName(qname);
1232         msg.addPart(part);
1233      }
1234      else if (oper.getStyle() == Style.WRAPPED)
1235      {
1236         // If we're WRAPPED, write the wrapper element first, and then
1237
// fill in any params. If there aren't any params, we'll see
1238
// an empty <complexType/> for the wrapper element.
1239
writeWrapperPart(def, msg, oper, true);
1240      }
1241      else
1242      {
1243         // Otherwise, write parts for the parameters.
1244
ArrayList JavaDoc parameters = oper.getParameters();
1245         for (int i = 0; i < parameters.size(); i++)
1246         {
1247            ParameterDesc parameter = (ParameterDesc)parameters.get(i);
1248            writePartToMessage(def, msg, true, parameter);
1249         }
1250      }
1251
1252      return msg;
1253   }
1254
1255   protected QName JavaDoc getRequestQName(OperationDesc oper)
1256   {
1257      QName JavaDoc qname = oper.getElementQName();
1258      if (qname == null)
1259      {
1260         qname = new QName JavaDoc(oper.getName());
1261      }
1262      return qname;
1263   }
1264
1265   protected QName JavaDoc getResponseQName(OperationDesc oper)
1266   {
1267      QName JavaDoc qname = oper.getElementQName();
1268      if (qname == null)
1269      {
1270         return new QName JavaDoc(oper.getName() + "Response");
1271      }
1272      return new QName JavaDoc(qname.getNamespaceURI(),
1273              qname.getLocalPart() + "Response");
1274   }
1275
1276   /**
1277    * Write out the schema definition for a WRAPPED operation request or
1278    * response.
1279    *
1280    * @param oper
1281    * @param request
1282    */

1283   public void writeWrapperPart(Definition def, Message msg,
1284                                OperationDesc oper, boolean request)
1285           throws AxisFault
1286   {
1287      QName JavaDoc qname = request ? getRequestQName(oper) : getResponseQName(oper);
1288      boolean hasParams = false;
1289      if (request)
1290      {
1291         hasParams = (oper.getNumInParams() > 0);
1292      }
1293      else
1294      {
1295         if (oper.getReturnClass() != void.class)
1296         {
1297            hasParams = true;
1298         }
1299         else
1300         {
1301            hasParams = (oper.getNumOutParams() > 0);
1302         }
1303      }
1304
1305      // First write the wrapper element itself.
1306
Element JavaDoc sequence = types.writeWrapperElement(qname, request, hasParams);
1307
1308      // If we got anything back above, there must be parameters in the
1309
// operation, and it's a <sequence> node in which to write them...
1310
if (sequence != null)
1311      {
1312         ArrayList JavaDoc parameters = request ? oper.getAllInParams() :
1313                 oper.getAllOutParams();
1314         if (!request)
1315         {
1316            String JavaDoc retName;
1317            if (oper.getReturnQName() == null)
1318            {
1319               retName = oper.getName() + "Response";
1320            }
1321            else
1322            {
1323               retName = oper.getReturnQName().getLocalPart();
1324            }
1325            types.writeWrappedParameter(sequence, retName,
1326                    oper.getReturnType(),
1327                    oper.getReturnClass());
1328         }
1329         for (int i = 0; i < parameters.size(); i++)
1330         {
1331            ParameterDesc parameter = (ParameterDesc)parameters.get(i);
1332            types.writeWrappedParameter(sequence,
1333                    parameter.getName(), // QName??
1334
parameter.getTypeQName(),
1335                    parameter.getJavaType());
1336         }
1337      }
1338
1339      // Finally write the part itself
1340
Part part = def.createPart();
1341      part.setName("parameters"); // We always se "parameters"
1342
part.setElementName(qname);
1343      msg.addPart(part);
1344   }
1345
1346   /**
1347    * Create a Response Message
1348    *
1349    * @param def
1350    * @throws WSDLException
1351    * @throws AxisFault
1352    */

1353   protected Message writeResponseMessage(Definition def,
1354                                          OperationDesc desc)
1355           throws WSDLException, AxisFault
1356   {
1357      Message msg = def.createMessage();
1358
1359      QName JavaDoc qName = createMessageName(def, desc.getName() + "Response");
1360
1361      msg.setQName(qName);
1362      msg.setUndefined(false);
1363
1364      if (desc.getStyle() == Style.WRAPPED)
1365      {
1366         writeWrapperPart(def, msg, desc, false);
1367      }
1368      else
1369      {
1370         // Write the part
1371
ParameterDesc retParam = new ParameterDesc();
1372         if (desc.getReturnQName() == null)
1373         {
1374            String JavaDoc ns = "";
1375            if (desc.getStyle() != Style.RPC)
1376            {
1377               ns = getServiceDesc().getDefaultNamespace();
1378               if (ns == null || "".equals(ns))
1379               {
1380                  ns = "http://ws.apache.org/axis/defaultNS";
1381               }
1382            }
1383            retParam.setQName(new QName JavaDoc(ns, desc.getName() + "Response"));
1384         }
1385         else
1386         {
1387            retParam.setQName(desc.getReturnQName());
1388         }
1389         retParam.setTypeQName(desc.getReturnType());
1390         retParam.setMode(ParameterDesc.OUT);
1391         retParam.setIsReturn(true);
1392         retParam.setJavaType(desc.getReturnClass());
1393         writePartToMessage(def, msg, false, retParam);
1394
1395         ArrayList JavaDoc parameters = desc.getAllOutParams();
1396         for (Iterator JavaDoc i = parameters.iterator(); i.hasNext();)
1397         {
1398            ParameterDesc param = (ParameterDesc)i.next();
1399            writePartToMessage(def, msg, false, param);
1400         }
1401      }
1402      return msg;
1403   }
1404
1405   /**
1406    * Create a Fault Message
1407    *
1408    * @param def
1409    * @param exception (an ExceptionRep object)
1410    * @throws WSDLException
1411    * @throws AxisFault
1412    */

1413   protected Message writeFaultMessage(Definition def,
1414                                       FaultDesc exception)
1415           throws WSDLException, AxisFault
1416   {
1417
1418      String JavaDoc pkgAndClsName = exception.getClassName();
1419      String JavaDoc clsName = pkgAndClsName.substring(pkgAndClsName.lastIndexOf('.') + 1,
1420              pkgAndClsName.length());
1421
1422      // Do this to cover the complex type case with no meta data
1423
exception.setName(clsName);
1424
1425      // The following code uses the class name for both the name= attribute
1426
// and the message= attribute.
1427

1428      Message msg = (Message)exceptionMsg.get(pkgAndClsName);
1429
1430      if (msg == null)
1431      {
1432         msg = def.createMessage();
1433         QName JavaDoc qName = createMessageName(def, clsName);
1434
1435         msg.setQName(qName);
1436         msg.setUndefined(false);
1437
1438         ArrayList JavaDoc parameters = exception.getParameters();
1439         if (parameters != null)
1440         {
1441            for (int i = 0; i < parameters.size(); i++)
1442            {
1443               ParameterDesc parameter = (ParameterDesc)parameters.get(i);
1444               writePartToMessage(def, msg, true, parameter);
1445            }
1446         }
1447         exceptionMsg.put(pkgAndClsName, msg);
1448      }
1449
1450      return msg;
1451
1452   }
1453
1454   /**
1455    * Create a Part
1456    *
1457    * @param def
1458    * @param msg
1459    * @param request message is for a request
1460    * @param param ParamRep object
1461    * @return The parameter name added or null
1462    * @throws WSDLException
1463    * @throws AxisFault
1464    */

1465   public String JavaDoc writePartToMessage(Definition def,
1466                                    Message msg,
1467                                    boolean request,
1468                                    ParameterDesc param) throws WSDLException, AxisFault
1469   {
1470      // Return if this is a void type
1471
if (param == null ||
1472              param.getJavaType() == java.lang.Void.TYPE)
1473         return null;
1474
1475      // If Request message, only continue if IN or INOUT
1476
// If Response message, only continue if OUT or INOUT
1477
if (request &&
1478              param.getMode() == ParameterDesc.OUT)
1479      {
1480         return null;
1481      }
1482      if (!request &&
1483              param.getMode() == ParameterDesc.IN)
1484      {
1485         return null;
1486      }
1487
1488      // Create the Part
1489
Part part = def.createPart();
1490
1491      // Get the java type to represent in the wsdl
1492
// (if the mode is OUT or INOUT and this
1493
// parameter does not represent the return type,
1494
// the type held in the Holder is the one that should
1495
// be written.)
1496
Class JavaDoc javaType = param.getJavaType();
1497      if (param.getMode() != ParameterDesc.IN &&
1498              param.getIsReturn() == false)
1499      {
1500         javaType = JavaUtils.getHolderValueType(javaType);
1501      }
1502
1503      if (use == Use.ENCODED || style == Style.RPC)
1504      {
1505         // Add the type representing the param
1506
// For convenience, add an element for the param
1507
// Write <part name=param_name type=param_type>
1508
QName JavaDoc typeQName = param.getTypeQName();
1509         if (javaType != null)
1510            typeQName = types.writeTypeForPart(javaType,
1511                    typeQName);
1512         //types.writeElementForPart(javaType, param.getTypeQName());
1513
if (typeQName != null)
1514         {
1515            part.setName(param.getName());
1516            part.setTypeName(typeQName);
1517            msg.addPart(part);
1518         }
1519      }
1520      else if (use == Use.LITERAL)
1521      {
1522         // This is doc/lit. So we should write out an element
1523
// declaration whose name and type may be found in the
1524
// ParameterDesc.
1525
QName JavaDoc qname = param.getQName();
1526         Element JavaDoc el = types.createElementDecl(qname.getLocalPart(),
1527                 param.getJavaType(),
1528                 param.getTypeQName(),
1529                 false, false);
1530         types.writeSchemaElement(qname, el);
1531
1532         part.setName(param.getName());
1533         part.setElementName(qname);
1534         msg.addPart(part);
1535      }
1536      return param.getName();
1537   }
1538
1539   /*
1540    * Return a message QName which has not already been defined in the WSDL
1541    */

1542   protected QName JavaDoc createMessageName(Definition def, String JavaDoc methodName)
1543   {
1544
1545      QName JavaDoc qName = new QName JavaDoc(intfNS, methodName);
1546
1547      // Check the make sure there isn't a message with this name already
1548
int messageNumber = 1;
1549      while (def.getMessage(qName) != null)
1550      {
1551         StringBuffer JavaDoc namebuf = new StringBuffer JavaDoc(methodName);
1552         namebuf.append(messageNumber);
1553         qName = new QName JavaDoc(intfNS, namebuf.toString());
1554         messageNumber++;
1555      }
1556      return qName;
1557   }
1558
1559   /**
1560    * Write a prettified document to a file.
1561    *
1562    * @param doc the Document to write
1563    * @param filename the name of the file to be written
1564    * @throws IOException various file i/o exceptions
1565    */

1566   protected void prettyDocumentToFile(Document JavaDoc doc, String JavaDoc filename)
1567           throws IOException JavaDoc
1568   {
1569      FileOutputStream JavaDoc fos = new FileOutputStream JavaDoc(new File JavaDoc(filename));
1570      XMLUtils.PrettyDocumentToStream(doc, fos);
1571      fos.close();
1572   }
1573
1574   // -------------------- Parameter Query Methods ----------------------------//
1575

1576   /**
1577    * Returns the <code>Class</code> to export
1578    *
1579    * @return the <code>Class</code> to export
1580    */

1581   public Class JavaDoc getCls()
1582   {
1583      return cls;
1584   }
1585
1586   /**
1587    * Sets the <code>Class</code> to export
1588    *
1589    * @param cls the <code>Class</code> to export
1590    */

1591   public void setCls(Class JavaDoc cls)
1592   {
1593      this.cls = cls;
1594   }
1595
1596   /**
1597    * Sets the <code>Class</code> to export.
1598    *
1599    * @param cls the <code>Class</code> to export
1600    */

1601   public void setClsSmart(Class JavaDoc cls, String JavaDoc location)
1602   {
1603
1604      if (cls == null || location == null)
1605         return;
1606
1607      // Strip off \ and / from location
1608
if (location.lastIndexOf('/') > 0)
1609      {
1610         location =
1611                 location.substring(location.lastIndexOf('/') + 1);
1612      }
1613      else if (location.lastIndexOf('\\') > 0)
1614      {
1615         location =
1616                 location.substring(location.lastIndexOf('\\') + 1);
1617      }
1618
1619      // Get the constructors of the class
1620
java.lang.reflect.Constructor JavaDoc[] constructors =
1621              cls.getDeclaredConstructors();
1622      Class JavaDoc intf = null;
1623      for (int i = 0; i < constructors.length && intf == null; i++)
1624      {
1625         Class JavaDoc[] parms = constructors[i].getParameterTypes();
1626         // If the constructor has a single parameter
1627
// that is an interface which
1628
// matches the location, then use this as the interface class.
1629
if (parms.length == 1 &&
1630                 parms[0].isInterface() &&
1631                 parms[0].getName() != null &&
1632                 Types.getLocalNameFromFullName(parms[0].getName()).equals(location))
1633         {
1634            intf = parms[0];
1635         }
1636      }
1637      if (intf != null)
1638      {
1639         setCls(intf);
1640         if (implCls == null)
1641         {
1642            setImplCls(cls);
1643         }
1644      }
1645      else
1646         setCls(cls);
1647   }
1648
1649   /**
1650    * Sets the <code>Class</code> to export
1651    *
1652    * @param className the name of the <code>Class</code> to export
1653    */

1654   public void setCls(String JavaDoc className) throws ClassNotFoundException JavaDoc
1655   {
1656      cls = ClassUtils.forName(className);
1657   }
1658
1659   /**
1660    * Returns the implementation <code>Class</code> if set
1661    *
1662    * @return the implementation Class or null
1663    */

1664   public Class JavaDoc getImplCls()
1665   {
1666      return implCls;
1667   }
1668
1669   /**
1670    * Sets the implementation <code>Class</code>
1671    *
1672    * @param implCls the <code>Class</code> to export
1673    */

1674   public void setImplCls(Class JavaDoc implCls)
1675   {
1676      this.implCls = implCls;
1677   }
1678
1679   /**
1680    * Sets the implementation <code>Class</code>
1681    *
1682    * @param className the name of the implementation <code>Class</code>
1683    */

1684   public void setImplCls(String JavaDoc className)
1685   {
1686      try
1687      {
1688         implCls = ClassUtils.forName(className);
1689      }
1690      catch (Exception JavaDoc ex)
1691      {
1692         ex.printStackTrace();
1693      }
1694   }
1695
1696   /**
1697    * Returns the interface namespace
1698    *
1699    * @return interface target namespace
1700    */

1701   public String JavaDoc getIntfNamespace()
1702   {
1703      return intfNS;
1704   }
1705
1706   /**
1707    * Set the interface namespace
1708    *
1709    * @param ns interface target namespace
1710    */

1711   public void setIntfNamespace(String JavaDoc ns)
1712   {
1713      this.intfNS = ns;
1714   }
1715
1716   /**
1717    * Returns the implementation namespace
1718    *
1719    * @return implementation target namespace
1720    */

1721   public String JavaDoc getImplNamespace()
1722   {
1723      return implNS;
1724   }
1725
1726   /**
1727    * Set the implementation namespace
1728    *
1729    * @param ns implementation target namespace
1730    */

1731   public void setImplNamespace(String JavaDoc ns)
1732   {
1733      this.implNS = ns;
1734   }
1735
1736   /**
1737    * Returns a vector of methods to export
1738    *
1739    * @return a space separated list of methods to export
1740    */

1741   public Vector JavaDoc getAllowedMethods()
1742   {
1743      return allowedMethods;
1744   }
1745
1746   /**
1747    * Add a list of methods to export
1748    */

1749   public void setAllowedMethods(String JavaDoc text)
1750   {
1751      if (text != null)
1752      {
1753         StringTokenizer JavaDoc tokenizer = new StringTokenizer JavaDoc(text, " ,+");
1754         if (allowedMethods == null)
1755         {
1756            allowedMethods = new Vector JavaDoc();
1757         }
1758         while (tokenizer.hasMoreTokens())
1759         {
1760            allowedMethods.add(tokenizer.nextToken());
1761         }
1762      }
1763   }
1764
1765   /**
1766    * Add a Vector of methods to export
1767    *
1768    * @param allowedMethods a vector of methods to export
1769    */

1770   public void setAllowedMethods(Vector JavaDoc allowedMethods)
1771   {
1772      if (this.allowedMethods == null)
1773      {
1774         this.allowedMethods = new Vector JavaDoc();
1775      }
1776      this.allowedMethods.addAll(allowedMethods);
1777   }
1778
1779   /**
1780    * Indicates if the emitter will search classes for inherited methods
1781    */

1782   public boolean getUseInheritedMethods()
1783   {
1784      return useInheritedMethods;
1785   }
1786
1787   /**
1788    * Turn on or off inherited method WSDL generation.
1789    */

1790   public void setUseInheritedMethods(boolean useInheritedMethods)
1791   {
1792      this.useInheritedMethods = useInheritedMethods;
1793   }
1794
1795   /**
1796    * Add a list of methods NOT to export
1797    *
1798    * @param disallowedMethods vector of method name strings
1799    */

1800   public void setDisallowedMethods(Vector JavaDoc disallowedMethods)
1801   {
1802      if (this.disallowedMethods == null)
1803      {
1804         this.disallowedMethods = new Vector JavaDoc();
1805      }
1806      this.disallowedMethods.addAll(disallowedMethods);
1807   }
1808
1809   /**
1810    * Add a list of methods NOT to export
1811    *
1812    * @param text space separated list of method names
1813    */

1814   public void setDisallowedMethods(String JavaDoc text)
1815   {
1816      if (text != null)
1817      {
1818         StringTokenizer JavaDoc tokenizer = new StringTokenizer JavaDoc(text, " ,+");
1819         if (disallowedMethods == null)
1820         {
1821            disallowedMethods = new Vector JavaDoc();
1822         }
1823         disallowedMethods = new Vector JavaDoc();
1824         while (tokenizer.hasMoreTokens())
1825         {
1826            disallowedMethods.add(tokenizer.nextToken());
1827         }
1828      }
1829   }
1830
1831   /**
1832    * Return list of methods that should not be exported
1833    */

1834   public Vector JavaDoc getDisallowedMethods()
1835   {
1836      return disallowedMethods;
1837   }
1838
1839   /**
1840    * Adds a list of classes (fully qualified) that will stop the traversal
1841    * of the inheritance tree if encounter in method or complex type generation
1842    *
1843    * @param stopClasses vector of class name strings
1844    */

1845   public void setStopClasses(ArrayList JavaDoc stopClasses)
1846   {
1847      if (this.stopClasses == null)
1848      {
1849         this.stopClasses = new ArrayList JavaDoc();
1850      }
1851      this.stopClasses.addAll(stopClasses);
1852   }
1853
1854   /**
1855    * Add a list of classes (fully qualified) that will stop the traversal
1856    * of the inheritance tree if encounter in method or complex type generation
1857    *
1858    * @param text space separated list of class names
1859    */

1860   public void setStopClasses(String JavaDoc text)
1861   {
1862      if (text != null)
1863      {
1864         StringTokenizer JavaDoc tokenizer = new StringTokenizer JavaDoc(text, " ,+");
1865         if (stopClasses == null)
1866         {
1867            stopClasses = new ArrayList JavaDoc();
1868         }
1869         while (tokenizer.hasMoreTokens())
1870         {
1871            stopClasses.add(tokenizer.nextToken());
1872         }
1873      }
1874   }
1875
1876   /**
1877    * Return the list of classes which stop inhertance searches
1878    */

1879   public ArrayList JavaDoc getStopClasses()
1880   {
1881      return stopClasses;
1882   }
1883
1884   /**
1885    * get the packagename to namespace map
1886    *
1887    * @return <code>Map</code>
1888    */

1889   public Map JavaDoc getNamespaceMap()
1890   {
1891      return namespaces;
1892   }
1893
1894   /**
1895    * Set the packagename to namespace map with the given map
1896    *
1897    * @param map packagename/namespace <code>Map</code>
1898    */

1899   public void setNamespaceMap(Map JavaDoc map)
1900   {
1901      if (map != null)
1902         namespaces.putAll(map);
1903   }
1904
1905   /**
1906    * Get the name of the input WSDL
1907    *
1908    * @return name of the input wsdl or null
1909    */

1910   public String JavaDoc getInputWSDL()
1911   {
1912      return inputWSDL;
1913   }
1914
1915   /**
1916    * Set the name of the input WSDL
1917    *
1918    * @param inputWSDL the name of the input WSDL
1919    */

1920   public void setInputWSDL(String JavaDoc inputWSDL)
1921   {
1922      this.inputWSDL = inputWSDL;
1923   }
1924
1925   /**
1926    * @return the name of the input schema, or null
1927    */

1928   public String JavaDoc getInputSchema()
1929   {
1930      return inputSchema;
1931   }
1932
1933   /**
1934    * Set the name of the input schema
1935    *
1936    * @param inputSchema the name of the input schema
1937    */

1938   public void setInputSchema(String JavaDoc inputSchema)
1939   {
1940      this.inputSchema = inputSchema;
1941   }
1942
1943   /**
1944    * Returns the String representation of the service endpoint URL
1945    *
1946    * @return String representation of the service endpoint URL
1947    */

1948   public String JavaDoc getLocationUrl()
1949   {
1950      return locationUrl;
1951   }
1952
1953   /**
1954    * Set the String representation of the service endpoint URL
1955    *
1956    * @param locationUrl the String representation of the service endpoint URL
1957    */

1958   public void setLocationUrl(String JavaDoc locationUrl)
1959   {
1960      this.locationUrl = locationUrl;
1961   }
1962
1963   /**
1964    * Returns the String representation of the interface import location URL
1965    *
1966    * @return String representation of the interface import location URL
1967    */

1968   public String JavaDoc getImportUrl()
1969   {
1970      return importUrl;
1971   }
1972
1973   /**
1974    * Set the String representation of the interface location URL
1975    * for importing
1976    *
1977    * @param importUrl the String representation of the interface
1978    * location URL for importing
1979    */

1980   public void setImportUrl(String JavaDoc importUrl)
1981   {
1982      this.importUrl = importUrl;
1983   }
1984
1985   /**
1986    * Returns the String representation of the service port name
1987    *
1988    * @return String representation of the service port name
1989    */

1990   public String JavaDoc getServicePortName()
1991   {
1992      return servicePortName;
1993   }
1994
1995   /**
1996    * Set the String representation of the service port name
1997    *
1998    * @param servicePortName the String representation of the service port name
1999    */

2000   public void setServicePortName(String JavaDoc servicePortName)
2001   {
2002      this.servicePortName = servicePortName;
2003   }
2004
2005   /**
2006    * Returns the String representation of the service element name
2007    *
2008    * @return String representation of the service element name
2009    */

2010   public String JavaDoc getServiceElementName()
2011   {
2012      return serviceElementName;
2013   }
2014
2015   /**
2016    * Set the String representation of the service element name
2017    *
2018    * @param serviceElementName the String representation of the service element name
2019    */

2020   public void setServiceElementName(String JavaDoc serviceElementName)
2021   {
2022      this.serviceElementName = serviceElementName;
2023   }
2024
2025   /**
2026    * Returns the String representation of the portType name
2027    *
2028    * @return String representation of the portType name
2029    */

2030   public String JavaDoc getPortTypeName()
2031   {
2032      return portTypeName;
2033   }
2034
2035   /**
2036    * Set the String representation of the portType name
2037    *
2038    * @param portTypeName the String representation of the portType name
2039    */

2040   public void setPortTypeName(String JavaDoc portTypeName)
2041   {
2042      this.portTypeName = portTypeName;
2043   }
2044
2045   /**
2046    * Returns the String representation of the binding name
2047    *
2048    * @return String representation of the binding name
2049    */

2050   public String JavaDoc getBindingName()
2051   {
2052      return bindingName;
2053   }
2054
2055   /**
2056    * Set the String representation of the binding name
2057    *
2058    * @param bindingName the String representation of the binding name
2059    */

2060   public void setBindingName(String JavaDoc bindingName)
2061   {
2062      this.bindingName = bindingName;
2063   }
2064
2065   /**
2066    * Returns the target service name
2067    *
2068    * @return the target service name
2069    */

2070   public String JavaDoc getTargetService()
2071   {
2072      return targetService;
2073   }
2074
2075   /**
2076    * Set the target service name
2077    *
2078    * @param targetService the target service name
2079    */

2080   public void setTargetService(String JavaDoc targetService)
2081   {
2082      this.targetService = targetService;
2083   }
2084
2085   /**
2086    * Returns the service description
2087    *
2088    * @return service description String
2089    */

2090   public String JavaDoc getDescription()
2091   {
2092      return description;
2093   }
2094
2095   /**
2096    * Set the service description
2097    *
2098    * @param description service description String
2099    */

2100   public void setDescription(String JavaDoc description)
2101   {
2102      this.description = description;
2103   }
2104
2105   /**
2106    * Returns the soapAction option value
2107    *
2108    * @return the String DEFAULT, NONE or OPERATION
2109    */

2110   public String JavaDoc getSoapAction()
2111   {
2112      return soapAction;
2113   }
2114
2115   /**
2116    * Sets the soapAction option value
2117    *
2118    * @param value must be DEFAULT, NONE, or OPERATION
2119    */

2120   public void setSoapAction(String JavaDoc value)
2121   {
2122      soapAction = value;
2123   }
2124
2125   /**
2126    * Returns the <code>TypeMapping</code> used by the service
2127    *
2128    * @return the <code>TypeMapping</code> used by the service
2129    */

2130   public TypeMapping getTypeMapping()
2131   {
2132      return tm;
2133   }
2134
2135   /**
2136    * Sets the <code>TypeMapping</code> used by the service
2137    *
2138    * @param tm the <code>TypeMapping</code> used by the service
2139    */

2140   public void setTypeMapping(TypeMapping tm)
2141   {
2142      this.tm = tm;
2143   }
2144
2145   /**
2146    * Returns the default <code>TypeMapping</code> used by the service
2147    *
2148    * @return the default <code>TypeMapping</code> used by the service
2149    */

2150   public TypeMapping getDefaultTypeMapping()
2151   {
2152      return defaultTM;
2153   }
2154
2155   /**
2156    * Sets the default <code>TypeMapping</code> used by the service
2157    *
2158    * @param defaultTM the default <code>TypeMapping</code> used by the service
2159    */

2160   public void setDefaultTypeMapping(TypeMapping defaultTM)
2161   {
2162      this.defaultTM = defaultTM;
2163   }
2164
2165
2166   /**
2167    * getStyle
2168    *
2169    * @return Style setting (Style.RPC, Style.DOCUMENT, Style.WRAPPED, etc.)
2170    */

2171   public Style getStyle()
2172   {
2173      return style;
2174   }
2175
2176   /**
2177    * setStyle
2178    *
2179    * @param value String representing a style ("document", "rpc", "wrapped")
2180    * Note that the case of the string is not important. "document" and "DOCUMENT"
2181    * are both treated as document style.
2182    * If the value is not a know style, the default setting is used.
2183    * See org.jboss.axis.enums.Style for a description of the interaction between
2184    * Style/Use
2185    * <br>NOTE: If style is specified as "wrapped", use is set to literal.
2186    */

2187   public void setStyle(String JavaDoc value)
2188   {
2189      setStyle(Style.getStyle(value));
2190   }
2191
2192   /**
2193    * setStyle
2194    *
2195    * @param value Style setting
2196    */

2197   public void setStyle(Style value)
2198   {
2199      style = value;
2200      if (style.equals(Style.WRAPPED))
2201      {
2202         setUse(Use.LITERAL);
2203      }
2204   }
2205
2206   /**
2207    * getUse
2208    *
2209    * @return Use setting (Use.ENCODED, Use.LITERAL)
2210    */

2211   public Use getUse()
2212   {
2213      return use;
2214   }
2215
2216   /**
2217    * setUse
2218    *
2219    * @param value String representing a use ("literal", "encoded")
2220    * Note that the case of the string is not important. "literal" and "LITERAL"
2221    * are both treated as literal use.
2222    * If the value is not a know use, the default setting is used.
2223    * See org.jboss.axis.enums.Style for a description of the interaction between
2224    * Style/Use
2225    */

2226   public void setUse(String JavaDoc value)
2227   {
2228      use = Use.getUse(value);
2229   }
2230
2231   /**
2232    * setUse
2233    *
2234    * @param value Use setting
2235    */

2236   public void setUse(Use value)
2237   {
2238      use = value;
2239   }
2240
2241   /**
2242    * setMode (sets style and use)
2243    *
2244    * @deprecated (use setStyle and setUse)
2245    */

2246   public void setMode(int mode)
2247   {
2248      if (mode == MODE_RPC)
2249      {
2250         setStyle(Style.RPC);
2251         setUse(Use.ENCODED);
2252      }
2253      else if (mode == MODE_DOCUMENT)
2254      {
2255         setStyle(Style.DOCUMENT);
2256         setUse(Use.LITERAL);
2257      }
2258      else if (mode == MODE_DOC_WRAPPED)
2259      {
2260         setStyle(Style.WRAPPED);
2261         setUse(Use.LITERAL);
2262      }
2263   }
2264
2265   /**
2266    * getMode (gets the mode based on the style setting)
2267    *
2268    * @return returns the mode (-1 if invalid)
2269    * @deprecated (use getStyle and getUse)
2270    */

2271   public int getMode()
2272   {
2273      if (style == Style.RPC)
2274      {
2275         return MODE_RPC;
2276      }
2277      else if (style == Style.DOCUMENT)
2278      {
2279         return MODE_DOCUMENT;
2280      }
2281      else if (style == Style.WRAPPED)
2282      {
2283         return MODE_DOC_WRAPPED;
2284      }
2285      return -1;
2286   }
2287
2288   public ServiceDesc getServiceDesc()
2289   {
2290      return serviceDesc;
2291   }
2292
2293   public void setServiceDesc(ServiceDesc serviceDesc)
2294   {
2295      this.serviceDesc = serviceDesc;
2296   }
2297
2298   /**
2299    * Return the list of extra classes that the emitter will produce WSDL for.
2300    */

2301   public Class JavaDoc[] getExtraClasses()
2302   {
2303      return extraClasses;
2304   }
2305
2306   /**
2307    * Provide a list of classes which the emitter will produce WSDL
2308    * type definitions for.
2309    */

2310   public void setExtraClasses(Class JavaDoc[] extraClasses)
2311   {
2312      this.extraClasses = extraClasses;
2313   }
2314
2315   /**
2316    * Provide a comma or space seperated list of classes which
2317    * the emitter will produce WSDL type definitions for.
2318    * The classes will be added to the current list.
2319    */

2320   public void setExtraClasses(String JavaDoc text) throws ClassNotFoundException JavaDoc
2321   {
2322      ArrayList JavaDoc clsList = new ArrayList JavaDoc();
2323      if (text != null)
2324      {
2325         StringTokenizer JavaDoc tokenizer = new StringTokenizer JavaDoc(text, " ,");
2326         while (tokenizer.hasMoreTokens())
2327         {
2328            String JavaDoc clsName = tokenizer.nextToken();
2329            // Let the caller handler ClassNotFoundException
2330
Class JavaDoc cls = ClassUtils.forName(clsName);
2331            clsList.add(cls);
2332         }
2333      }
2334      // Allocate the new array
2335
Class JavaDoc[] ec;
2336      if (extraClasses != null)
2337      {
2338         ec = new Class JavaDoc[clsList.size() + extraClasses.length];
2339         // copy existing elements
2340
for (int i = 0; i < extraClasses.length; i++)
2341         {
2342            Class JavaDoc c = extraClasses[i];
2343            ec[i] = c;
2344         }
2345      }
2346      else
2347      {
2348         ec = new Class JavaDoc[clsList.size()];
2349      }
2350      // copy the new classes
2351
for (int i = 0; i < clsList.size(); i++)
2352      {
2353         Class JavaDoc c = (Class JavaDoc)clsList.get(i);
2354         ec[i] = c;
2355      }
2356      // set the member variable
2357
this.extraClasses = ec;
2358   }
2359
2360}
2361
Popular Tags