KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis > tool > codegen > eclipse > CodeGenWizard


1 package org.apache.axis.tool.codegen.eclipse;
2
3 import java.io.File JavaDoc;
4 import java.io.FileInputStream JavaDoc;
5 import java.io.IOException JavaDoc;
6 import java.io.InputStream JavaDoc;
7 import java.util.HashMap JavaDoc;
8 import java.util.Map JavaDoc;
9
10 import javax.wsdl.WSDLException;
11
12 import org.apache.axis.tool.codegen.eclipse.ui.OptionsPage;
13 import org.apache.axis.tool.codegen.eclipse.ui.OutputPage;
14 import org.apache.axis.tool.codegen.eclipse.ui.WSDLFileSelectionPage;
15 import org.apache.axis.tool.codegen.eclipse.util.UIConstants;
16 import org.apache.axis.tool.codegen.eclipse.plugin.CodegenWizardPlugin;
17 import org.apache.axis.wsdl.builder.WOMBuilderFactory;
18 import org.apache.axis.wsdl.codegen.CodeGenConfiguration;
19 import org.apache.axis.wsdl.codegen.CodeGenerationEngine;
20 import org.apache.axis.wsdl.codegen.CommandLineOption;
21 import org.apache.axis.wsdl.codegen.CommandLineOptionConstants;
22 import org.apache.wsdl.WSDLDescription;
23 import org.eclipse.jface.dialogs.MessageDialog;
24 import org.eclipse.jface.viewers.ISelection;
25 import org.eclipse.jface.viewers.IStructuredSelection;
26 import org.eclipse.jface.wizard.Wizard;
27 import org.eclipse.ui.INewWizard;
28 import org.eclipse.ui.IWorkbench;
29 import org.eclipse.ui.IWorkbenchWizard;
30
31 /**
32  * The main wizard for the codegen wizard
33  */

34
35 public class CodeGenWizard extends Wizard implements INewWizard {
36     private WSDLFileSelectionPage page1;
37
38     private OptionsPage page2;
39
40     private OutputPage page3;
41
42     private ISelection selection;
43
44     private boolean canFinish = false;
45
46     /**
47      * Constructor for CodeGenWizard.
48      */

49     public CodeGenWizard() {
50         super();
51         setNeedsProgressMonitor(true);
52         this.setWindowTitle(org.apache.axis.tool.codegen.eclipse.plugin.CodegenWizardPlugin
53                 .getResourceString("general.name"));
54     }
55
56     /**
57      * Adding the page to the wizard.
58      */

59
60     public void addPages() {
61         page1 = new WSDLFileSelectionPage(selection);
62         addPage(page1);
63         page2 = new OptionsPage();
64         addPage(page2);
65         page3 = new OutputPage();
66         addPage(page3);
67
68     }
69
70     /**
71      * This method is called when 'Finish' button is pressed in the wizard. We
72      * will create an operation and run it using wizard as execution context.
73      */

74     public boolean performFinish() {
75
76         try {
77             // getContainer().run(true, false, op);
78
doFinish();
79         } catch (Exception JavaDoc e) {
80             e.printStackTrace();
81             MessageDialog.openError(getShell(), CodegenWizardPlugin
82                     .getResourceString("general.Error"), e.getMessage());
83             return false;
84         }
85         MessageDialog.openInformation(this.getShell(), CodegenWizardPlugin
86                 .getResourceString("general.name"), CodegenWizardPlugin
87                 .getResourceString("wizard.success"));
88         return true;
89     }
90
91     /**
92      * The worker method.
93      */

94
95     private void doFinish() {
96   
97         try {
98             WSDLDescription wom = this.getWOM(page1.getFileName());
99             Map JavaDoc optionsMap = fillOptionMap();
100             CodeGenConfiguration codegenConfig = new CodeGenConfiguration(wom,
101                     optionsMap);
102             new CodeGenerationEngine(codegenConfig).generate();
103         } catch (Exception JavaDoc e) {
104             throw new RuntimeException JavaDoc(e);
105         }
106
107     }
108
109     /**
110      *
111      */

112     private Map JavaDoc fillOptionMap() {
113         Map JavaDoc optionMap = new HashMap JavaDoc();
114
115         optionMap.put(CommandLineOptionConstants.WSDL_LOCATION_URI_OPTION,
116                 new CommandLineOption(
117                         CommandLineOptionConstants.WSDL_LOCATION_URI_OPTION,
118                         getStringArray(page1.getFileName())));
119
120         if (page2.isAsyncOnlyOn()) {
121             optionMap
122                     .put(
123                             CommandLineOptionConstants.CODEGEN_ASYNC_ONLY_OPTION,
124                             new CommandLineOption(
125                                     CommandLineOptionConstants.CODEGEN_ASYNC_ONLY_OPTION,
126                                     new String JavaDoc[0]));
127         }
128         if (page2.isSyncOnlyOn()) {
129             optionMap
130                     .put(
131                             CommandLineOptionConstants.CODEGEN_SYNC_ONLY_OPTION,
132                             new CommandLineOption(
133                                     CommandLineOptionConstants.CODEGEN_SYNC_ONLY_OPTION,
134                                     new String JavaDoc[0]));
135         }
136         optionMap.put(CommandLineOptionConstants.PACKAGE_OPTION,
137                 new CommandLineOption(
138                         CommandLineOptionConstants.PACKAGE_OPTION,
139                         getStringArray(page2.getPackageName())));
140         optionMap.put(CommandLineOptionConstants.STUB_LANGUAGE_OPTION,
141                 new CommandLineOption(
142                         CommandLineOptionConstants.STUB_LANGUAGE_OPTION,
143                         getStringArray(mapLanguagesWithCombo(page2
144                                 .getSelectedLanguage()))));
145         optionMap.put(CommandLineOptionConstants.OUTPUT_LOCATION_OPTION,
146                 new CommandLineOption(
147                         CommandLineOptionConstants.OUTPUT_LOCATION_OPTION,
148                         getStringArray(page3.getOutputLocation())));
149         if (page2.isServerside()) {
150             optionMap.put(CommandLineOptionConstants.SERVER_SIDE_CODE_OPTION,
151                     new CommandLineOption(
152                             CommandLineOptionConstants.SERVER_SIDE_CODE_OPTION,
153                             new String JavaDoc[0]));
154
155             if (page2.isServerXML()) {
156                 optionMap
157                         .put(
158                                 CommandLineOptionConstants.GENERATE_SERVICE_DESCRIPTION_OPTION,
159                                 new CommandLineOption(
160                                         CommandLineOptionConstants.GENERATE_SERVICE_DESCRIPTION_OPTION,
161                                         new String JavaDoc[0]));
162             }
163         }
164         if (page2.isGenerateTestCase()){
165             optionMap
166             .put(
167                     CommandLineOptionConstants.GENERATE_TEST_CASE_OPTION,
168                     new CommandLineOption(
169                             CommandLineOptionConstants.GENERATE_TEST_CASE_OPTION,
170                             new String JavaDoc[0]));
171         }
172         //System.out.println(page3.getOutputLocation());
173
return optionMap;
174     }
175
176     private String JavaDoc mapLanguagesWithCombo(String JavaDoc UILangValue) {
177         if (UIConstants.JAVA.equals(UILangValue)) {
178             return CommandLineOptionConstants.LanguageNames.JAVA;
179         } else if (UIConstants.C_SHARP.equals(UILangValue)) {
180             return CommandLineOptionConstants.LanguageNames.C_SHARP;
181         } else if (UIConstants.C_PLUS_PLUS.equals(UILangValue)) {
182             return CommandLineOptionConstants.LanguageNames.C_PLUS_PLUS;
183         } else {
184             return null;
185         }
186     }
187
188     /**
189      * We will accept the selection in the workbench to see if we can initialize
190      * from it.
191      *
192      * @see IWorkbenchWizard#init(IWorkbench, IStructuredSelection)
193      */

194     public void init(IWorkbench workbench, IStructuredSelection selection) {
195         this.selection = selection;
196     }
197
198     private WSDLDescription getWOM(String JavaDoc wsdlLocation) throws WSDLException,
199             IOException JavaDoc {
200         InputStream JavaDoc in = new FileInputStream JavaDoc(new File JavaDoc(wsdlLocation));
201         return WOMBuilderFactory.getBuilder(WOMBuilderFactory.WSDL11).build(in);
202     }
203
204     private String JavaDoc[] getStringArray(String JavaDoc value) {
205         String JavaDoc[] values = new String JavaDoc[1];
206         values[0] = value;
207         return values;
208     }
209 }
Popular Tags