View Javadoc

1   /*
2    * Copyright 2001-2004 The Apache Software Foundation.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.apache.geronimo.ews.ws4j2ee.toWs.wsdl;
18  
19  import org.apache.axis.utils.ClassUtils;
20  import org.apache.axis.wsdl.Java2WSDL;
21  import org.apache.axis.wsdl.fromJava.Emitter;
22  import org.apache.commons.logging.Log;
23  import org.apache.commons.logging.LogFactory;
24  import org.apache.geronimo.ews.ws4j2ee.context.ContextValidator;
25  import org.apache.geronimo.ews.ws4j2ee.context.J2EEWebServiceContext;
26  import org.apache.geronimo.ews.ws4j2ee.context.impl.AxisEmitterBasedJaxRpcMapperContext;
27  import org.apache.geronimo.ews.ws4j2ee.context.wsdl.impl.AxisEmitterBasedWSDLContext;
28  import org.apache.geronimo.ews.ws4j2ee.toWs.GenerationFault;
29  import org.apache.geronimo.ews.ws4j2ee.toWs.Generator;
30  import org.apache.geronimo.ews.ws4j2ee.toWs.Ws4J2eeDeployContext;
31  import org.apache.geronimo.ews.ws4j2ee.utils.Utils;
32  
33  /***
34   * <p>This genarated theWrapper WS required in the
35   * Axis.</p>
36   *
37   * @author Srinath Perera(hemapani@opensource.lk)
38   */
39  public class WSDLGenerator extends Java2WSDL implements Generator {
40      private J2EEWebServiceContext wscontext;
41      private Ws4J2eeDeployContext clparser;
42      private Emitter emitter;
43      private String wsdlFile;
44      private boolean verbose;
45  
46      protected static Log log =
47              LogFactory.getLog(WSDLGenerator.class.getName());
48  
49      public WSDLGenerator(J2EEWebServiceContext wscontext,
50                           Emitter emitter,
51                           Ws4J2eeDeployContext clparser) throws GenerationFault {
52          this.wscontext = wscontext;
53          this.emitter = emitter;
54          this.clparser = clparser;
55          this.wsdlFile = wscontext.getMiscInfo().getWsdlFile().fileName();
56      }
57  
58      public void generate() throws GenerationFault {
59          try {
60              if (verbose)
61                  log.info("calling Java2WSDL to genarated wsdl ...........");
62              //generate the wsdl file
63              ClassUtils.setDefaultClassLoader(wscontext.getMiscInfo().getClassloader());
64              emitter.setLocationUrl("http://localhost:8080/ws/" + wscontext.getWSCFContext().getWscfport().getPortComponentName());
65              emitter.setServicePortName(wscontext.getWSCFContext().getWscfport().getWsdlPort().getLocalpart());
66              int mode = Emitter.MODE_ALL;
67              mode = clparser.getMode();
68  			
69              // Find the class using the name
70              String seiName = wscontext.getMiscInfo().getJaxrpcSEI();
71              emitter.setCls(seiName);
72              // Generate a full wsdl, or interface & implementation wsdls
73              Utils.prepareTheDir(wsdlFile);
74              if (wsdlImplFilename == null) {
75                  emitter.emit(wsdlFile, mode);
76              } else {
77                  emitter.emit(wsdlFile, wsdlImplFilename);
78              }
79  //			//initiate the wsdlContext
80              this.wscontext.setWSDLContext(new AxisEmitterBasedWSDLContext(emitter.getWSDL()));
81              //parse the ejb-jar.xml here
82              ContextValidator validator = new ContextValidator(wscontext);
83              //initiate the jaxrpcmapping context 
84              this.wscontext.setJAXRPCMappingContext(new AxisEmitterBasedJaxRpcMapperContext(emitter, wscontext));
85  //			//initiate the wscf context 
86  //			this.wscontext.setWSCFContext( new AxisEmitterBasedWSCFContext(emitter, wscontext));
87              //validate the j2ee context
88              validator.validateWithOutWSDL(emitter);
89          } catch (Exception e) {
90              log.error(e);
91              throw GenerationFault.createGenerationFault(e);
92          }
93      }
94  }