001: /*
002: * soapUI, copyright (C) 2004-2007 eviware.com
003: *
004: * soapUI is free software; you can redistribute it and/or modify it under the
005: * terms of version 2.1 of the GNU Lesser General Public License as published by
006: * the Free Software Foundation.
007: *
008: * soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
009: * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
010: * See the GNU Lesser General Public License for more details at gnu.org.
011: */
012:
013: package com.eviware.soapui.impl.wsdl.actions.iface.tools.gsoap;
014:
015: import java.io.File;
016: import java.util.ArrayList;
017: import java.util.List;
018:
019: import com.eviware.soapui.SoapUI;
020: import com.eviware.soapui.impl.wsdl.actions.iface.tools.support.AbstractToolsAction;
021: import com.eviware.soapui.impl.wsdl.actions.iface.tools.support.ArgumentBuilder;
022: import com.eviware.soapui.impl.wsdl.actions.iface.tools.support.ProcessToolRunner;
023: import com.eviware.soapui.impl.wsdl.actions.iface.tools.support.ToolHost;
024: import com.eviware.soapui.impl.wsdl.support.HelpUrls;
025: import com.eviware.soapui.model.iface.Interface;
026: import com.eviware.soapui.settings.ToolsSettings;
027: import com.eviware.soapui.support.Tools;
028: import com.eviware.soapui.support.UISupport;
029: import com.eviware.soapui.support.types.StringToStringMap;
030: import com.eviware.x.form.XForm;
031: import com.eviware.x.form.XFormDialog;
032: import com.eviware.x.form.XFormDialogBuilder;
033: import com.eviware.x.form.XFormFactory;
034:
035: /**
036: * Invokes GSoap wsdl2h
037: *
038: * @author Ole.Matzura
039: */
040:
041: /*
042: * http://www.cs.fsu.edu/~engelen/soap.html
043: *
044: * Option Description
045: -a generate indexed struct names for local elements with anonymous types
046: -c generate C source code
047: -d use DOM to populate xs:any and xsd:anyType elements
048: -e don't qualify enum names
049: This option is for backward compatibility with gSOAP 2.4.1 and earlier.
050: The option does not produce code that conforms to WS-I Basic Profile 1.0a.
051: -f generate flat C++ class hierarchy for schema extensions
052: -g generate global top-level element declarations
053: -h print help information
054: -I path use path to find files
055: -l include license information in output
056: -m use xsd.h module to import primitive types
057: -n name use name as the base namespace prefix name instead of ns
058: -N name use name as the base namespace prefix name for service namespaces
059: -o file output to file
060: -p create polymorphic types with C++ inheritance hierarchy with base xsd__anyType
061: This is automatically performed when WSDL contains polymorphic definitions
062: -r host:port connect via proxy host and port
063: -s don't generate STL code (no std::string and no std::vector)
064: -t file use type map file instead of the default file typemap.dat
065: -u don't generate unions
066: -v verbose output
067: -w always wrap response parameters in a response struct
068: -x don't generate _XML any/anyAttribute extensibility elements
069: -y generate typedef synonyms for structs and enums
070: -? print help information
071: */
072:
073: public class GSoapAction extends AbstractToolsAction<Interface> {
074: // private static final String WSDL2H_PATH = "path";
075: private static final String WSDL2H_OUTPUT = "file";
076:
077: //WSDL2H settings
078: private static final String GENERATE_INDEXED_STRUCT = "generate indexed struct names";
079: private static final String GENERATE_C_SOURCE = "generate C source code";
080: private static final String DOM = "use DOM";
081: private static final String DONT_QUALIFY_ENUM_NAMES = "don't qualify enum names";
082: private static final String FLAT_CPP_CLASS_HIERARCHY = "generate flat C++ class hierarchy";
083: private static final String GLOBAL_TOP_LEVEL_DECLARATIONS = "generate global top-level declarations";
084: private static final String PATH = "path to find files";
085: private static final String INCLUDE_LICENSE_INFORMATION = "include license information";
086: private static final String USE_XSD_H = "use xsd.h module";
087: private static final String BASE_NAMESPACE_PREFIX_INSTEAD_OF_NS = "prefixNs";
088: private static final String BASE_NAMESPACE_PREFIX_FOR_SERVICE_NS = "servicePrefixNs";
089: private static final String POLYMORPHIC_TYPES = "create polymorphic types";
090: private static final String PROXY_HOST_PORT = "proxy host:port";
091: private static final String NO_STL = "don't generate STL code";
092: private static final String TYPE_MAP_FILE = "use type map file";
093: private static final String NO_UNIONS = "don't generate unions";
094: private static final String VERBOSE = "verbose output";
095: private static final String WRAP_RESPONSE_STRUCT = "wrap response in struct";
096: private static final String NO_ANY = "don't generate _XML any/anyAttribute";
097: private static final String TYPEDEF_SYNONYMS = "generate typedef synonyms for structs and enums";
098:
099: //SOAPCPP2 settings
100: private static final String SOAP_11 = "generate SOAP 1.1 bindings";
101: private static final String SOAP_12 = "generate SOAP 1.2 bindings";
102: private static final String CLIENT_SIDE = "generate client-side code only";
103: private static final String SERVER_SIDE = "generate server-side code only";
104: private static final String NO_LIB = "don't generate soapClientLib/soapServerLib";
105: private static final String SOAP_ACTION = "use value of SOAPAction HTTP header to dispatch method at server side";
106: private static final String GENERATE_C_SOURCE_CPP = "generate C source code";
107: // private static final String SAVE_PATH = "use path to save files";
108: private static final String SOAP_RPC = "generate SOAP RPC encoding style bindings";
109: private static final String SERVICE_PROXIES = "generate service proxies and objects inherited from soap struct";
110: private static final String IMPORT_PATH = "import path(s)";
111: private static final String GENERATE_LINKABLE_MODULES = "generate linkable modules (experimental)";
112: private static final String GENERATE_MATLAB_CODE = "generate Matlab(tm) code for MEX compiler";
113: private static final String SERVICE_NAME = "use service name to rename service functions and namespace table";
114: private static final String NAME_PREFIX = "file prefix";
115: private static final String XSI_TYPED = "generate code for fully xsi:type typed SOAP/XML messaging";
116: private static final String NO_GEN_WSDL_SCHEMA = "don't generate WSDL and schema files";
117: private static final String NO_GEN_SAMPLE_XML = "don't generate sample XML message files";
118:
119: private static final String WSDL2H = "run wsdl2h";
120: private static final String SOAPCPP2 = "run soapcpp2";
121: public static final String SOAPUI_ACTION_ID = "GSoapAction";
122:
123: public GSoapAction() {
124: super ("GSoap Artifacts",
125: "Generates GSoap artifacts using wsdl2h and soap2cpp");
126: }
127:
128: protected StringToStringMap initValues(Interface modelItem) {
129: StringToStringMap values = super .initValues(modelItem);
130:
131: values.putIfMissing(WSDL2H, Boolean.toString(true));
132: values.putIfMissing(SOAPCPP2, Boolean.toString(true));
133: return values;
134: }
135:
136: protected XFormDialog buildDialog(Interface modelItem) {
137: XFormDialogBuilder builder = XFormFactory
138: .createDialogBuilder("GSoap Artifacts");
139:
140: XForm wsdl2hAdvForm = builder.createForm("wsdl2h");
141:
142: wsdl2hAdvForm.addCheckBox(WSDL2H, null);
143: addWSDLFields(wsdl2hAdvForm, modelItem);
144:
145: wsdl2hAdvForm.addTextField(WSDL2H_OUTPUT,
146: "name of output file", XForm.FieldType.PROJECT_FILE);
147:
148: XForm soapcpp2AdvForm = builder.createForm("soapcpp2");
149:
150: soapcpp2AdvForm.addCheckBox(SOAPCPP2, null);
151:
152: wsdl2hAdvForm.addCheckBox(GENERATE_INDEXED_STRUCT, null);
153: wsdl2hAdvForm.addCheckBox(GENERATE_C_SOURCE, null);
154: wsdl2hAdvForm.addCheckBox(DOM, null);
155: wsdl2hAdvForm.addCheckBox(DONT_QUALIFY_ENUM_NAMES, null);
156: wsdl2hAdvForm.addCheckBox(FLAT_CPP_CLASS_HIERARCHY, null);
157: wsdl2hAdvForm.addCheckBox(GLOBAL_TOP_LEVEL_DECLARATIONS, null);
158: wsdl2hAdvForm.addTextField(PATH, "use path to find files",
159: XForm.FieldType.PROJECT_FOLDER);
160: wsdl2hAdvForm.addCheckBox(INCLUDE_LICENSE_INFORMATION, null);
161: wsdl2hAdvForm.addCheckBox(USE_XSD_H, null);
162: wsdl2hAdvForm
163: .addTextField(
164: BASE_NAMESPACE_PREFIX_INSTEAD_OF_NS,
165: "use name as the base namespace prefix name instead of ns",
166: XForm.FieldType.TEXT);
167: wsdl2hAdvForm
168: .addTextField(
169: BASE_NAMESPACE_PREFIX_FOR_SERVICE_NS,
170: "use name as the base namespace prefix name for service namespaces",
171: XForm.FieldType.TEXT);
172:
173: wsdl2hAdvForm.addCheckBox(POLYMORPHIC_TYPES, null);
174: wsdl2hAdvForm.addTextField(PROXY_HOST_PORT,
175: "connect via proxy host and port (host:port)",
176: XForm.FieldType.TEXT);
177: wsdl2hAdvForm.addCheckBox(NO_STL, null);
178: wsdl2hAdvForm
179: .addTextField(
180: TYPE_MAP_FILE,
181: "use type map file instead of the default file typemap.dat",
182: XForm.FieldType.PROJECT_FILE);
183: wsdl2hAdvForm.addCheckBox(NO_UNIONS, null);
184: wsdl2hAdvForm.addCheckBox(VERBOSE, null);
185: wsdl2hAdvForm.addCheckBox(WRAP_RESPONSE_STRUCT, null);
186: wsdl2hAdvForm.addCheckBox(NO_ANY, null);
187: wsdl2hAdvForm.addCheckBox(TYPEDEF_SYNONYMS, null);
188:
189: soapcpp2AdvForm.addCheckBox(SOAP_11, null);
190: soapcpp2AdvForm.addCheckBox(SOAP_12, null);
191: soapcpp2AdvForm.addCheckBox(CLIENT_SIDE, null);
192: soapcpp2AdvForm.addCheckBox(SERVER_SIDE, null);
193: soapcpp2AdvForm.addCheckBox(NO_LIB, null);
194: soapcpp2AdvForm.addCheckBox(SOAP_ACTION, null);
195: soapcpp2AdvForm.addCheckBox(GENERATE_C_SOURCE_CPP, null);
196: //soapcpp2AdvForm.addTextField(SAVE_PATH, "", XForm.FieldType.DIRECTORY);
197: soapcpp2AdvForm.addCheckBox(SOAP_RPC, null);
198: soapcpp2AdvForm.addCheckBox(SERVICE_PROXIES, null);
199: soapcpp2AdvForm.addTextField(IMPORT_PATH,
200: "use path(s) for #import",
201: XForm.FieldType.PROJECT_FOLDER);
202: soapcpp2AdvForm.addCheckBox(GENERATE_LINKABLE_MODULES, null);
203: soapcpp2AdvForm.addCheckBox(GENERATE_MATLAB_CODE, null);
204: soapcpp2AdvForm.addCheckBox(SERVICE_NAME, null);
205: soapcpp2AdvForm.addTextField(NAME_PREFIX,
206: "save files with new prefix name instead of 'soap'",
207: XForm.FieldType.TEXT);
208: soapcpp2AdvForm.addCheckBox(XSI_TYPED, null);
209: soapcpp2AdvForm.addCheckBox(NO_GEN_WSDL_SCHEMA, null);
210: soapcpp2AdvForm.addCheckBox(NO_GEN_SAMPLE_XML, null);
211:
212: return builder.buildDialog(buildDefaultActions(
213: HelpUrls.GSOAP_HELP_URL, modelItem),
214: "Specify arguments for GSoap wsdl2h and soap2cpp",
215: UISupport.TOOL_ICON);
216: }
217:
218: protected void generate(StringToStringMap values,
219: ToolHost toolHost, Interface modelItem) throws Exception {
220: String gsoapDir = SoapUI.getSettings().getString(
221: ToolsSettings.GSOAP_LOCATION, null);
222: if (Tools.isEmpty(gsoapDir)) {
223: UISupport
224: .showErrorMessage("GSoap directory must be set in global preferences");
225: return;
226: }
227:
228: List<ProcessBuilder> builders = new ArrayList<ProcessBuilder>();
229:
230: if (values.getBoolean(WSDL2H)) {
231: ProcessBuilder wsdl2hBuilder = new ProcessBuilder();
232: ArgumentBuilder wsdl2hArgs = buildWsdl2HArgs(modelItem);
233: wsdl2hBuilder.command(wsdl2hArgs.getArgs());
234: //wsdl2hBuilder.directory(new File(gsoapDir));
235: wsdl2hBuilder.directory(new File(Tools.getDir(values
236: .get(WSDL2H_OUTPUT))));
237: builders.add(wsdl2hBuilder);
238: }
239:
240: if (values.getBoolean(SOAPCPP2)) {
241: ProcessBuilder soapcpp2Builder = new ProcessBuilder();
242: ArgumentBuilder soapcpp2Args = buildSoapcpp2Args();
243: soapcpp2Builder.command(soapcpp2Args.getArgs());
244: soapcpp2Builder.directory(new File(Tools.getDir(values
245: .get(WSDL2H_OUTPUT))));
246:
247: builders.add(soapcpp2Builder);
248: }
249:
250: if (builders.isEmpty())
251: UISupport.showErrorMessage("Nothing to run!");
252: else
253: toolHost.run(new ProcessToolRunner(builders
254: .toArray(new ProcessBuilder[builders.size()]),
255: "GSoap", modelItem));
256: }
257:
258: private ArgumentBuilder buildWsdl2HArgs(Interface modelItem) {
259: String gsoapDir = SoapUI.getSettings().getString(
260: ToolsSettings.GSOAP_LOCATION, null);
261: StringToStringMap values = dialog.getValues();
262: ArgumentBuilder builder = new ArgumentBuilder(values);
263: builder.startScript(gsoapDir + File.separator + "wsdl2h", "",
264: "");
265: builder.addArgs(new String[] { "-v" });
266:
267: values.put(WSDL2H_OUTPUT, Tools.getFilename(values
268: .get(WSDL2H_OUTPUT)));
269:
270: builder.addString(WSDL2H_OUTPUT, "-o", "");
271: builder.addArgs(getWsdlUrl(values, modelItem));
272:
273: builder.addBoolean(GENERATE_INDEXED_STRUCT, "-a");
274: builder.addBoolean(GENERATE_C_SOURCE, "-c");
275: builder.addBoolean(DOM, "-c");
276: builder.addBoolean(DONT_QUALIFY_ENUM_NAMES, "-e");
277: builder.addBoolean(FLAT_CPP_CLASS_HIERARCHY, "-f");
278: builder.addBoolean(GLOBAL_TOP_LEVEL_DECLARATIONS, "-g");
279: builder.addString(PATH, "-I", "");
280: builder.addBoolean(INCLUDE_LICENSE_INFORMATION, "-l");
281: builder.addBoolean(USE_XSD_H, "-m");
282: builder
283: .addString(BASE_NAMESPACE_PREFIX_INSTEAD_OF_NS, "-n",
284: "");
285: builder.addString(BASE_NAMESPACE_PREFIX_FOR_SERVICE_NS, "-N",
286: "");
287: builder.addBoolean(POLYMORPHIC_TYPES, "-p");
288: builder.addString(PROXY_HOST_PORT, "-r", "");
289: builder.addBoolean(NO_STL, "-s");
290: builder.addString(TYPE_MAP_FILE, "-t", "");
291: builder.addBoolean(NO_UNIONS, "-u");
292: builder.addBoolean(VERBOSE, "-v");
293: builder.addBoolean(WRAP_RESPONSE_STRUCT, "-w");
294: builder.addBoolean(NO_ANY, "-x");
295: builder.addBoolean(TYPEDEF_SYNONYMS, "-y");
296: return builder;
297: }
298:
299: private ArgumentBuilder buildSoapcpp2Args() {
300: String gsoapDir = SoapUI.getSettings().getString(
301: ToolsSettings.GSOAP_LOCATION, null);
302: StringToStringMap values = dialog.getValues();
303: ArgumentBuilder builder = new ArgumentBuilder(values);
304: builder.startScript(gsoapDir + File.separator + "soapcpp2", "",
305: "");
306: builder.addArgs(new String[] { "-Iimport",
307: values.get(WSDL2H_OUTPUT) });
308:
309: builder.addBoolean(SOAP_11, "-1");
310: builder.addBoolean(SOAP_12, "-2");
311: builder.addBoolean(CLIENT_SIDE, "-C");
312: builder.addBoolean(SERVER_SIDE, "-S");
313: builder.addBoolean(NO_LIB, "-L");
314: builder.addBoolean(SOAP_ACTION, "-a");
315: builder.addBoolean(GENERATE_C_SOURCE_CPP, "-c");
316: builder.addBoolean(SOAP_RPC, "-e");
317: builder.addBoolean(SERVICE_PROXIES, "-i");
318: builder.addString(IMPORT_PATH, "-I", "");
319: builder.addBoolean(GENERATE_LINKABLE_MODULES, "-l");
320: builder.addBoolean(GENERATE_MATLAB_CODE, "-m");
321: builder.addBoolean(SERVICE_NAME, "-n");
322: builder.addString(NAME_PREFIX, "-p", "");
323: builder.addBoolean(XSI_TYPED, "-t");
324: builder.addBoolean(NO_GEN_WSDL_SCHEMA, "-w");
325: builder.addBoolean(NO_GEN_SAMPLE_XML, "-x");
326:
327: return builder;
328: }
329: }
|