KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > deployment > util > webservice > WsCompileInvokerImpl


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.enterprise.deployment.util.webservice;
25
26 import java.io.*;
27 import java.util.*;
28
29 //JAX-RPC SPI
30
import com.sun.xml.rpc.spi.JaxRpcObjectFactory;
31 import com.sun.xml.rpc.spi.tools.CompileTool;
32
33 /**
34  * This is an implementation of the WsCompileInvoker
35  */

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 JavaDoc operation) throws WsCompileInvokerException {
46
47         String JavaDoc key, value;
48         int wsCompileOptionCount = 0;
49         
50         Object JavaDoc[] keySet = wsCompileOptions.keySet().toArray();
51         
52         for(int j=0; j<keySet.length; j++) {
53             key = (String JavaDoc) keySet[j];
54             value = (String JavaDoc) wsCompileOptions.get(keySet[j]);
55             if(value == null)
56                 wsCompileOptionCount++;
57             else
58                 wsCompileOptionCount+=2;
59         }
60                 
61         String JavaDoc[] wscompileArgs = new String JavaDoc[wsCompileOptionCount+3];
62         int argsIndex = 0 ;
63
64         for(int i=0; i<keySet.length; i++) {
65             key = (String JavaDoc) keySet[i];
66             value = (String JavaDoc) 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 /**
81  * This is used to generate WSDL and mapping files given information on SEI config
82 */

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 /**
104  * This is used to generate SEI and mapping files given information on WSDL file location, require package name
105 */

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 /**
124  * This is used to generate non-portable client stubs given information on WSDL file location, require package name
125 */

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