KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis > tool > codegen > WSDL2JavaGenerator


1 /*
2  * Copyright 2004,2005 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 package org.apache.axis.tool.codegen;
17
18 import java.io.File JavaDoc;
19 import java.io.FileInputStream JavaDoc;
20 import java.io.IOException JavaDoc;
21 import java.io.InputStream JavaDoc;
22 import java.util.HashMap JavaDoc;
23 import java.util.Map JavaDoc;
24
25 import javax.wsdl.WSDLException;
26
27 import org.apache.axis.tool.codegen.eclipse.util.UIConstants;
28 import org.apache.axis.wsdl.builder.WOMBuilderFactory;
29 import org.apache.axis.wsdl.codegen.CommandLineOption;
30 import org.apache.axis.wsdl.codegen.CommandLineOptionConstants;
31 import org.apache.wsdl.WSDLDescription;
32
33
34 public class WSDL2JavaGenerator {
35     
36     /**
37      * Maps a string containing the name of a language to a constant defined in CommandLineOptionConstants.LanguageNames
38      *
39      * @param UILangValue a string containg a language, e.g. "java", "cs", "cpp" or "vb"
40      * @return a normalized string constant
41      */

42     private String JavaDoc mapLanguagesWithCombo(String JavaDoc UILangValue)
43     {
44        if (UIConstants.JAVA.equals(UILangValue))
45        {
46           return CommandLineOptionConstants.LanguageNames.JAVA;
47        }
48        else if (UIConstants.C_SHARP.equals(UILangValue))
49        {
50           return CommandLineOptionConstants.LanguageNames.C_SHARP;
51        }
52        else if (UIConstants.C_PLUS_PLUS.equals(UILangValue))
53        {
54           return CommandLineOptionConstants.LanguageNames.C_PLUS_PLUS;
55        }
56        else
57        {
58           return null;
59        }
60     }
61     /**
62      * Creates a list of parameters for the code generator based on the decisions made by the user on the OptionsPage
63      * (page2). For each setting, there is a Command-Line option for the Axis2 code generator.
64      *
65      * @return a Map with keys from CommandLineOptionConstants with the values entered by the user on the Options Page.
66      */

67     public Map JavaDoc fillOptionMap(boolean isAyncOnly,
68                       boolean isSyncOnly,
69                       boolean isServerSide,
70                       boolean isServerXML,
71                       boolean isTestCase,
72                       String JavaDoc WSDLFileName,
73                       String JavaDoc packageName,
74                       String JavaDoc selectedLanguage,
75                       String JavaDoc outputLocation
76                       )
77     {
78        Map JavaDoc optionMap = new HashMap JavaDoc();
79        //WSDL file name
80
optionMap.put(CommandLineOptionConstants.WSDL_LOCATION_URI_OPTION, new CommandLineOption(
81           CommandLineOptionConstants.WSDL_LOCATION_URI_OPTION, getStringArray(WSDLFileName)));
82        
83        //Async only
84
if (isAyncOnly)
85        {
86           optionMap.put(CommandLineOptionConstants.CODEGEN_ASYNC_ONLY_OPTION, new CommandLineOption(
87              CommandLineOptionConstants.CODEGEN_ASYNC_ONLY_OPTION, new String JavaDoc[0]));
88        }
89        //sync only
90
if (isSyncOnly)
91        {
92           optionMap.put(CommandLineOptionConstants.CODEGEN_SYNC_ONLY_OPTION, new CommandLineOption(
93              CommandLineOptionConstants.CODEGEN_SYNC_ONLY_OPTION, new String JavaDoc[0]));
94        }
95        //serverside
96
if (isServerSide)
97        {
98           optionMap.put(CommandLineOptionConstants.SERVER_SIDE_CODE_OPTION, new CommandLineOption(
99              CommandLineOptionConstants.SERVER_SIDE_CODE_OPTION, new String JavaDoc[0]));
100           //server xml
101
if (isServerXML)
102           {
103              optionMap.put(CommandLineOptionConstants.GENERATE_SERVICE_DESCRIPTION_OPTION, new CommandLineOption(
104                 CommandLineOptionConstants.GENERATE_SERVICE_DESCRIPTION_OPTION, new String JavaDoc[0]));
105           }
106        }
107        //test case
108
if (isTestCase)
109        {
110           optionMap.put(CommandLineOptionConstants.GENERATE_TEST_CASE_OPTION, new CommandLineOption(
111              CommandLineOptionConstants.GENERATE_TEST_CASE_OPTION, new String JavaDoc[0]));
112        }
113        //package name
114
optionMap.put(CommandLineOptionConstants.PACKAGE_OPTION, new CommandLineOption(
115           CommandLineOptionConstants.PACKAGE_OPTION, getStringArray(packageName)));
116        //selected language
117
optionMap.put(CommandLineOptionConstants.STUB_LANGUAGE_OPTION, new CommandLineOption(
118           CommandLineOptionConstants.STUB_LANGUAGE_OPTION, getStringArray(mapLanguagesWithCombo(selectedLanguage))));
119        //output location
120
optionMap.put(CommandLineOptionConstants.OUTPUT_LOCATION_OPTION, new CommandLineOption(
121           CommandLineOptionConstants.OUTPUT_LOCATION_OPTION, getStringArray(outputLocation)));
122        
123        // System.out.println(page3.getOutputLocation());
124
return optionMap;
125     }
126     /**
127      * Reads the WSDL Object Model from the given location.
128      *
129      * @param wsdlLocation the filesystem location (full path) of the WSDL file to read in.
130      * @return the WSDLDescription object containing the WSDL Object Model of the given WSDL file
131      * @throws WSDLException when WSDL File is invalid
132      * @throws IOException on errors reading the WSDL file
133      */

134     public WSDLDescription getWOM(String JavaDoc wsdlLocation) throws WSDLException, IOException JavaDoc
135     {
136        InputStream JavaDoc in = new FileInputStream JavaDoc(new File JavaDoc(wsdlLocation));
137        return WOMBuilderFactory.getBuilder(WOMBuilderFactory.WSDL11).build(in);
138     }
139
140     /**
141      * Converts a single String into a String Array
142      *
143      * @param value a single string
144      * @return an array containing only one element
145      */

146     private String JavaDoc[] getStringArray(String JavaDoc value)
147     {
148        String JavaDoc[] values = new String JavaDoc[1];
149        values[0] = value;
150        return values;
151     }
152 }
153
Popular Tags