KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis2 > tool > ant > AntCodegenTask


1 package org.apache.axis2.tool.ant;
2
3 import java.io.File JavaDoc;
4 import java.io.FileInputStream JavaDoc;
5 import java.io.FileNotFoundException JavaDoc;
6 import java.io.FileOutputStream JavaDoc;
7 import java.io.FileWriter JavaDoc;
8 import java.io.IOException JavaDoc;
9 import java.io.InputStream JavaDoc;
10 import java.io.PrintStream JavaDoc;
11 import java.util.HashMap JavaDoc;
12 import java.util.Map JavaDoc;
13
14 import javax.wsdl.WSDLException;
15
16 import org.apache.axis2.wsdl.WSDLVersionWrapper;
17 import org.apache.axis2.wsdl.builder.WOMBuilderFactory;
18 import org.apache.axis2.wsdl.codegen.CodeGenConfiguration;
19 import org.apache.axis2.wsdl.codegen.CodeGenerationEngine;
20 import org.apache.axis2.wsdl.codegen.CommandLineOption;
21 import org.apache.axis2.wsdl.codegen.CommandLineOptionConstants;
22 import org.apache.axis2.wsdl.codegen.CommandLineOptionParser;
23 import org.apache.axis2.wsdl.util.URLProcessor;
24 import org.apache.tools.ant.BuildException;
25 import org.apache.tools.ant.Task;
26 import org.apache.wsdl.WSDLDescription;
27
28 /*
29 * Copyright 2004,2005 The Apache Software Foundation.
30 *
31 * Licensed under the Apache License, Version 2.0 (the "License");
32 * you may not use this file except in compliance with the License.
33 * You may obtain a copy of the License at
34 *
35 * http://www.apache.org/licenses/LICENSE-2.0
36 *
37 * Unless required by applicable law or agreed to in writing, software
38 * distributed under the License is distributed on an "AS IS" BASIS,
39 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
40 * See the License for the specific language governing permissions and
41 * limitations under the License.
42 *
43 *
44 */

45 public class AntCodegenTask extends Task{
46
47     private String JavaDoc WSDLFileName=null;
48     private String JavaDoc output=".";
49     private String JavaDoc packageName=URLProcessor.DEFAULT_PACKAGE;
50     private String JavaDoc language=CommandLineOptionConstants.LanguageNames.JAVA;
51
52     private boolean asyncOnly=false;
53     private boolean syncOnly=false;
54     private boolean serverSide=false;
55     private boolean testcase=false;
56     private boolean generateServerXml=false;
57
58     /**
59      *
60      */

61     private Map JavaDoc fillOptionMap() {
62         Map JavaDoc optionMap = new HashMap JavaDoc();
63
64         optionMap.put(CommandLineOptionConstants.WSDL_LOCATION_URI_OPTION,
65                 new CommandLineOption(
66                         CommandLineOptionConstants.WSDL_LOCATION_URI_OPTION,
67                         getStringArray(WSDLFileName)));
68
69         if (asyncOnly) {
70             optionMap
71                     .put(
72                             CommandLineOptionConstants.CODEGEN_ASYNC_ONLY_OPTION,
73                             new CommandLineOption(
74                                     CommandLineOptionConstants.CODEGEN_ASYNC_ONLY_OPTION,
75                                     new String JavaDoc[0]));
76         }
77         if (syncOnly) {
78             optionMap
79                     .put(
80                             CommandLineOptionConstants.CODEGEN_SYNC_ONLY_OPTION,
81                             new CommandLineOption(
82                                     CommandLineOptionConstants.CODEGEN_SYNC_ONLY_OPTION,
83                                     new String JavaDoc[0]));
84         }
85         optionMap.put(CommandLineOptionConstants.PACKAGE_OPTION,
86                 new CommandLineOption(
87                         CommandLineOptionConstants.PACKAGE_OPTION,
88                         getStringArray(packageName)));
89         optionMap.put(CommandLineOptionConstants.STUB_LANGUAGE_OPTION,
90                 new CommandLineOption(
91                         CommandLineOptionConstants.STUB_LANGUAGE_OPTION,
92                         getStringArray(language)));
93         optionMap.put(CommandLineOptionConstants.OUTPUT_LOCATION_OPTION,
94                 new CommandLineOption(
95                         CommandLineOptionConstants.OUTPUT_LOCATION_OPTION,
96                         getStringArray(output)));
97         if (serverSide) {
98             optionMap.put(CommandLineOptionConstants.SERVER_SIDE_CODE_OPTION,
99                     new CommandLineOption(
100                             CommandLineOptionConstants.SERVER_SIDE_CODE_OPTION,
101                             new String JavaDoc[0]));
102
103             if (generateServerXml) {
104                 optionMap.put(
105                         CommandLineOptionConstants.GENERATE_SERVICE_DESCRIPTION_OPTION,
106                         new CommandLineOption(
107                                 CommandLineOptionConstants.GENERATE_SERVICE_DESCRIPTION_OPTION,
108                                 new String JavaDoc[0]));
109             }
110         }
111         if (testcase){
112             optionMap
113                     .put(
114                             CommandLineOptionConstants.GENERATE_TEST_CASE_OPTION,
115                             new CommandLineOption(
116                                     CommandLineOptionConstants.GENERATE_TEST_CASE_OPTION,
117                                     new String JavaDoc[0]));
118         }
119         //System.out.println(page3.getOutputLocation());
120
return optionMap;
121     }
122
123     private WSDLDescription getWOM(String JavaDoc wsdlLocation) throws WSDLException ,
124             IOException JavaDoc {
125         InputStream JavaDoc in = new FileInputStream JavaDoc(new File JavaDoc(wsdlLocation));
126         WSDLVersionWrapper wsdlvWrap = WOMBuilderFactory.getBuilder(WOMBuilderFactory.WSDL11).build(in);
127         return wsdlvWrap.getDescription();
128     }
129
130     private String JavaDoc[] getStringArray(String JavaDoc value) {
131         String JavaDoc[] values = new String JavaDoc[1];
132         values[0] = value;
133         return values;
134     }
135
136
137     public void execute() throws BuildException {
138         try {
139             
140             CommandLineOptionParser parser = new CommandLineOptionParser(this.fillOptionMap());
141             new CodeGenerationEngine(parser).generate();
142         } catch (Throwable JavaDoc e) {
143             throw new BuildException(e);
144         }
145
146     }
147
148     public void setWSDLFileName(String JavaDoc WSDLFileName) {
149         this.WSDLFileName = WSDLFileName;
150     }
151
152     public void setOutput(String JavaDoc output) {
153         this.output = output;
154     }
155
156     public void setPackageName(String JavaDoc packageName) {
157         this.packageName = packageName;
158     }
159
160     public void setLanguage(String JavaDoc language) {
161         this.language = language;
162     }
163
164     public void setAsyncOnly(boolean asyncOnly) {
165         this.asyncOnly = asyncOnly;
166     }
167
168     public void setSyncOnly(boolean syncOnly) {
169         this.syncOnly = syncOnly;
170     }
171
172     public void setServerSide(boolean serverSide) {
173         this.serverSide = serverSide;
174     }
175
176     public void setTestcase(boolean testcase) {
177         this.testcase = testcase;
178     }
179
180     public void setGenerateServerXml(boolean generateServerXml) {
181         this.generateServerXml = generateServerXml;
182     }
183     
184     public static void main(String JavaDoc[] args){
185         AntCodegenTask task = new AntCodegenTask();
186         task.setWSDLFileName("modules/samples/test-resources/wsdl/compound2.wsdl");
187         task.setOutput("temp");
188         task.execute();
189     }
190
191
192 }
193
Popular Tags