KickJava   Java API By Example, From Geeks To Geeks.

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


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

16 package org.apache.axis.wsdl.toJava;
17
18 import org.apache.axis.Constants;
19 import org.apache.axis.deployment.wsdd.WSDDConstants;
20 import org.apache.axis.description.OperationDesc;
21 import org.apache.axis.description.ServiceDesc;
22 import org.apache.axis.components.logger.LogFactory;
23 import org.apache.axis.constants.Scope;
24 import org.apache.axis.constants.Style;
25 import org.apache.axis.constants.Use;
26 import org.apache.axis.utils.JavaUtils;
27 import org.apache.axis.utils.Messages;
28 import org.apache.axis.wsdl.symbolTable.BindingEntry;
29 import org.apache.axis.wsdl.symbolTable.FaultInfo;
30 import org.apache.axis.wsdl.symbolTable.Parameter;
31 import org.apache.axis.wsdl.symbolTable.Parameters;
32 import org.apache.axis.wsdl.symbolTable.SchemaUtils;
33 import org.apache.axis.wsdl.symbolTable.SymbolTable;
34 import org.apache.axis.wsdl.symbolTable.TypeEntry;
35 import org.apache.commons.logging.Log;
36
37 import javax.wsdl.Binding;
38 import javax.wsdl.BindingOperation;
39 import javax.wsdl.Definition;
40 import javax.wsdl.Operation;
41 import javax.wsdl.OperationType;
42 import javax.wsdl.Port;
43 import javax.wsdl.Service;
44 import javax.wsdl.extensions.UnknownExtensibilityElement;
45 import javax.wsdl.extensions.soap.SOAPBinding;
46 import javax.xml.namespace.QName JavaDoc;
47 import java.io.File JavaDoc;
48 import java.io.FileOutputStream JavaDoc;
49 import java.io.IOException JavaDoc;
50 import java.io.OutputStreamWriter JavaDoc;
51 import java.io.PrintWriter JavaDoc;
52 import java.util.ArrayList JavaDoc;
53 import java.util.Collection JavaDoc;
54 import java.util.HashMap JavaDoc;
55 import java.util.HashSet JavaDoc;
56 import java.util.Iterator JavaDoc;
57 import java.util.Map JavaDoc;
58 import java.util.Vector JavaDoc;
59
60 /**
61  * This is Wsdl2java's deploy Writer. It writes the deploy.wsdd file.
62  */

63 public class JavaDeployWriter extends JavaWriter {
64     /** Field log */
65     protected static Log log = LogFactory.getLog(JavaDeployWriter.class.getName());
66
67     /** Field definition */
68     protected Definition definition;
69
70     /** Field symbolTable */
71     protected SymbolTable symbolTable;
72
73     /** Field emitter */
74     protected Emitter emitter;
75
76     /** Field use */
77     Use use = Use.DEFAULT;
78
79     /**
80      * Constructor.
81      *
82      * @param emitter
83      * @param definition
84      * @param symbolTable
85      */

86     public JavaDeployWriter(Emitter emitter, Definition definition,
87                             SymbolTable symbolTable) {
88
89         super(emitter, "deploy");
90
91         this.emitter = emitter;
92         this.definition = definition;
93         this.symbolTable = symbolTable;
94     } // ctor
95

96     /**
97      * Generate deploy.wsdd. Only generate it if the emitter
98      * is generating server-side mappings.
99      *
100      * @throws IOException
101      */

102     public void generate() throws IOException JavaDoc {
103
104         if (emitter.isServerSide()) {
105             super.generate();
106         }
107     } // generate
108

109     /**
110      * Return the fully-qualified name of the deploy.wsdd file
111      * to be generated.
112      *
113      * @return
114      */

115     protected String JavaDoc getFileName() {
116
117         String JavaDoc dir =
118                 emitter.getNamespaces().getAsDir(definition.getTargetNamespace());
119
120         return dir + "deploy.wsdd";
121     } // getFileName
122

123     /**
124      * Replace the default file header with the deployment doc file header.
125      *
126      * @param pw
127      * @throws IOException
128      */

129     protected void writeFileHeader(PrintWriter JavaDoc pw) throws IOException JavaDoc {
130
131         pw.println(Messages.getMessage("deploy00"));
132         pw.println(Messages.getMessage("deploy02"));
133         pw.println(Messages.getMessage("deploy03"));
134         pw.println(Messages.getMessage("deploy05"));
135         pw.println(Messages.getMessage("deploy06"));
136         pw.println(Messages.getMessage("deploy07"));
137         pw.println(Messages.getMessage("deploy09"));
138         pw.println();
139         pw.println("<deployment");
140         pw.println(" xmlns=\"" + WSDDConstants.URI_WSDD + "\"");
141         pw.println(" xmlns:" + WSDDConstants.NS_PREFIX_WSDD_JAVA + "=\""
142                 + WSDDConstants.URI_WSDD_JAVA + "\">");
143     } // writeFileHeader
144

145     /**
146      * Write the body of the deploy.wsdd file.
147      *
148      * @param pw
149      * @throws IOException
150      */

151     protected void writeFileBody(PrintWriter JavaDoc pw) throws IOException JavaDoc {
152         writeDeployServices(pw);
153         pw.println("</deployment>");
154     } // writeFileBody
155

156     /**
157      * Write out deployment and undeployment instructions for each WSDL service
158      *
159      * @param pw
160      * @throws IOException
161      */

162     protected void writeDeployServices(PrintWriter JavaDoc pw) throws IOException JavaDoc {
163
164         // deploy the ports on each service
165
Map JavaDoc serviceMap = definition.getServices();
166
167         for (Iterator JavaDoc mapIterator = serviceMap.values().iterator();
168              mapIterator.hasNext();) {
169             Service myService = (Service) mapIterator.next();
170
171             pw.println();
172             pw.println(
173                     " <!-- "
174                     + Messages.getMessage(
175                             "wsdlService00", myService.getQName().getLocalPart()) + " -->");
176             pw.println();
177
178             for (Iterator JavaDoc portIterator = myService.getPorts().values().iterator();
179                  portIterator.hasNext();) {
180                 Port myPort = (Port) portIterator.next();
181                 BindingEntry bEntry =
182                         symbolTable.getBindingEntry(myPort.getBinding().getQName());
183
184                 // If this isn't an SOAP binding, skip it
185
if (bEntry.getBindingType() != BindingEntry.TYPE_SOAP) {
186                     continue;
187                 }
188
189                 writeDeployPort(pw, myPort, myService, bEntry);
190             }
191         }
192     } // writeDeployServices
193

194     /**
195      * Write out bean mappings for each type
196      *
197      * @param pw
198      * @param binding
199      * @param hasLiteral
200      * @param hasMIME
201      * @param use
202      * @throws IOException
203      */

204     protected void writeDeployTypes(
205             PrintWriter JavaDoc pw, Binding binding, boolean hasLiteral, boolean hasMIME, Use use)
206             throws IOException JavaDoc {
207
208         pw.println();
209
210         if (hasMIME) {
211             QName JavaDoc bQName = binding.getQName();
212
213             writeTypeMapping(
214                     pw, bQName.getNamespaceURI(), "DataHandler",
215                     "javax.activation.DataHandler",
216                     "org.apache.axis.encoding.ser.JAFDataHandlerSerializerFactory",
217                     "org.apache.axis.encoding.ser.JAFDataHandlerDeserializerFactory",
218                     use.getEncoding());
219         }
220
221         Map JavaDoc types = symbolTable.getTypeIndex();
222         Collection JavaDoc typeCollection = types.values();
223         for (Iterator JavaDoc i = typeCollection.iterator(); i.hasNext(); ) {
224             TypeEntry type = (TypeEntry) i.next();
225
226             // Note this same check is repeated in JavaStubWriter.
227
boolean process = true;
228
229             // Don't register types we shouldn't (see Utils.shouldEmit for
230
// details)
231
if (!Utils.shouldEmit(type)) {
232                 process = false;
233             }
234
235             if (process) {
236                 String JavaDoc namespaceURI = type.getQName().getNamespaceURI();
237                 String JavaDoc localPart = type.getQName().getLocalPart();
238                 String JavaDoc javaType = type.getName();
239                 String JavaDoc serializerFactory;
240                 String JavaDoc deserializerFactory;
241                 String JavaDoc encodingStyle = "";
242                 QName JavaDoc innerType = null;
243
244                 if (!hasLiteral) {
245                     encodingStyle = use.getEncoding();
246                 }
247
248                 if (javaType.endsWith("[]")) {
249                     if (SchemaUtils.isListWithItemType(type.getNode())) {
250                         serializerFactory =
251                         "org.apache.axis.encoding.ser.SimpleListSerializerFactory";
252                         deserializerFactory =
253                         "org.apache.axis.encoding.ser.SimpleListDeserializerFactory";
254                     } else {
255                         serializerFactory =
256                         "org.apache.axis.encoding.ser.ArraySerializerFactory";
257                         deserializerFactory =
258                         "org.apache.axis.encoding.ser.ArrayDeserializerFactory";
259                         innerType = type.getComponentType();
260                     }
261                 } else if ((type.getNode() != null) && (Utils.getEnumerationBaseAndValues(
262                         type.getNode(), symbolTable) != null)) {
263                     serializerFactory =
264                             "org.apache.axis.encoding.ser.EnumSerializerFactory";
265                     deserializerFactory =
266                             "org.apache.axis.encoding.ser.EnumDeserializerFactory";
267                 } else if (type.isSimpleType()) {
268                     serializerFactory =
269                             "org.apache.axis.encoding.ser.SimpleSerializerFactory";
270                     deserializerFactory =
271                             "org.apache.axis.encoding.ser.SimpleDeserializerFactory";
272                 } else if (type.getBaseType() != null) {
273                     serializerFactory =
274                             "org.apache.axis.encoding.ser.SimpleSerializerFactory";
275                     deserializerFactory =
276                             "org.apache.axis.encoding.ser.SimpleDeserializerFactory";
277                 } else {
278                     serializerFactory =
279                             "org.apache.axis.encoding.ser.BeanSerializerFactory";
280                     deserializerFactory =
281                             "org.apache.axis.encoding.ser.BeanDeserializerFactory";
282                 }
283
284                 if (innerType == null) {
285                     // no arrays
286
writeTypeMapping(pw, namespaceURI, localPart, javaType,
287                         serializerFactory, deserializerFactory,
288                         encodingStyle);
289                 } else {
290                     // arrays
291
writeArrayTypeMapping(pw, namespaceURI, localPart, javaType,
292                             encodingStyle, innerType);
293                 }
294             }
295         }
296     } // writeDeployTypes
297

298     /**
299      * Raw routine that writes out the typeMapping.
300      *
301      * @param pw
302      * @param namespaceURI
303      * @param localPart
304      * @param javaType
305      * @param serializerFactory
306      * @param deserializerFactory
307      * @param encodingStyle
308      * @throws IOException
309      */

310     protected void writeArrayTypeMapping(
311             PrintWriter JavaDoc pw, String JavaDoc namespaceURI, String JavaDoc localPart, String JavaDoc javaType, String JavaDoc encodingStyle, QName JavaDoc innerType)
312             throws IOException JavaDoc {
313
314         pw.println(" <arrayMapping");
315         pw.println(" xmlns:ns=\"" + namespaceURI + "\"");
316         pw.println(" qname=\"ns:" + localPart + '"');
317         pw.println(" type=\"java:" + javaType + '"');
318         pw.println(" innerType=\"" + Utils.genQNameAttributeString(innerType, "cmp-ns") + '"');
319         pw.println(" encodingStyle=\"" + encodingStyle + "\"");
320         pw.println(" />");
321     }
322
323     /**
324      * Raw routine that writes out the typeMapping.
325      *
326      * @param pw
327      * @param namespaceURI
328      * @param localPart
329      * @param javaType
330      * @param serializerFactory
331      * @param deserializerFactory
332      * @param encodingStyle
333      * @throws IOException
334      */

335     protected void writeTypeMapping(
336             PrintWriter JavaDoc pw, String JavaDoc namespaceURI, String JavaDoc localPart, String JavaDoc javaType, String JavaDoc serializerFactory, String JavaDoc deserializerFactory, String JavaDoc encodingStyle)
337             throws IOException JavaDoc {
338
339         pw.println(" <typeMapping");
340         pw.println(" xmlns:ns=\"" + namespaceURI + "\"");
341         pw.println(" qname=\"ns:" + localPart + '"');
342         pw.println(" type=\"java:" + javaType + '"');
343         pw.println(" serializer=\"" + serializerFactory + "\"");
344         pw.println(" deserializer=\"" + deserializerFactory + "\"");
345         pw.println(" encodingStyle=\"" + encodingStyle + "\"");
346         pw.println(" />");
347     }
348
349     /**
350      * Write out deployment and undeployment instructions for given WSDL port
351      *
352      * @param pw
353      * @param port
354      * @param service
355      * @param bEntry
356      * @throws IOException
357      */

358     protected void writeDeployPort(
359             PrintWriter JavaDoc pw, Port port, Service service, BindingEntry bEntry)
360             throws IOException JavaDoc {
361
362         String JavaDoc serviceName = port.getName();
363         boolean hasLiteral = bEntry.hasLiteral();
364         boolean hasMIME = Utils.hasMIME(bEntry);
365         String JavaDoc prefix = WSDDConstants.NS_PREFIX_WSDD_JAVA;
366         String JavaDoc styleStr = "";
367         Iterator JavaDoc iterator =
368                 bEntry.getBinding().getExtensibilityElements().iterator();
369
370         while (iterator.hasNext()) {
371             Object JavaDoc obj = iterator.next();
372
373             if (obj instanceof SOAPBinding) {
374                 use = Use.ENCODED;
375             } else if (obj instanceof UnknownExtensibilityElement) {
376
377                 // TODO: After WSDL4J supports soap12, change this code
378
UnknownExtensibilityElement unkElement =
379                         (UnknownExtensibilityElement) obj;
380                 QName JavaDoc name =
381                         unkElement.getElementType();
382
383                 if (name.getNamespaceURI().equals(Constants.URI_WSDL12_SOAP)
384                         && name.getLocalPart().equals("binding")) {
385                     use = Use.ENCODED;
386                 }
387             }
388         }
389
390         if (symbolTable.isWrapped()) {
391             styleStr = " style=\"" + Style.WRAPPED + "\"";
392             use = Use.LITERAL;
393         } else {
394             styleStr = " style=\"" + bEntry.getBindingStyle().getName() + "\"";
395
396             if (hasLiteral) {
397                 use = Use.LITERAL;
398             }
399         }
400
401         String JavaDoc useStr = " use=\"" + use + "\"";
402
403         pw.println(" <service name=\"" + serviceName + "\" provider=\""
404                 + prefix + ":RPC" + "\"" + styleStr + useStr + ">");
405         pw.println(" <parameter name=\"wsdlTargetNamespace\" value=\""
406                 + service.getQName().getNamespaceURI() + "\"/>");
407         pw.println(" <parameter name=\"wsdlServiceElement\" value=\""
408                 + service.getQName().getLocalPart() + "\"/>");
409         // MIME attachments don't work with multiref, so turn it off.
410
if (hasMIME) {
411             pw.println(
412                     " <parameter name=\"sendMultiRefs\" value=\"false\"/>");
413         }
414         ArrayList JavaDoc qualified = new ArrayList JavaDoc();
415         ArrayList JavaDoc unqualified = new ArrayList JavaDoc();
416         Map JavaDoc elementFormDefaults = symbolTable.getElementFormDefaults();
417         for(Iterator JavaDoc it = elementFormDefaults.entrySet().iterator();it.hasNext();){
418             Map.Entry JavaDoc entry = (Map.Entry JavaDoc) it.next();
419             if(entry.getValue().equals("qualified")){
420                 qualified.add(entry.getKey());
421             } else {
422                 unqualified.add(entry.getKey());
423             }
424         }
425         if(qualified.size()>0){
426             pw.print(" <parameter name=\"schemaQualified\" value=\"");
427             for(int i=0;i<qualified.size();i++){
428                 pw.print(qualified.get(i));
429                 if(i != qualified.size()-1){
430                     pw.print(',');
431                 }
432             }
433             pw.println("\"/>");
434         }
435         if(unqualified.size()>0){
436             pw.print(" <parameter name=\"schemaUnqualified\" value=\"");
437             for(int i=0;i<unqualified.size();i++){
438                 pw.print(unqualified.get(i));
439                 if(i != unqualified.size()-1){
440                     pw.print(',');
441                 }
442             }
443             pw.println("\"/>");
444         }
445         pw.println(" <parameter name=\"wsdlServicePort\" value=\""
446                 + serviceName + "\"/>");
447
448         writeDeployBinding(pw, bEntry);
449         writeDeployTypes(pw, bEntry.getBinding(), hasLiteral, hasMIME, use);
450         pw.println(" </service>");
451     } // writeDeployPort
452

453     /**
454      * Write out deployment instructions for given WSDL binding
455      *
456      * @param pw
457      * @param bEntry
458      * @throws IOException
459      */

460     protected void writeDeployBinding(PrintWriter JavaDoc pw, BindingEntry bEntry)
461             throws IOException JavaDoc {
462
463         Binding binding = bEntry.getBinding();
464         String JavaDoc className = bEntry.getName();
465
466         if (emitter.isSkeletonWanted()) {
467              className += "Skeleton";
468          } else
469          {
470              String JavaDoc customClassName = emitter.getImplementationClassName();
471              if ( customClassName != null )
472                  className = customClassName;
473              else
474                  className += "Impl";
475          }
476
477         pw.println(" <parameter name=\"className\" value=\"" + className
478                 + "\"/>");
479
480         pw.println(" <parameter name=\"wsdlPortType\" value=\""
481                 + binding.getPortType().getQName().getLocalPart() + "\"/>");
482
483         pw.println(" <parameter name=\"typeMappingVersion\" value=\""
484                    + emitter.getTypeMappingVersion() + "\"/>");
485
486         HashSet JavaDoc allowedMethods = new HashSet JavaDoc();
487
488         String JavaDoc namespaceURI = binding.getQName().getNamespaceURI();
489
490         if (!emitter.isSkeletonWanted()) {
491             Iterator JavaDoc operationsIterator =
492                     binding.getBindingOperations().iterator();
493
494             for (; operationsIterator.hasNext();) {
495                 BindingOperation bindingOper =
496                         (BindingOperation) operationsIterator.next();
497                 Operation operation = bindingOper.getOperation();
498                 OperationType type = operation.getStyle();
499
500                 // These operation types are not supported. The signature
501
// will be a string stating that fact.
502
if ((OperationType.NOTIFICATION.equals(type))
503                         || (OperationType.SOLICIT_RESPONSE.equals(type))) {
504                     continue;
505                 }
506                 String JavaDoc javaOperName = null;
507
508                 ServiceDesc serviceDesc = emitter.getServiceDesc();
509                 if (emitter.isDeploy() && serviceDesc != null) {
510                     // If the emitter works in deploy mode, sync the java operation name with it of the ServiceDesc
511
OperationDesc[] operDescs = serviceDesc.getOperationsByQName(new QName JavaDoc(namespaceURI, operation.getName()));
512                     if (operDescs.length == 0) {
513                         log.warn("Can't find operation in the Java Class for WSDL binding operation : " + operation.getName());
514                         continue;
515                     }
516                     OperationDesc operDesc = operDescs[0];
517                     if (operDesc.getMethod() == null) {
518                         log.warn("Can't find Java method for operation descriptor : " + operDesc.getName());
519                         continue;
520                     }
521
522                     javaOperName = operDesc.getMethod().getName();
523                 } else {
524                     javaOperName =
525                         JavaUtils.xmlNameToJava(operation.getName());
526                 }
527
528                 allowedMethods.add(javaOperName);
529
530                 // We pass "" as the namespace argument because we're just
531
// interested in the return type for now.
532
Parameters params =
533                         symbolTable.getOperationParameters(operation, "", bEntry);
534
535                 if (params != null) {
536                     // TODO: Should really construct a FaultDesc here and
537
// TODO: pass it to writeOperation, but this will take
538
// TODO: some refactoring
539

540                     // Get the operation QName
541
QName JavaDoc elementQName = Utils.getOperationQName(bindingOper,
542                             bEntry, symbolTable);
543
544                     // Get the operation's return QName and type
545
QName JavaDoc returnQName = null;
546                     QName JavaDoc returnType = null;
547
548                     if (params.returnParam != null) {
549                         returnQName = params.returnParam.getQName();
550                         returnType = Utils.getXSIType(params.returnParam);
551                     }
552
553                     // Get the operations faults
554
Map JavaDoc faultMap = bEntry.getFaults();
555                     ArrayList JavaDoc faults = null;
556
557                     if (faultMap != null) {
558                         faults = (ArrayList JavaDoc) faultMap.get(bindingOper);
559                     }
560
561                     // Get the operation's SOAPAction
562
String JavaDoc SOAPAction = Utils.getOperationSOAPAction(bindingOper);
563
564                     // Write the operation metadata
565
writeOperation(pw, javaOperName, elementQName, returnQName,
566                             returnType, params, binding.getQName(),
567                             faults, SOAPAction);
568                 }
569             }
570         }
571
572         pw.print(" <parameter name=\"allowedMethods\" value=\"");
573
574         if (allowedMethods.isEmpty()) {
575             pw.println("*\"/>");
576         } else {
577             boolean first = true;
578
579             for (Iterator JavaDoc i = allowedMethods.iterator(); i.hasNext();) {
580                 String JavaDoc method = (String JavaDoc) i.next();
581
582                 if (first) {
583                     pw.print(method);
584
585                     first = false;
586                 } else {
587                     pw.print(" " + method);
588                 }
589             }
590
591             pw.println("\"/>");
592         }
593
594         Scope scope = emitter.getScope();
595
596         if (scope != null) {
597             pw.println(" <parameter name=\"scope\" value=\""
598                     + scope.getName() + "\"/>");
599         }
600     } // writeDeployBinding
601

602     /**
603      * Raw routine that writes out the operation and parameters.
604      *
605      * @param pw
606      * @param javaOperName
607      * @param elementQName
608      * @param returnQName
609      * @param returnType
610      * @param params
611      * @param bindingQName
612      * @param faults
613      */

614     protected void writeOperation(PrintWriter JavaDoc pw, String JavaDoc javaOperName,
615                                   QName JavaDoc elementQName, QName JavaDoc returnQName,
616                                   QName JavaDoc returnType, Parameters params,
617                                   QName JavaDoc bindingQName, ArrayList JavaDoc faults,
618                                   String JavaDoc SOAPAction) {
619
620         pw.print(" <operation name=\"" + javaOperName + "\"");
621
622         if (elementQName != null) {
623             pw.print(" qname=\""
624                     + Utils.genQNameAttributeString(elementQName, "operNS")
625                     + "\"");
626         }
627
628         if (returnQName != null) {
629             pw.print(" returnQName=\""
630                     + Utils.genQNameAttributeStringWithLastLocalPart(returnQName, "retNS")
631                     + "\"");
632         }
633
634         if (returnType != null) {
635             pw.print(" returnType=\""
636                     + Utils.genQNameAttributeString(returnType, "rtns")
637                     + "\"");
638         }
639
640         Parameter retParam = params.returnParam;
641         if (retParam != null) {
642             TypeEntry type = retParam.getType();
643             QName JavaDoc returnItemQName = Utils.getItemQName(type);
644             if (returnItemQName != null) {
645                 pw.print(" returnItemQName=\"");
646                 pw.print(Utils.genQNameAttributeString(returnItemQName, "tns"));
647                 pw.print("\"");
648             }
649             QName JavaDoc returnItemType = Utils.getItemType(type);
650             if (returnItemType != null && use == Use.ENCODED) {
651                     pw.print(" returnItemType=\"");
652                     pw.print(Utils.genQNameAttributeString(returnItemType, "tns2"));
653                     pw.print("\"");
654             }
655         }
656
657         if (SOAPAction != null) {
658             pw.print(" soapAction=\""
659                     + SOAPAction
660                     + "\"");
661         }
662
663         if (!OperationType.REQUEST_RESPONSE.equals(params.mep)) {
664             String JavaDoc mepString = getMepString(params.mep);
665             if (mepString != null) {
666                 pw.print(" mep=\""
667                          + mepString
668                          + "\"");
669             }
670         }
671
672         if ((params.returnParam != null) && params.returnParam.isOutHeader()) {
673             pw.print(" returnHeader=\"true\"");
674         }
675
676         pw.println(" >");
677
678         Vector JavaDoc paramList = params.list;
679
680         for (int i = 0; i < paramList.size(); i++) {
681             Parameter param = (Parameter) paramList.elementAt(i);
682
683             // Get the parameter name QName and type QName
684
QName JavaDoc paramQName = param.getQName();
685             QName JavaDoc paramType = Utils.getXSIType(param);
686
687             pw.print(" <parameter");
688
689             if (paramQName == null) {
690                 pw.print(" name=\"" + param.getName() + "\"");
691             } else {
692                 pw.print(" qname=\""
693                         + Utils.genQNameAttributeStringWithLastLocalPart(paramQName, "pns")
694                         + "\"");
695             }
696
697             pw.print(" type=\""
698                     + Utils.genQNameAttributeString(paramType, "tns") + "\"");
699
700             // Get the parameter mode
701
if (param.getMode() != Parameter.IN) {
702                 pw.print(" mode=\"" + getModeString(param.getMode()) + "\"");
703             }
704
705             // Is this a header?
706
if (param.isInHeader()) {
707                 pw.print(" inHeader=\"true\"");
708             }
709
710             if (param.isOutHeader()) {
711                 pw.print(" outHeader=\"true\"");
712             }
713
714             QName JavaDoc itemQName = Utils.getItemQName(param.getType());
715             if (itemQName != null) {
716                 pw.print(" itemQName=\"");
717                 pw.print(Utils.genQNameAttributeString(itemQName, "itns"));
718                 pw.print("\"");
719             }
720
721             pw.println("/>");
722         }
723
724         if (faults != null) {
725             for (Iterator JavaDoc iterator = faults.iterator(); iterator.hasNext();) {
726                 FaultInfo faultInfo = (FaultInfo) iterator.next();
727                 QName JavaDoc faultQName = faultInfo.getQName();
728
729                 if (faultQName != null) {
730                     String JavaDoc className =
731                             Utils.getFullExceptionName(faultInfo.getMessage(),
732                                     symbolTable);
733
734                     pw.print(" <fault");
735                     pw.print(" name=\"" + faultInfo.getName() + "\"");
736                     pw.print(" qname=\""
737                             + Utils.genQNameAttributeString(faultQName, "fns")
738                             + "\"");
739                     pw.print(" class=\"" + className + "\"");
740                     pw.print(
741                             " type=\""
742                             + Utils.genQNameAttributeString(
743                                     faultInfo.getXMLType(), "tns") + "\"");
744                     pw.println("/>");
745                 }
746             }
747         }
748
749         pw.println(" </operation>");
750     }
751
752     /**
753      * Method getModeString
754      *
755      * @param mode
756      * @return
757      */

758     public String JavaDoc getModeString(byte mode) {
759
760         if (mode == Parameter.IN) {
761             return "IN";
762         } else if (mode == Parameter.INOUT) {
763             return "INOUT";
764         } else {
765             return "OUT";
766         }
767     }
768
769     /**
770      * Method getPrintWriter
771      *
772      * @param filename
773      * @return
774      * @throws IOException
775      */

776     protected PrintWriter JavaDoc getPrintWriter(String JavaDoc filename) throws IOException JavaDoc {
777
778         File JavaDoc file = new File JavaDoc(filename);
779         File JavaDoc parent = new File JavaDoc(file.getParent());
780
781         parent.mkdirs();
782
783         FileOutputStream JavaDoc out = new FileOutputStream JavaDoc(file);
784         OutputStreamWriter JavaDoc writer = new OutputStreamWriter JavaDoc(out, "UTF-8");
785
786         return new PrintWriter JavaDoc(writer);
787     }
788     
789     private static final Map JavaDoc mepStrings = new HashMap JavaDoc();
790     static {
791         mepStrings.put(OperationType.REQUEST_RESPONSE.toString(), "request-response");
792         mepStrings.put(OperationType.ONE_WAY.toString(), "oneway");
793     }
794     
795     String JavaDoc getMepString(OperationType mep) {
796         return (String JavaDoc)mepStrings.get(mep.toString());
797     }
798 } // class JavaDeployWriter
799
Popular Tags