1 16 17 package org.apache.axis2.wsdl.codegen; 18 19 import org.apache.axis2.wsdl.builder.WOMBuilderFactory; 20 import org.apache.axis2.wsdl.codegen.emitter.CSharpEmitter; 21 import org.apache.axis2.wsdl.codegen.emitter.Emitter; 22 import org.apache.axis2.wsdl.codegen.emitter.JavaEmitter; 23 import org.apache.axis2.wsdl.codegen.extension.AxisBindingBuilder; 24 import org.apache.axis2.wsdl.codegen.extension.CodeGenExtension; 25 import org.apache.axis2.wsdl.codegen.extension.PackageFinder; 26 import org.apache.axis2.wsdl.codegen.extension.XMLBeansExtension; 27 import org.apache.axis2.wsdl.databinding.TypeMapper; 28 import org.apache.wsdl.WSDLDescription; 29 30 import javax.wsdl.WSDLException; 31 import java.io.File ; 32 import java.io.FileInputStream ; 33 import java.io.IOException ; 34 import java.io.InputStream ; 35 import java.util.ArrayList ; 36 import java.util.List ; 37 38 42 public class CodeGenerationEngine { 43 44 private List moduleEndpoints = new ArrayList (); 45 46 private CodeGenConfiguration configuration; 47 48 49 public CodeGenerationEngine(CommandLineOptionParser parser) throws CodeGenerationException{ 50 WSDLDescription wom ; 51 try { 52 wom = this.getWOM(parser); 53 } 54 catch (WSDLException e) { 55 throw new CodeGenerationException("Error parsing WSDL", e); 56 } 57 catch(IOException e1){ 58 throw new CodeGenerationException("Invalid WSDL Location ", e1); 59 } 60 61 this.configuration = new CodeGenConfiguration(wom, parser); 62 AxisBindingBuilder axisBindingBuilder = new AxisBindingBuilder(); 63 axisBindingBuilder.init(this.configuration); 64 axisBindingBuilder.engage(); 65 66 PackageFinder packageFinder = new PackageFinder(); 67 packageFinder.init(this.configuration); 68 this.moduleEndpoints.add(packageFinder); 69 70 XMLBeansExtension xmlBeanExtension = new XMLBeansExtension(); 71 xmlBeanExtension.init(this.configuration); 72 this.moduleEndpoints.add(xmlBeanExtension); 73 } 74 75 76 public void generate()throws CodeGenerationException{ 77 78 for(int i = 0; i< this.moduleEndpoints.size(); i++){ 79 ((CodeGenExtension)this.moduleEndpoints.get(i)).engage(); 80 } 81 82 Emitter emitter = null; 83 TypeMapper mapper = configuration.getTypeMapper(); 84 85 switch (configuration.getOutputLanguage()){ 86 case XSLTConstants.LanguageTypes.JAVA: 87 emitter = new JavaEmitter(this.configuration,mapper); 88 break; 89 case XSLTConstants.LanguageTypes.C_SHARP: 90 emitter = new CSharpEmitter(this.configuration,mapper); 91 break; 92 case XSLTConstants.LanguageTypes.C_PLUS_PLUS: 93 case XSLTConstants.LanguageTypes.VB_DOT_NET: 94 95 default: 96 throw new UnsupportedOperationException (); 97 98 } 99 if (this.configuration.isServerSide()) 100 emitter.emitSkeleton(); 101 else 102 emitter.emitStub(); 103 104 105 } 106 107 108 private WSDLDescription getWOM(CommandLineOptionParser parser) throws WSDLException, IOException { 109 String uri = ((CommandLineOption) parser.getAllOptions().get(CommandLineOptionConstants.WSDL_LOCATION_URI_OPTION)).getOptionValue(); 110 InputStream in = new FileInputStream (new File (uri)); 111 return WOMBuilderFactory.getBuilder(WOMBuilderFactory.WSDL11).build(in).getDescription(); 112 } 113 114 115 116 } 117 | Popular Tags |