KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > axis > wsdl > WSDL2Java


1 /*
2  * The Apache Software License, Version 1.1
3  *
4  *
5  * Copyright (c) 2001-2003 The Apache Software Foundation. All rights
6  * reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in
17  * the documentation and/or other materials provided with the
18  * distribution.
19  *
20  * 3. The end-user documentation included with the redistribution,
21  * if any, must include the following acknowledgment:
22  * "This product includes software developed by the
23  * Apache Software Foundation (http://www.apache.org/)."
24  * Alternately, this acknowledgment may appear in the software itself,
25  * if and wherever such third-party acknowledgments normally appear.
26  *
27  * 4. The names "Axis" and "Apache Software Foundation" must
28  * not be used to endorse or promote products derived from this
29  * software without prior written permission. For written
30  * permission, please contact apache@apache.org.
31  *
32  * 5. Products derived from this software may not be called "Apache",
33  * nor may "Apache" appear in their name, without prior written
34  * permission of the Apache Software Foundation.
35  *
36  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
37  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
38  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
39  * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
40  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
42  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
43  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
44  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
45  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
46  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
47  * SUCH DAMAGE.
48  * ====================================================================
49  *
50  * This software consists of voluntary contributions made by many
51  * individuals on behalf of the Apache Software Foundation. For more
52  * information on the Apache Software Foundation, please see
53  * <http://www.apache.org/>.
54  */

55 package org.jboss.axis.wsdl;
56
57 import org.jboss.axis.enums.Scope;
58 import org.jboss.axis.utils.CLOption;
59 import org.jboss.axis.utils.CLOptionDescriptor;
60 import org.jboss.axis.utils.JavaUtils;
61 import org.jboss.axis.utils.Messages;
62 import org.jboss.axis.wsdl.gen.Parser;
63 import org.jboss.axis.wsdl.gen.WSDL2;
64 import org.jboss.axis.wsdl.toJava.Emitter;
65
66 /**
67  * Command line interface to the WSDL2Java utility
68  */

69 public class WSDL2Java extends WSDL2
70 {
71    // Define our short one-letter option identifiers.
72
protected static final int SERVER_OPT = 's';
73    protected static final int SKELETON_DEPLOY_OPT = 'S';
74    protected static final int NAMESPACE_OPT = 'N';
75    protected static final int NAMESPACE_FILE_OPT = 'f';
76    protected static final int OUTPUT_OPT = 'o';
77    protected static final int SCOPE_OPT = 'd';
78    protected static final int TEST_OPT = 't';
79    protected static final int PACKAGE_OPT = 'p';
80    protected static final int ALL_OPT = 'a';
81    protected static final int TYPEMAPPING_OPT = 'T';
82    protected static final int FACTORY_CLASS_OPT = 'F';
83    protected static final int HELPER_CLASS_OPT = 'H';
84    protected static final int USERNAME_OPT = 'U';
85    protected static final int PASSWORD_OPT = 'P';
86
87    protected boolean bPackageOpt = false;
88    private Emitter emitter;
89
90    /**
91     * Define the understood options. Each CLOptionDescriptor contains:
92     * - The "long" version of the option. Eg, "help" means that "--help" will
93     * be recognised.
94     * - The option flags, governing the option's argument(s).
95     * - The "short" version of the option. Eg, 'h' means that "-h" will be
96     * recognised.
97     * - A description of the option for the usage message
98     */

99    protected static final CLOptionDescriptor[] options = new CLOptionDescriptor[]{
100       new CLOptionDescriptor("server-side",
101               CLOptionDescriptor.ARGUMENT_DISALLOWED,
102               SERVER_OPT,
103               Messages.getMessage("optionSkel00")),
104       new CLOptionDescriptor("skeletonDeploy",
105               CLOptionDescriptor.ARGUMENT_REQUIRED,
106               SKELETON_DEPLOY_OPT,
107               Messages.getMessage("optionSkeletonDeploy00")),
108       new CLOptionDescriptor("NStoPkg",
109               CLOptionDescriptor.DUPLICATES_ALLOWED + CLOptionDescriptor.ARGUMENTS_REQUIRED_2,
110               NAMESPACE_OPT,
111               Messages.getMessage("optionNStoPkg00")),
112       new CLOptionDescriptor("fileNStoPkg",
113               CLOptionDescriptor.ARGUMENT_REQUIRED,
114               NAMESPACE_FILE_OPT,
115               Messages.getMessage("optionFileNStoPkg00")),
116       new CLOptionDescriptor("package",
117               CLOptionDescriptor.ARGUMENT_REQUIRED,
118               PACKAGE_OPT,
119               Messages.getMessage("optionPackage00")),
120       new CLOptionDescriptor("output",
121               CLOptionDescriptor.ARGUMENT_REQUIRED,
122               OUTPUT_OPT,
123               Messages.getMessage("optionOutput00")),
124       new CLOptionDescriptor("deployScope",
125               CLOptionDescriptor.ARGUMENT_REQUIRED,
126               SCOPE_OPT,
127               Messages.getMessage("optionScope00")),
128       new CLOptionDescriptor("testCase",
129               CLOptionDescriptor.ARGUMENT_DISALLOWED,
130               TEST_OPT,
131               Messages.getMessage("optionTest00")),
132       new CLOptionDescriptor("all",
133               CLOptionDescriptor.ARGUMENT_DISALLOWED,
134               ALL_OPT,
135               Messages.getMessage("optionAll00")),
136       new CLOptionDescriptor("typeMappingVersion",
137               CLOptionDescriptor.ARGUMENT_REQUIRED,
138               TYPEMAPPING_OPT,
139               Messages.getMessage("optionTypeMapping00")),
140       new CLOptionDescriptor("factory",
141               CLOptionDescriptor.ARGUMENT_REQUIRED,
142               FACTORY_CLASS_OPT,
143               Messages.getMessage("optionFactory00")),
144       new CLOptionDescriptor("helperGen",
145               CLOptionDescriptor.ARGUMENT_DISALLOWED,
146               HELPER_CLASS_OPT,
147               Messages.getMessage("optionHelper00")),
148       new CLOptionDescriptor("user",
149               CLOptionDescriptor.ARGUMENT_REQUIRED,
150               USERNAME_OPT,
151               Messages.getMessage("optionUsername")),
152       new CLOptionDescriptor("password",
153               CLOptionDescriptor.ARGUMENT_REQUIRED,
154               PASSWORD_OPT,
155               Messages.getMessage("optionPassword"))
156    };
157
158    /**
159     * Instantiate a WSDL2Java emitter.
160     */

161    protected WSDL2Java()
162    {
163       // emitter is the same as the parent's parser variable. Just cast it
164
// here once so we don't have to cast it every time we use it.
165
emitter = (Emitter)parser;
166       addOptions(options);
167    } // ctor
168

169    /**
170     * Instantiate an extension of the Parser
171     */

172    protected Parser createParser()
173    {
174       return new Emitter();
175    } // createParser
176

177    /**
178     * Parse an option
179     *
180     * @param option is the option
181     */

182    protected void parseOption(CLOption option)
183    {
184       switch (option.getId())
185       {
186          case FACTORY_CLASS_OPT:
187             emitter.setFactory(option.getArgument());
188             break;
189
190          case HELPER_CLASS_OPT:
191             emitter.setHelperWanted(true);
192             break;
193
194          case SKELETON_DEPLOY_OPT:
195             emitter.setSkeletonWanted(JavaUtils.isTrueExplicitly(option.getArgument(0)));
196             // --skeletonDeploy assumes --server-side, so fall thru
197

198          case SERVER_OPT:
199             emitter.setServerSide(true);
200             break;
201
202          case NAMESPACE_OPT:
203             String JavaDoc namespace = option.getArgument(0);
204             String JavaDoc packageName = option.getArgument(1);
205             emitter.getNamespaceMap().put(namespace, packageName);
206             break;
207
208          case NAMESPACE_FILE_OPT:
209             emitter.setNStoPkg(option.getArgument());
210             break;
211
212          case PACKAGE_OPT:
213             bPackageOpt = true;
214             emitter.setPackageName(option.getArgument());
215             break;
216
217          case OUTPUT_OPT:
218             emitter.setOutputDir(option.getArgument());
219             break;
220
221          case SCOPE_OPT:
222             String JavaDoc arg = option.getArgument();
223
224             // Provide 'null' default, prevents logging internal error.
225
// we have something different to report here.
226
Scope scope = Scope.getScope(arg, null);
227
228             if (scope != null)
229             {
230                emitter.setScope(scope);
231             }
232             else
233             {
234                System.err.println(Messages.getMessage("badScope00", arg));
235             }
236
237             break;
238
239          case TEST_OPT:
240             emitter.setTestCaseWanted(true);
241             break;
242
243          case ALL_OPT:
244             emitter.setAllWanted(true);
245             break;
246
247          case TYPEMAPPING_OPT:
248             String JavaDoc tmValue = option.getArgument();
249             if (tmValue.equals("1.1"))
250             {
251                emitter.setTypeMappingVersion("1.1");
252             }
253             else if (tmValue.equals("1.2"))
254             {
255                emitter.setTypeMappingVersion("1.2");
256             }
257             else
258             {
259                System.out.println(Messages.getMessage("badTypeMappingOption00"));
260             }
261             break;
262
263          case USERNAME_OPT:
264             emitter.setUsername(option.getArgument());
265             break;
266
267          case PASSWORD_OPT:
268             emitter.setPassword(option.getArgument());
269             break;
270
271          default:
272             super.parseOption(option);
273       }
274    } // parseOption
275

276    /**
277     * validateOptions
278     * This method is invoked after the options are set to validate
279     * the option settings.
280     */

281    protected void validateOptions()
282    {
283       super.validateOptions();
284
285       // validate argument combinations
286
if (emitter.isSkeletonWanted() && !emitter.isServerSide())
287       {
288          System.out.println(Messages.getMessage("badSkeleton00"));
289          printUsage();
290       }
291       if (!emitter.getNamespaceMap().isEmpty() && bPackageOpt)
292       {
293          System.out.println(Messages.getMessage("badpackage00"));
294          printUsage();
295       }
296    } // validateOptions
297

298    /**
299     * Main
300     * Run the WSDL2Java emitter with the specified command-line arguments
301     *
302     * @param args command-line arguments
303     */

304    public static void main(String JavaDoc args[])
305    {
306       WSDL2Java wsdl2java = new WSDL2Java();
307       wsdl2java.run(args);
308    }
309 }
310
Popular Tags