KickJava   Java API By Example, From Geeks To Geeks.

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


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 /**
30  * This interface is used by the deploytool to generate webservice artifacts.
31  * A client is expected to set the options and features using the add* methods before calling the generate* method
32  *
33  * Here is a code sample
34  *
35  * SEIConfig cfg = new SEIConfig("WeatherWebService", "WeatherWebService", "endpoint",
36  * "endpoint.WeatherService", "endpoint.WeatherServiceImpl");
37  * WsCompileInvoker inv = WsCompileInvoker.getWsCompileInvoker(System.out);
38  * inv.addWsCompileOption(inv.TARGET_DIR, "/home/user/codesamples/weatherinfo/test");
39  * inv.addWsCompileOption(inv.MAP_FILE, "/home/user/codesamples/weatherinfo/test/map109.xml");
40  * inv.addWsCompileOption(inv.CLASS_PATH, "/home/user/codesamples/weatherinfo/service/build/classes");
41  * inv.addWsCompileFeature("wsi");
42  * inv.addWsCompileFeature("strict");
43  * inv.generateWSDL(cfg);
44  *
45  * If the client uses the same instance of WsCompileInvoker for multiple invocations of wscompile, then it is
46  * the client's responsibility to empty the options (using the clearWsCompileOptionsAndFeatures() method) that
47  * are present in this Map before using this Map for the next wscompile invocation
48  */

49
50 public abstract class WsCompileInvoker {
51
52 /**
53  * This Map holds all the options to be used while invoking the wscompile tool; the options are set by the client
54  * of this interface using the setter methods available in this interface.
55  **/

56     protected HashMap wsCompileOptions = null;
57
58 /**
59  * This specifies the classpath to be used by the wscompile tool - ideally this should at least be set to
60  * directory where the SEI package is present.
61  */

62     public static final String JavaDoc CLASS_PATH = "-classpath";
63
64 /**
65  * This specifies the target directory to be used by the wscompile tool to create the service artifacts - if
66  * this is not specified, then the current directory will be used by the wscompile tool
67  */

68     public static final String JavaDoc TARGET_DIR = "-d";
69
70 /**
71  * This specifies the file name to be used by the wscompile tool for creating the 109 mapping file.
72  */

73     public static final String JavaDoc MAP_FILE = "-mapping";
74     
75 /**
76  * This is used to generate WSDL and mapping files given information on SEI config; the caller sends in all the
77  * required info in SEIConfig (info like name of webservice, interface name, package name etc) and this method
78  * creates the equivalent jaxrpc-config.xml, invokes wscompile with -define option which will generate the WSDL
79  * and the mapping file.
80  *
81  * @param SEIConfig containing webservice name, package name, namespace, SEI and its implementation
82 */

83     public abstract void generateWSDL(SEIConfig config) throws WsCompileInvokerException, IOException;
84
85 /**
86  * This is used to generate SEI and mapping files given information on WSDL file location, require package name.
87  * The caller sends the required info on WSDL location, package name etc in WSDLConfig argument and this method
88  * creates the equivalent jaxrpc-config,xml, invokes wscompile with -import option which will generate the SEI
89  * and a template implementation of the SEI.
90  * @param WSDLConfig containing webservice name, package name, and WSDL location
91 */

92
93     public abstract void generateSEI(WSDLConfig config) throws WsCompileInvokerException, IOException;
94
95 /**
96  * This is used to generate the non-portable client side artifacts given information on WSDL file location and the
97  * package name; The caller sends the required info on WSDL location, package name etc in WSDLConfig argument and
98  * this method creates the equivalent jaxrpc-config.xml, invokes wscompile with -gen:client option which will
99  * generate all required non-portable client-side artifacts like JAXRPC stubs etc.
100  * @param WSDLConfig containing webservice name, package name, and WSDL location
101  */

102     public abstract void generateClientStubs(WSDLConfig config) throws WsCompileInvokerException, IOException;
103     
104 /**
105  * This is used to set an option to be used while invoking the wscompile tool; for example to use the -classpath
106  * option for wscompile, the call will be setWsCompileOption(WsCompileInvoker.CLASS_PATH, "the_path");
107  * For using wscompile options that are not defined in WsCompileInvoker, the 'option' argument of this call will be
108  * the actual argument to be used ; for example, for using the '-s' option of wscompile, the call
109  * to set the option will be setWsCompileOption("-s", "the_path_to_be_used");
110  * For options that dont have an operand, the second argument can be null; for example, to invoke the wscompile tool
111  * with verbose option, the -verbose option will be set with this call setWsCompileOption("-verbose", null);
112  * @param String option the wscompile option to be used
113  * @param String operand the operand for the option; null if none;
114  */

115     public void addWsCompileOption(String JavaDoc option, String JavaDoc operand) {
116         if(wsCompileOptions == null)
117             wsCompileOptions = new HashMap();
118         wsCompileOptions.put(option, operand);
119     }
120
121 /**
122  * This is used to remove an option that was already set
123  * @param String The option that has to be removed
124  * @returns true If the option was found and removed
125  * @returns false If the option was not found
126  */

127     public boolean removeWsCompileOption(String JavaDoc option) {
128         if( (wsCompileOptions != null) && wsCompileOptions.containsKey(option) ) {
129             wsCompileOptions.remove(option);
130             return true;
131         }
132         return false;
133     }
134             
135 /**
136  * This is used to set a feature to be used while invoking the wscompile tool; for example to use the -f:wsi feature,
137  * the call will be addWsCompileFeature("wsi")
138  * This will prefix -f: to the feature and set it as part of the options Map with operand being null
139  * @param String the feature to be set
140  */

141     public void addWsCompileFeature(String JavaDoc feature) {
142         addWsCompileOption("-f:"+feature, null);
143     }
144     
145 /**
146  * This is used to remove a feature that was set; for example to remove "-f:strict" feature that was set before the
147  * call will be removeWsCompileFeature("strict")
148  * @param String the feature to be removed
149  * @returns true if the feature was found and removed
150  * @false false if the feature was not found
151  */

152
153     public boolean removeWsCompileFeature(String JavaDoc feature) {
154         return(removeWsCompileOption("-f:"+feature));
155     }
156     
157 /**
158  * This is used to clear all options that have been set
159  */

160     public void clearWsCompileOptionsAndFeatures() {
161         if(wsCompileOptions != null)
162             wsCompileOptions.clear();
163     }
164
165 /**
166  * This returns instance of the WsCompileInvoker interface. This is meant to be used by the tool to get
167  * an instance of the interface
168  * @param OutputStream a stream where the messages, if any, from the wscompile tool will be sent
169  * @returns WsCompileInvoker an instance of the WsCompileInvoker object
170  */

171     
172     public static WsCompileInvoker getWsCompileInvoker(OutputStream out) {
173         return(new WsCompileInvokerImpl(out));
174     }
175 }
176
Popular Tags