1 package org.apache.axis2.tool.ant; 2 3 import java.io.File ; 4 import java.io.FileInputStream ; 5 import java.io.FileNotFoundException ; 6 import java.io.FileOutputStream ; 7 import java.io.FileWriter ; 8 import java.io.IOException ; 9 import java.io.InputStream ; 10 import java.io.PrintStream ; 11 import java.util.HashMap ; 12 import java.util.Map ; 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 45 public class AntCodegenTask extends Task{ 46 47 private String WSDLFileName=null; 48 private String output="."; 49 private String packageName=URLProcessor.DEFAULT_PACKAGE; 50 private String 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 61 private Map fillOptionMap() { 62 Map optionMap = new HashMap (); 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 [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 [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 [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 [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 [0])); 118 } 119 return optionMap; 121 } 122 123 private WSDLDescription getWOM(String wsdlLocation) throws WSDLException , 124 IOException { 125 InputStream in = new FileInputStream (new File (wsdlLocation)); 126 WSDLVersionWrapper wsdlvWrap = WOMBuilderFactory.getBuilder(WOMBuilderFactory.WSDL11).build(in); 127 return wsdlvWrap.getDescription(); 128 } 129 130 private String [] getStringArray(String value) { 131 String [] values = new String [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 e) { 143 throw new BuildException(e); 144 } 145 146 } 147 148 public void setWSDLFileName(String WSDLFileName) { 149 this.WSDLFileName = WSDLFileName; 150 } 151 152 public void setOutput(String output) { 153 this.output = output; 154 } 155 156 public void setPackageName(String packageName) { 157 this.packageName = packageName; 158 } 159 160 public void setLanguage(String 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 [] 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 |