1 package org.apache.axis.tool.codegen.eclipse; 2 3 import java.io.File ; 4 import java.io.FileInputStream ; 5 import java.io.IOException ; 6 import java.io.InputStream ; 7 import java.util.HashMap ; 8 import java.util.Map ; 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 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 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 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 74 public boolean performFinish() { 75 76 try { 77 doFinish(); 79 } catch (Exception 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 94 95 private void doFinish() { 96 97 try { 98 WSDLDescription wom = this.getWOM(page1.getFileName()); 99 Map optionsMap = fillOptionMap(); 100 CodeGenConfiguration codegenConfig = new CodeGenConfiguration(wom, 101 optionsMap); 102 new CodeGenerationEngine(codegenConfig).generate(); 103 } catch (Exception e) { 104 throw new RuntimeException (e); 105 } 106 107 } 108 109 112 private Map fillOptionMap() { 113 Map optionMap = new HashMap (); 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 [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 [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 [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 [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 [0])); 171 } 172 return optionMap; 174 } 175 176 private String mapLanguagesWithCombo(String 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 194 public void init(IWorkbench workbench, IStructuredSelection selection) { 195 this.selection = selection; 196 } 197 198 private WSDLDescription getWOM(String wsdlLocation) throws WSDLException, 199 IOException { 200 InputStream in = new FileInputStream (new File (wsdlLocation)); 201 return WOMBuilderFactory.getBuilder(WOMBuilderFactory.WSDL11).build(in); 202 } 203 204 private String [] getStringArray(String value) { 205 String [] values = new String [1]; 206 values[0] = value; 207 return values; 208 } 209 } | Popular Tags |