1 23 24 package com.sun.enterprise.deployment.util.webservice; 25 26 import java.io.*; 27 import java.util.*; 28 29 import com.sun.xml.rpc.spi.JaxRpcObjectFactory; 31 import com.sun.xml.rpc.spi.tools.CompileTool; 32 33 36 37 public class WsCompileInvokerImpl extends WsCompileInvoker { 38 39 private OutputStream output = null; 40 41 public WsCompileInvokerImpl(OutputStream out) { 42 output = out; 43 } 44 45 private void invokeTool(File configFile, String operation) throws WsCompileInvokerException { 46 47 String key, value; 48 int wsCompileOptionCount = 0; 49 50 Object [] keySet = wsCompileOptions.keySet().toArray(); 51 52 for(int j=0; j<keySet.length; j++) { 53 key = (String ) keySet[j]; 54 value = (String ) wsCompileOptions.get(keySet[j]); 55 if(value == null) 56 wsCompileOptionCount++; 57 else 58 wsCompileOptionCount+=2; 59 } 60 61 String [] wscompileArgs = new String [wsCompileOptionCount+3]; 62 int argsIndex = 0 ; 63 64 for(int i=0; i<keySet.length; i++) { 65 key = (String ) keySet[i]; 66 value = (String ) wsCompileOptions.get(keySet[i]); 67 wscompileArgs[argsIndex++] = key; 68 if(value != null) 69 wscompileArgs[argsIndex++] = value; 70 } 71 wscompileArgs[argsIndex++] = "-" + operation; 72 wscompileArgs[argsIndex++] = "-keep"; 73 wscompileArgs[argsIndex++] = configFile.getPath(); 74 75 CompileTool tool = JaxRpcObjectFactory.newInstance().createCompileTool(output, "wscompile"); 76 if(!tool.run(wscompileArgs)) 77 throw new WsCompileInvokerException("wscompile invocation failed"); 78 } 79 80 83 public void generateWSDL(SEIConfig config) throws WsCompileInvokerException, IOException { 84 File configFile = File.createTempFile("wscompileinvoker_seiinfo", 85 "config"); 86 configFile.deleteOnExit(); 87 FileWriter writer = new FileWriter(configFile); 88 writer.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\n"); 89 writer.write("<configuration xmlns=\"http://java.sun.com/xml/ns/jax-rpc/ri/config\">\n"); 90 writer.write("<service name=\"" + config.getWebServiceName() + "\" "); 91 writer.write("targetNamespace=\"urn:" + config.getNameSpace() + "\" "); 92 writer.write("typeNamespace=\"urn:" + config.getNameSpace() + "\" "); 93 writer.write("packageName=\"" + config.getPackageName() + "\">\n"); 94 writer.write("<interface name=\"" + config.getInterface() + "\" "); 95 writer.write("servantName=\"" + config.getServant() + "\"/>\n"); 96 writer.write("<typeMappingRegistry />\n"); 97 writer.write("</service>\n"); 98 writer.write("</configuration>\n"); 99 writer.close(); 100 invokeTool(configFile, "define"); 101 } 102 103 106 107 public void generateSEI(WSDLConfig config) throws WsCompileInvokerException, IOException { 108 File configFile = File.createTempFile("wscompileinvoker_wsdlinfo", 109 "config"); 110 configFile.deleteOnExit(); 111 FileWriter writer = new FileWriter(configFile); 112 writer.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\n"); 113 writer.write("<configuration xmlns=\"http://java.sun.com/xml/ns/jax-rpc/ri/config\">\n"); 114 writer.write("<wsdl location=\"" + config.getWsdlLocation() + 115 "\" packageName=\"" + config.getPackageName() +"\">\n"); 116 writer.write("<typeMappingRegistry />\n"); 117 writer.write("</wsdl>\n"); 118 writer.write("</configuration>\n"); 119 writer.close(); 120 invokeTool(configFile, "import"); 121 } 122 123 126 127 public void generateClientStubs(WSDLConfig config) throws WsCompileInvokerException, IOException { 128 File configFile = File.createTempFile("wscompileinvoker_stubsinfo", 129 "config"); 130 configFile.deleteOnExit(); 131 FileWriter writer = new FileWriter(configFile); 132 writer.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\n"); 133 writer.write("<configuration xmlns=\"http://java.sun.com/xml/ns/jax-rpc/ri/config\">\n"); 134 writer.write("<wsdl name=\"" + config.getWebServiceName() + "\" location=\"" + config.getWsdlLocation() + 135 "\" packageName=\"" + config.getPackageName() +"\">\n"); 136 writer.write("<typeMappingRegistry />\n"); 137 writer.write("</wsdl>\n"); 138 writer.write("</configuration>\n"); 139 writer.close(); 140 invokeTool(configFile, "gen:client"); 141 } 142 143 } 144 | Popular Tags |