KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis2 > wsdl > codegen > CodeGenerationEngine


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.axis2.wsdl.codegen;
18
19 import org.apache.axis2.wsdl.builder.WOMBuilderFactory;
20 import org.apache.axis2.wsdl.codegen.emitter.CSharpEmitter;
21 import org.apache.axis2.wsdl.codegen.emitter.Emitter;
22 import org.apache.axis2.wsdl.codegen.emitter.JavaEmitter;
23 import org.apache.axis2.wsdl.codegen.extension.AxisBindingBuilder;
24 import org.apache.axis2.wsdl.codegen.extension.CodeGenExtension;
25 import org.apache.axis2.wsdl.codegen.extension.PackageFinder;
26 import org.apache.axis2.wsdl.codegen.extension.XMLBeansExtension;
27 import org.apache.axis2.wsdl.databinding.TypeMapper;
28 import org.apache.wsdl.WSDLDescription;
29
30 import javax.wsdl.WSDLException;
31 import java.io.File JavaDoc;
32 import java.io.FileInputStream JavaDoc;
33 import java.io.IOException JavaDoc;
34 import java.io.InputStream JavaDoc;
35 import java.util.ArrayList JavaDoc;
36 import java.util.List JavaDoc;
37
38 /**
39  * @author chathura@opensource.lk
40  *
41  */

42 public class CodeGenerationEngine {
43
44     private List JavaDoc moduleEndpoints = new ArrayList JavaDoc();
45
46     private CodeGenConfiguration configuration;
47    
48
49     public CodeGenerationEngine(CommandLineOptionParser parser) throws CodeGenerationException{
50         WSDLDescription wom ;
51         try {
52             wom = this.getWOM(parser);
53         }
54         catch (WSDLException e) {
55             throw new CodeGenerationException("Error parsing WSDL", e);
56         }
57         catch(IOException JavaDoc e1){
58             throw new CodeGenerationException("Invalid WSDL Location ", e1);
59         }
60
61         this.configuration = new CodeGenConfiguration(wom, parser);
62         AxisBindingBuilder axisBindingBuilder = new AxisBindingBuilder();
63         axisBindingBuilder.init(this.configuration);
64         axisBindingBuilder.engage();
65
66         PackageFinder packageFinder = new PackageFinder();
67         packageFinder.init(this.configuration);
68         this.moduleEndpoints.add(packageFinder);
69
70         XMLBeansExtension xmlBeanExtension = new XMLBeansExtension();
71         xmlBeanExtension.init(this.configuration);
72         this.moduleEndpoints.add(xmlBeanExtension);
73     }
74
75
76     public void generate()throws CodeGenerationException{
77
78         for(int i = 0; i< this.moduleEndpoints.size(); i++){
79             ((CodeGenExtension)this.moduleEndpoints.get(i)).engage();
80         }
81
82         Emitter emitter = null;
83         TypeMapper mapper = configuration.getTypeMapper();
84
85         switch (configuration.getOutputLanguage()){
86             case XSLTConstants.LanguageTypes.JAVA:
87                 emitter = new JavaEmitter(this.configuration,mapper);
88                 break;
89             case XSLTConstants.LanguageTypes.C_SHARP:
90                 emitter = new CSharpEmitter(this.configuration,mapper);
91                 break;
92             case XSLTConstants.LanguageTypes.C_PLUS_PLUS:
93             case XSLTConstants.LanguageTypes.VB_DOT_NET:
94
95             default:
96                 throw new UnsupportedOperationException JavaDoc();
97
98         }
99         if (this.configuration.isServerSide())
100             emitter.emitSkeleton();
101         else
102             emitter.emitStub();
103
104
105     }
106
107
108     private WSDLDescription getWOM(CommandLineOptionParser parser) throws WSDLException, IOException JavaDoc {
109         String JavaDoc uri = ((CommandLineOption) parser.getAllOptions().get(CommandLineOptionConstants.WSDL_LOCATION_URI_OPTION)).getOptionValue();
110         InputStream JavaDoc in = new FileInputStream JavaDoc(new File JavaDoc(uri));
111         return WOMBuilderFactory.getBuilder(WOMBuilderFactory.WSDL11).build(in).getDescription();
112     }
113
114
115
116 }
117
Popular Tags