KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis2 > wsdl > codegen > emitter > MultiLanguageClientEmitter


1 package org.apache.axis2.wsdl.codegen.emitter;
2
3 import org.apache.axis2.wsdl.codegen.CodeGenConfiguration;
4 import org.apache.axis2.wsdl.codegen.CodeGenerationException;
5 import org.apache.axis2.wsdl.codegen.Constants;
6 import org.apache.axis2.wsdl.codegen.extension.AxisBindingBuilder;
7 import org.apache.axis2.wsdl.codegen.writer.*;
8 import org.apache.axis2.wsdl.databinding.TypeMapper;
9 import org.apache.crimson.tree.XmlDocument;
10 import org.apache.wsdl.*;
11 import org.apache.wsdl.extensions.ExtensionConstants;
12 import org.apache.wsdl.extensions.SOAPBody;
13 import org.apache.wsdl.extensions.SOAPOperation;
14 import org.w3c.dom.Attr JavaDoc;
15 import org.w3c.dom.Element JavaDoc;
16 import org.w3c.dom.Text JavaDoc;
17
18 import java.io.ByteArrayInputStream JavaDoc;
19 import java.io.ByteArrayOutputStream JavaDoc;
20 import java.io.IOException JavaDoc;
21 import java.io.InputStream JavaDoc;
22 import java.util.Collection JavaDoc;
23 import java.util.HashMap JavaDoc;
24 import java.util.Iterator JavaDoc;
25 import java.util.Map JavaDoc;
26
27
28
29 /*
30 * Copyright 2004,2005 The Apache Software Foundation.
31 *
32 * Licensed under the Apache License, Version 2.0 (the "License");
33 * you may not use this file except in compliance with the License.
34 * You may obtain a copy of the License at
35 *
36 * http://www.apache.org/licenses/LICENSE-2.0
37 *
38 * Unless required by applicable law or agreed to in writing, software
39 * distributed under the License is distributed on an "AS IS" BASIS,
40 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
41 * See the License for the specific language governing permissions and
42 * limitations under the License.
43 *
44 * Abstract Client emitter
45 * the XML will look like the following
46 * todo escape the following
47 * <pre>
48 <interface package="">
49 <method name="">
50 <input>
51 <param name="" type=""/>*
52 </input> ?
53 <output>
54 <param name="" type=""/>?
55 </output>?
56 </method>
57 </interface>
58 </pre>
59 */

60
61
62 public abstract class MultiLanguageClientEmitter implements Emitter{
63     private static final String JavaDoc CALL_BACK_HANDLER_SUFFIX = "CallbackHandler";
64     private static final String JavaDoc STUB_SUFFIX = "Stub";
65     private static final String JavaDoc TEST_SUFFIX = "Test";
66     private static final String JavaDoc LOCAL_TEST_SUFFIX = "LocalTest";
67     private static final String JavaDoc SERVICE_CLASS_SUFFIX ="Skeleton";
68     private static final String JavaDoc TEST_PACKAGE_NAME_SUFFIX =".test";
69     private static final String JavaDoc DATABINDING_SUPPORTER_NAME_SUFFIX ="DatabindingSupporter";
70     private static final String JavaDoc DATABINDING_PACKAGE_NAME_SUFFIX =".databinding";
71     private static final String JavaDoc TEST_SERVICE_CLASS_NAME_SUFFIX ="SkeletonTest";
72     private static final String JavaDoc MESSAGE_RECEIVER_SUFFIX = "MessageReceiver";
73
74
75     protected InputStream JavaDoc xsltStream = null;
76     protected CodeGenConfiguration configuration;
77     protected TypeMapper mapper;
78
79     /**
80      * Sets the mapper
81      * @see org.apache.axis2.wsdl.databinding.TypeMapper
82      * @param mapper
83      */

84     public void setMapper(TypeMapper mapper) {
85         this.mapper = mapper;
86     }
87
88     /**
89      * Sets the code generator configuration
90      * @param configuration
91      */

92     public void setCodeGenConfiguration(CodeGenConfiguration configuration) {
93         this.configuration = configuration;
94     }
95
96     /**
97      *
98      * @see org.apache.axis2.wsdl.codegen.emitter.Emitter#emitStub()
99      */

100     public void emitStub() throws CodeGenerationException {
101         try {
102             //get the binding
103
WSDLDescription wom = this.configuration.getWom();
104             WSDLBinding axisBinding = wom.getBinding(AxisBindingBuilder.AXIS_BINDING_QNAME);
105             WSDLService axisService = null;
106             //write interfaces
107
Map JavaDoc services = wom.getServices();
108             if (!services.isEmpty()) {
109                 if (services.size()==1){
110                     axisService = (WSDLService)services.values().toArray()[0];
111                 }else{
112                     throw new UnsupportedOperationException JavaDoc("Single service WSDL files only");
113                 }
114             }
115             //
116
testCompatibiltyAll(axisBinding);
117             //
118
writeInterface(axisBinding);
119             //write interface implementations
120
writeInterfaceImplementation(axisBinding,axisService);
121             //write the call back handlers
122
writeCallBackHandlers(axisBinding);
123             //write the test classes
124
// writeTestClasses(axisBinding);
125
//write the databinding supporters
126
writeDatabindingSupporters(axisBinding);
127             //write a dummy implementation call for the tests to run.
128
//writeTestSkeletonImpl(axisBinding);
129
//write a testservice.xml that will load the dummy skeleton impl for testing
130
//writeTestServiceXML(axisBinding);
131
} catch (Exception JavaDoc e) {
132             e.printStackTrace();
133             throw new CodeGenerationException(e);
134         }
135     }
136
137
138     protected void writeTestSkeletonImpl(WSDLBinding binding)throws Exception JavaDoc{
139         if (configuration.isWriteTestCase()){
140             XmlDocument classModel = createDocumentForTestSkeletonImpl(binding);
141             TestSkeletonImplWriter callbackWriter =
142                     new TestSkeletonImplWriter(this.configuration.getOutputLocation(),
143                             this.configuration.getOutputLanguage()
144                     );
145             writeClass(classModel,callbackWriter);
146         }
147     }
148
149     /**
150      *
151      */

152     protected void writeCallBackHandlers(WSDLBinding binding) throws Exception JavaDoc{
153
154         if (configuration.isAsyncOn()){
155             XmlDocument interfaceModel = createDOMDocumentForCallbackHandler(binding);
156             CallbackHandlerWriter callbackWriter =
157                     new CallbackHandlerWriter(this.configuration.getOutputLocation(),
158                             this.configuration.getOutputLanguage()
159                     );
160             writeClass(interfaceModel,callbackWriter);
161         }
162
163     }
164
165     /**
166      * Write the local test classes. these test classes are different from the
167      * usual test classes because it is meant to work with the generated test
168      * skeleton class.
169      * @param binding
170      * @throws Exception
171      */

172     protected void writeLocalTestClasses(WSDLBinding binding) throws Exception JavaDoc{
173
174         if (configuration.isWriteTestCase()){
175             XmlDocument classModel = createDOMDocuementForLocalTestCase(binding);
176             LocalTestClassWriter callbackWriter =
177                     new LocalTestClassWriter(this.configuration.getOutputLocation(),
178                             this.configuration.getOutputLanguage()
179                     );
180             writeClass(classModel,callbackWriter);
181         }
182     }
183     /**
184      *
185      */

186     protected void writeTestClasses(WSDLBinding binding) throws Exception JavaDoc{
187
188         if (configuration.isWriteTestCase()){
189             XmlDocument classModel = createDOMDocuementForTestCase(binding);
190             TestClassWriter callbackWriter =
191                     new TestClassWriter(this.configuration.getOutputLocation(),
192                             this.configuration.getOutputLanguage()
193                     );
194             writeClass(classModel,callbackWriter);
195         }
196
197     }
198     /**
199      * Writes the interfaces
200      * @param axisBinding
201      * @throws Exception
202      */

203     protected void writeInterface(WSDLBinding axisBinding) throws Exception JavaDoc {
204         XmlDocument interfaceModel = createDOMDocuementForInterface(axisBinding);
205         InterfaceWriter interfaceWriter =
206                 new InterfaceWriter(this.configuration.getOutputLocation(),
207                         this.configuration.getOutputLanguage()
208                 );
209         writeClass(interfaceModel,interfaceWriter);
210     }
211
212     /**
213      * Writes the skeleton
214      * @param axisBinding
215      * @throws Exception
216      */

217     protected void writeSkeleton(WSDLBinding axisBinding) throws Exception JavaDoc {
218
219         //Note - One can generate the skeleton using the interface XML
220
XmlDocument skeletonModel = createDOMDocuementForSkeleton(axisBinding);
221         ClassWriter skeletonWriter = new SkeletonWriter(this.configuration.getOutputLocation(),
222                 this.configuration.getOutputLanguage()
223         );
224         writeClass(skeletonModel,skeletonWriter);
225
226
227     }
228
229     /**
230      * Writes the skeleton
231      * @param axisBinding
232      * @throws Exception
233      */

234     protected void writeDatabindingSupporters(WSDLBinding axisBinding) throws Exception JavaDoc {
235         Collection JavaDoc col = axisBinding.getBoundInterface().getOperations().values();
236         for (Iterator JavaDoc iterator = col.iterator(); iterator.hasNext();) {
237             //Note - there will be a supporter generated per method and will contain the methods to serilize and
238
//deserilize the relevant objects
239
XmlDocument databindingSupporterModel = createDOMDocumentforSerialization((WSDLOperation)iterator.next());
240             ClassWriter databindingSupportWriter = new DatabindingSupportClassWriter(this.configuration.getOutputLocation(),
241                     this.configuration.getOutputLanguage(),this.configuration.getDatabindingType()
242             );
243             writeClass(databindingSupporterModel,databindingSupportWriter);
244         }
245
246     }
247
248     protected void writeTestServiceXML(WSDLBinding axisBinding) throws Exception JavaDoc {
249         if (this.configuration.isWriteTestCase()){
250             //Note - One can generate the service xml using the interface XML
251
XmlDocument skeletonModel = createDOMDocuementForServiceXML(axisBinding, true);
252             TestServiceXMLWriter testServiceXmlWriter = new TestServiceXMLWriter(this.configuration.getOutputLocation(),
253                     this.configuration.getOutputLanguage()
254             );
255             writeClass(skeletonModel,testServiceXmlWriter);
256         }
257     }
258
259     /**
260      * Writes the skeleton
261      * @param axisBinding
262      * @throws Exception
263      */

264     protected void writeServiceXml(WSDLBinding axisBinding) throws Exception JavaDoc {
265         if (this.configuration.isGenerateDeployementDescriptor()){
266             XmlDocument skeletonModel = createDOMDocuementForServiceXML(axisBinding, false);
267             ClassWriter serviceXmlWriter = new ServiceXMLWriter(this.configuration.getOutputLocation(),
268                     this.configuration.getOutputLanguage()
269             );
270             writeClass(skeletonModel,serviceXmlWriter);
271         }
272     }
273
274
275     /**
276      * Writes the implementations
277      * @param axisBinding
278      * @throws Exception
279      */

280     protected void writeInterfaceImplementation(WSDLBinding axisBinding,WSDLService service) throws Exception JavaDoc {
281         XmlDocument interfaceImplModel = createDOMDocuementForInterfaceImplementation(axisBinding, service);
282         InterfaceImplementationWriter writer =
283                 new InterfaceImplementationWriter(this.configuration.getOutputLocation(),
284                         this.configuration.getOutputLanguage()
285                 );
286         writeClass(interfaceImplModel,writer);
287     }
288
289     protected void writeMessageReceiver(WSDLBinding axisBinding)throws Exception JavaDoc{
290         if (configuration.isWriteMessageReceiver()){
291             XmlDocument classModel = createDocumentForMessageReceiver(axisBinding);
292             MessageReceiverWriter writer =
293                     new MessageReceiverWriter(this.configuration.getOutputLocation(),
294                             this.configuration.getOutputLanguage()
295                     );
296             writeClass(classModel,writer);
297         }
298     }
299
300     /**
301      * todo Not used yet
302      * @param wsdlType
303      * @throws Exception
304      */

305     protected void writeBeans(WSDLTypes wsdlType) throws Exception JavaDoc {
306         Collection JavaDoc collection= wsdlType.getExtensibilityElements();
307         if (collection != null){
308             for (Iterator JavaDoc iterator = collection.iterator(); iterator.hasNext();) {
309                 XmlDocument interfaceModel = createDOMDocuementForBean();
310                 BeanWriter beanWriter =
311                         new BeanWriter(this.configuration.getOutputLocation(),
312                                 this.configuration.getOutputLanguage()
313                         );
314                 writeClass(interfaceModel,beanWriter);
315             }
316         }
317
318     }
319     /**
320      * A resusable method for the implementation of interface and implementation writing
321      * @param model
322      * @param writer
323      * @throws IOException
324      * @throws Exception
325      */

326     protected void writeClass(XmlDocument model,ClassWriter writer) throws IOException JavaDoc,Exception JavaDoc {
327         ByteArrayOutputStream JavaDoc memoryStream = new ByteArrayOutputStream JavaDoc();
328         model.write(memoryStream);
329         writer.loadTemplate();
330         writer.createOutFile(model.getDocumentElement().getAttribute("package"),
331                 model.getDocumentElement().getAttribute("name"));
332         writer.writeOutFile(new ByteArrayInputStream JavaDoc(memoryStream.toByteArray()));
333     }
334
335     /**
336      * @see org.apache.axis2.wsdl.codegen.emitter.Emitter#emitSkeleton()
337      */

338     public void emitSkeleton() throws CodeGenerationException {
339         try {
340             //get the binding
341
WSDLBinding axisBinding = this.configuration.getWom().getBinding(AxisBindingBuilder.AXIS_BINDING_QNAME);
342             //
343
testCompatibiltyAll(axisBinding);
344             //write interfaces
345
writeSkeleton(axisBinding);
346             //write interface implementations
347
writeServiceXml(axisBinding);
348             //write the local test classes
349
// writeLocalTestClasses(axisBinding);
350
//write a dummy implementation call for the tests to run.
351
writeTestSkeletonImpl(axisBinding);
352             //write a testservice.xml that will load the dummy skeleton impl for testing
353
writeTestServiceXML(axisBinding);
354             //write a MessageReceiver for this particular service.
355
writeMessageReceiver(axisBinding);
356             //////////////////////////////////////
357
// Call the emit stub method to generate the client side too
358
emitStub();
359
360         } catch (Exception JavaDoc e) {
361             e.printStackTrace();
362             throw new CodeGenerationException(e);
363         }
364     }
365
366     protected XmlDocument createDocumentForTestSkeletonImpl(WSDLBinding binding){
367         WSDLInterface boundInterface = binding.getBoundInterface();
368
369         XmlDocument doc = new XmlDocument();
370         Element JavaDoc rootElement = doc.createElement("class");
371         addAttribute(doc,"package",configuration.getPackageName()+TEST_PACKAGE_NAME_SUFFIX, rootElement);
372         addAttribute(doc,"servicename",boundInterface.getName().getLocalPart()+SERVICE_CLASS_SUFFIX,rootElement);
373         addAttribute(doc, "implpackage", configuration.getPackageName(), rootElement);
374         addAttribute(doc,"name",boundInterface.getName().getLocalPart()+TEST_SERVICE_CLASS_NAME_SUFFIX,rootElement);
375         addAttribute(doc, "namespace", boundInterface.getName().getNamespaceURI(), rootElement);
376         fillSyncAttributes(doc, rootElement);
377         loadOperations(boundInterface, doc, rootElement);
378         doc.appendChild(rootElement);
379         return doc;
380     }
381
382     /**
383      * Generating the callbacks
384      * @param binding
385      * @return
386      */

387     protected XmlDocument createDOMDocumentForCallbackHandler(WSDLBinding binding){
388         WSDLInterface boundInterface = binding.getBoundInterface();
389         XmlDocument doc = new XmlDocument();
390         Element JavaDoc rootElement = doc.createElement("callback");
391         addAttribute(doc,"package",configuration.getPackageName(),rootElement);
392         addAttribute(doc,"name",boundInterface.getName().getLocalPart()+CALL_BACK_HANDLER_SUFFIX,rootElement);
393         addAttribute(doc,"namespace",boundInterface.getName().getNamespaceURI(),rootElement);
394
395         //TODO JAXRPC mapping support should be considered
396
this.loadOperations(boundInterface, doc, rootElement);
397         //this.loadOperations(boundInterface, doc, rootElement, "on", "Complete");
398

399         doc.appendChild(rootElement);
400         return doc;
401     }
402
403     /**
404      * Finds the input element for the xml document
405      * @param doc
406      * @param operation
407      * @return
408      */

409     protected Element JavaDoc getInputElement(XmlDocument doc,WSDLOperation operation){
410         Element JavaDoc inputElt = doc.createElement("input");
411         Element JavaDoc param = getInputParamElement(doc, operation);
412         inputElt.appendChild(param);
413         return inputElt;
414     }
415
416     private Element JavaDoc getInputParamElement(XmlDocument doc, WSDLOperation operation) {
417         //todo this should go in a loop
418
Element JavaDoc param = doc.createElement("param");
419         MessageReference inputMessage = operation.getInputMessage();
420         addAttribute(doc,"name",this.mapper.getParameterName(inputMessage.getElement()),param);
421         String JavaDoc typeMapping = this.mapper.getTypeMapping(inputMessage.getElement());
422         String JavaDoc typeMappingStr =typeMapping==null?"":typeMapping;
423         addAttribute(doc,"type",typeMappingStr,param);
424         return param;
425     }
426
427     /**
428      * Finds the output element for the output element
429      * @param doc
430      * @param operation
431      * @return
432      */

433     protected Element JavaDoc getOutputElement(XmlDocument doc,WSDLOperation operation){
434         Element JavaDoc outputElt = doc.createElement("output");
435         Element JavaDoc param = getOutputParamElement(doc, operation);
436         outputElt.appendChild(param);
437         return outputElt;
438     }
439
440     private Element JavaDoc getOutputParamElement(XmlDocument doc, WSDLOperation operation) {
441         Element JavaDoc param = doc.createElement("param");
442         addAttribute(doc,"name",this.mapper.getParameterName(operation.getOutputMessage().getElement()),param);
443
444         String JavaDoc typeMapping = this.mapper.getTypeMapping(operation.getOutputMessage().getElement());
445         String JavaDoc typeMappingStr=typeMapping==null?"":typeMapping;
446         addAttribute(doc,"type",typeMappingStr,param);
447         return param;
448     }
449
450     /**
451      * Todo Finish this
452      * @return
453      */

454     protected XmlDocument createDOMDocuementForBean(){
455         return null;
456     }
457
458     protected XmlDocument createDOMDocuementForServiceXML(WSDLBinding binding, boolean forTesting) {
459         WSDLInterface boundInterface = binding.getBoundInterface();
460
461         XmlDocument doc = new XmlDocument();
462         Element JavaDoc rootElement = doc.createElement("interface");
463         String JavaDoc localPart = boundInterface.getName().getLocalPart();
464         if(forTesting){
465             addAttribute(doc,"package",configuration.getPackageName()+TEST_PACKAGE_NAME_SUFFIX, rootElement);
466             addAttribute(doc,"name",localPart+TEST_SERVICE_CLASS_NAME_SUFFIX,rootElement);
467             addAttribute(doc,"servicename",localPart+TEST_SERVICE_CLASS_NAME_SUFFIX,rootElement);
468         }else{
469             addAttribute(doc,"package",configuration.getPackageName(), rootElement);
470             addAttribute(doc,"name",localPart+SERVICE_CLASS_SUFFIX,rootElement);
471             addAttribute(doc,"servicename",localPart,rootElement);
472         }
473         
474         addAttribute(doc,"messagereceiver",localPart+MESSAGE_RECEIVER_SUFFIX,rootElement);
475         fillSyncAttributes(doc, rootElement);
476         loadOperations(boundInterface, doc, rootElement);
477         doc.appendChild(rootElement);
478
479         return doc;
480     }
481
482
483     protected XmlDocument createDocumentForMessageReceiver(WSDLBinding binding){
484         WSDLInterface boundInterface = binding.getBoundInterface();
485
486         XmlDocument doc = new XmlDocument();
487         Element JavaDoc rootElement = doc.createElement("interface");
488         addAttribute(doc,"package",configuration.getPackageName(), rootElement);
489         String JavaDoc localPart = boundInterface.getName().getLocalPart();
490         addAttribute(doc,"name",localPart+MESSAGE_RECEIVER_SUFFIX,rootElement);
491         addAttribute(doc,"skeletonname",localPart + SERVICE_CLASS_SUFFIX,rootElement);
492         addAttribute(doc, "basereceiver", "org.apache.axis2.receivers.AbstractInOutSyncMessageReceiver", rootElement);
493         addAttribute(doc,"dbsupportpackage",configuration.getPackageName()+DATABINDING_PACKAGE_NAME_SUFFIX,rootElement);
494         fillSyncAttributes(doc, rootElement);
495         loadOperations(boundInterface, doc, rootElement, binding);
496         doc.appendChild(rootElement);
497
498
499         return doc;
500     }
501     /**
502      * Creates the DOM tree for the interface creation
503      * @param binding
504      * @return
505      */

506     protected XmlDocument createDOMDocuementForInterface(WSDLBinding binding){
507         WSDLInterface boundInterface = binding.getBoundInterface();
508
509         XmlDocument doc = new XmlDocument();
510         Element JavaDoc rootElement = doc.createElement("interface");
511         addAttribute(doc,"package",configuration.getPackageName(), rootElement);
512         addAttribute(doc,"name",boundInterface.getName().getLocalPart(),rootElement);
513         addAttribute(doc,"callbackname",boundInterface.getName().getLocalPart() + CALL_BACK_HANDLER_SUFFIX,rootElement);
514         fillSyncAttributes(doc, rootElement);
515         loadOperations(boundInterface, doc, rootElement);
516         doc.appendChild(rootElement);
517         return doc;
518
519     }
520
521     protected XmlDocument createDOMDocuementForSkeleton(WSDLBinding binding){
522         WSDLInterface boundInterface = binding.getBoundInterface();
523
524         XmlDocument doc = new XmlDocument();
525         Element JavaDoc rootElement = doc.createElement("interface");
526         addAttribute(doc,"package",configuration.getPackageName(), rootElement);
527         addAttribute(doc,"name",boundInterface.getName().getLocalPart()+SERVICE_CLASS_SUFFIX,rootElement);
528         addAttribute(doc,"callbackname",boundInterface.getName().getLocalPart() + CALL_BACK_HANDLER_SUFFIX,rootElement);
529         fillSyncAttributes(doc, rootElement);
530         loadOperations(boundInterface, doc, rootElement);
531         doc.appendChild(rootElement);
532         return doc;
533
534     }
535     private void fillSyncAttributes(XmlDocument doc, Element JavaDoc rootElement) {
536         addAttribute(doc,"isAsync",this.configuration.isAsyncOn()?"1":"0",rootElement);
537         addAttribute(doc,"isSync",this.configuration.isSyncOn()?"1":"0",rootElement);
538     }
539
540     private void loadOperations(WSDLInterface boundInterface, XmlDocument doc, Element JavaDoc rootElement){
541         loadOperations(boundInterface, doc, rootElement, null);
542     }
543
544     private void loadOperations(WSDLInterface boundInterface, XmlDocument doc, Element JavaDoc rootElement,WSDLBinding binding) {
545         Collection JavaDoc col = boundInterface.getOperations().values();
546         Element JavaDoc methodElement = null;
547         WSDLOperation operation = null;
548
549         for (Iterator JavaDoc iterator = col.iterator(); iterator.hasNext();) {
550             operation = (WSDLOperation) iterator.next();
551             methodElement = doc.createElement("method");
552             String JavaDoc localPart = operation.getName().getLocalPart();
553             addAttribute(doc,"name",localPart,methodElement);
554             addAttribute(doc,"namespace",operation.getName().getNamespaceURI(),methodElement);
555             addAttribute(doc,"style",operation.getStyle(),methodElement);
556             addAttribute(doc,"dbsupportname",localPart+DATABINDING_SUPPORTER_NAME_SUFFIX,methodElement);
557             if(null != binding){
558                 WSDLBindingOperation bindingOperation = binding.getBindingOperation(operation.getName());
559                 addSOAPAction(doc,methodElement,bindingOperation);
560                 testCompatibilityInput(bindingOperation);
561                 testCompatibilityOutput(bindingOperation);
562             }
563             addAttribute(doc,"mep",operation.getMessageExchangePattern(), methodElement);
564             methodElement.appendChild(getInputElement(doc,operation));
565             methodElement.appendChild(getOutputElement(doc,operation));
566             rootElement.appendChild(methodElement);
567         }
568     }
569
570
571     private void addSOAPAction(XmlDocument doc,Element JavaDoc rootElement,WSDLBindingOperation binding){
572         Iterator JavaDoc extIterator = binding.getExtensibilityElements().iterator();
573         boolean actionAdded = false;
574         while(extIterator.hasNext()){
575             WSDLExtensibilityElement element = (WSDLExtensibilityElement)extIterator.next();
576             if(element.getType().equals(ExtensionConstants.SOAP_OPERATION)){
577                 addAttribute(doc,"soapaction", ((SOAPOperation)element).getSoapAction(),rootElement);
578                 actionAdded = true ;
579             }
580         }
581
582         if (!actionAdded){
583             addAttribute(doc,"soapaction", "",rootElement);
584         }
585     }
586
587     protected XmlDocument createDOMDocuementForTestCase(WSDLBinding binding) {
588         WSDLInterface boundInterface = binding.getBoundInterface();
589
590         XmlDocument doc = new XmlDocument();
591         Element JavaDoc rootElement = doc.createElement("class");
592         addAttribute(doc,"package",configuration.getPackageName(),rootElement);
593         String JavaDoc localPart = boundInterface.getName().getLocalPart();
594         addAttribute(doc,"name",localPart+TEST_SUFFIX,rootElement);
595         addAttribute(doc,"namespace",boundInterface.getName().getNamespaceURI(),rootElement);
596         addAttribute(doc,"interfaceName",localPart,rootElement);
597         addAttribute(doc,"callbackname",localPart + CALL_BACK_HANDLER_SUFFIX,rootElement);
598         addAttribute(doc,"stubname",localPart + STUB_SUFFIX,rootElement);
599         addAttribute(doc,"dbsupportpackage",configuration.getPackageName()+DATABINDING_PACKAGE_NAME_SUFFIX,rootElement);
600         fillSyncAttributes(doc, rootElement);
601         loadOperations(boundInterface, doc, rootElement);
602         doc.appendChild(rootElement);
603         return doc;
604
605     }
606
607     protected XmlDocument createDOMDocuementForLocalTestCase(WSDLBinding binding) {
608         WSDLInterface boundInterface = binding.getBoundInterface();
609
610         XmlDocument doc = new XmlDocument();
611         Element JavaDoc rootElement = doc.createElement("class");
612         String JavaDoc serviceXMLPath = configuration.getPackageName().replace('.','/')+TEST_PACKAGE_NAME_SUFFIX.replace('.','/')+"/testservice.xml";
613         addAttribute(doc,"package",configuration.getPackageName()+TEST_PACKAGE_NAME_SUFFIX,rootElement);
614         addAttribute(doc, "servicexmlpath", serviceXMLPath, rootElement);
615         addAttribute(doc, "implpackage", configuration.getPackageName(), rootElement);
616         String JavaDoc localPart = boundInterface.getName().getLocalPart();
617         addAttribute(doc,"name",localPart+LOCAL_TEST_SUFFIX,rootElement);
618         addAttribute(doc,"namespace",boundInterface.getName().getNamespaceURI(),rootElement);
619         addAttribute(doc,"interfaceName",localPart,rootElement);
620         addAttribute(doc,"callbackname",localPart + CALL_BACK_HANDLER_SUFFIX,rootElement);
621         addAttribute(doc,"stubname",localPart + STUB_SUFFIX,rootElement);
622         addAttribute(doc, "address", "http://localhost:"+Constants.TEST_PORT+"/services/"+boundInterface.getName().getLocalPart()+TEST_SERVICE_CLASS_NAME_SUFFIX, rootElement);
623         fillSyncAttributes(doc, rootElement);
624         loadOperations(boundInterface, doc, rootElement);
625         doc.appendChild(rootElement);
626         return doc;
627
628     }
629
630     protected XmlDocument createDOMDocumentforSerialization(WSDLOperation operation){
631         XmlDocument doc = new XmlDocument();
632         Element JavaDoc rootElement = doc.createElement("class");
633         addAttribute(doc,"package",configuration.getPackageName()+DATABINDING_PACKAGE_NAME_SUFFIX,rootElement);
634         String JavaDoc localPart =operation.getName().getLocalPart();
635         addAttribute(doc,"name",localPart+DATABINDING_SUPPORTER_NAME_SUFFIX,rootElement);
636         addAttribute(doc,"methodname",localPart,rootElement);
637         addAttribute(doc,"namespace",operation.getName().getNamespaceURI(),rootElement);
638         rootElement.appendChild(getInputParamElement(doc,operation));
639         rootElement.appendChild(getOutputParamElement(doc,operation));
640         doc.appendChild(rootElement);
641         return doc;
642     }
643
644     /**
645      * Creates the DOM tree for implementations
646      * @param binding
647      * @param service
648      * @return
649      */

650     protected XmlDocument createDOMDocuementForInterfaceImplementation(WSDLBinding binding, WSDLService service) {
651         WSDLInterface boundInterface = binding.getBoundInterface();
652
653         WSDLEndpoint endpoint = null;
654         HashMap JavaDoc endpoints = service.getEndpoints();
655         XmlDocument doc = new XmlDocument();
656         Element JavaDoc rootElement = doc.createElement("class");
657         addAttribute(doc,"package",configuration.getPackageName(),rootElement);
658         String JavaDoc localPart = boundInterface.getName().getLocalPart();
659         addAttribute(doc,"name",localPart+STUB_SUFFIX,rootElement);
660         addAttribute(doc,"servicename",localPart,rootElement);
661         addAttribute(doc,"namespace",boundInterface.getName().getNamespaceURI(),rootElement);
662         addAttribute(doc,"interfaceName",localPart,rootElement);
663         addAttribute(doc,"callbackname",localPart + CALL_BACK_HANDLER_SUFFIX,rootElement);
664         addAttribute(doc,"dbsupportpackage",configuration.getPackageName()+DATABINDING_PACKAGE_NAME_SUFFIX,rootElement);
665         addEndpoints(doc,rootElement,endpoints);
666         fillSyncAttributes(doc, rootElement);
667         loadOperations(boundInterface, doc, rootElement,binding);
668         doc.appendChild(rootElement);
669
670
671
672         return doc;
673
674     }
675
676     protected void addEndpoints(XmlDocument doc,Element JavaDoc rootElement,HashMap JavaDoc endpointMap){
677         Object JavaDoc[] endpoints = endpointMap.values().toArray();
678         WSDLEndpoint endpoint;
679         Element JavaDoc endpointElement;
680         Text JavaDoc text;
681         for (int i = 0; i < endpoints.length; i++) {
682             endpoint = (WSDLEndpoint)endpoints[i];
683             endpointElement = doc.createElement("endpoint");
684             org.apache.wsdl.extensions.SOAPAddress address = null;
685             Iterator JavaDoc iterator = endpoint.getExtensibilityElements().iterator();
686             while(iterator.hasNext()) {
687                 WSDLExtensibilityElement element = (WSDLExtensibilityElement)iterator.next();
688                 if (element.getType().equals(ExtensionConstants.SOAP_ADDRESS)){
689                     address = (org.apache.wsdl.extensions.SOAPAddress)element;
690                 }
691             }
692             text = doc.createTextNode(address.getLocationURI()); //todo How to get the end point address
693
endpointElement.appendChild(text);
694             rootElement.appendChild(endpointElement);
695         }
696
697     }
698
699     protected void addAttribute(XmlDocument document,String JavaDoc AttribName, String JavaDoc attribValue, Element JavaDoc element){
700         Attr JavaDoc attribute = document.createAttribute(AttribName);
701         attribute.setValue(attribValue);
702         element.setAttributeNode(attribute);
703     }
704
705     protected String JavaDoc removeUnsuitableCharacters(String JavaDoc word){
706         return word.replaceAll("\\W","_");
707     }
708
709     private void testCompatibiltyAll(WSDLBinding binding){
710         HashMap JavaDoc map = binding.getBindingOperations();
711         WSDLBindingOperation bindingOp;
712         Collection JavaDoc col = map.values();
713         for (Iterator JavaDoc iterator = col.iterator(); iterator.hasNext();) {
714             bindingOp = (WSDLBindingOperation)iterator.next();
715             testCompatibilityInput(bindingOp);
716             testCompatibilityOutput(bindingOp);
717         }
718
719
720     }
721     private void testCompatibilityInput(WSDLBindingOperation binding){
722
723         Iterator JavaDoc extIterator = binding.getInput().getExtensibilityElements().iterator();
724         while(extIterator.hasNext()){
725             WSDLExtensibilityElement element = (WSDLExtensibilityElement)extIterator.next();
726             if(element.getType().equals(ExtensionConstants.SOAP_BODY)){
727                 if(WSDLConstants.WSDL_USE_ENCODED.equals(((SOAPBody)element).getUse())){
728                     throw new RuntimeException JavaDoc("The use 'encoded' is not supported!");
729                 }
730             }
731         }
732     }
733
734     private void testCompatibilityOutput(WSDLBindingOperation binding){
735
736         Iterator JavaDoc extIterator = binding.getOutput().getExtensibilityElements().iterator();
737         while(extIterator.hasNext()){
738             WSDLExtensibilityElement element = (WSDLExtensibilityElement)extIterator.next();
739             if(element.getType().equals(ExtensionConstants.SOAP_BODY)){
740                 if(WSDLConstants.WSDL_USE_ENCODED.equals(((SOAPBody)element).getUse())){
741                     throw new RuntimeException JavaDoc("The use 'encoded' is not supported!");
742                 }
743             }
744         }
745     }
746 }
747
748
Popular Tags