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.dotnet;
014:
015: import java.io.File;
016:
017: import com.eviware.soapui.SoapUI;
018: import com.eviware.soapui.impl.wsdl.actions.iface.tools.support.AbstractToolsAction;
019: import com.eviware.soapui.impl.wsdl.actions.iface.tools.support.ArgumentBuilder;
020: import com.eviware.soapui.impl.wsdl.actions.iface.tools.support.ProcessToolRunner;
021: import com.eviware.soapui.impl.wsdl.actions.iface.tools.support.ToolHost;
022: import com.eviware.soapui.impl.wsdl.support.HelpUrls;
023: import com.eviware.soapui.model.iface.Interface;
024: import com.eviware.soapui.settings.ToolsSettings;
025: import com.eviware.soapui.support.Tools;
026: import com.eviware.soapui.support.UISupport;
027: import com.eviware.soapui.support.types.StringToStringMap;
028: import com.eviware.x.form.XForm;
029: import com.eviware.x.form.XFormDialog;
030: import com.eviware.x.form.XFormDialogBuilder;
031: import com.eviware.x.form.XFormFactory;
032:
033: /**
034: * Invokes .NET wsdl.exe
035: *
036: * @author Ole.Matzura
037: */
038:
039: public class DotNetWsdlAction extends AbstractToolsAction<Interface> {
040: private static final String OUTPUT = "output directory";
041: private static final String LANGUAGE = "language";
042: private static final String SERVER = "serverInterface";
043: private static final String NAMESPACE = "namespace";
044: private static final String PROTOCOL = "protocol";
045:
046: private static final String SHARETYPES = "sharetypes";
047: private static final String FIELDS = "fields";
048: private static final String ORDER = "order";
049: private static final String ENABLEDATABINDING = "enableDataBinding";
050: private static final String URLKEY = "url key";
051: private static final String BASEURL = "base url";
052:
053: private static final String USERNAME = "username";
054: private static final String PASSWORD = "password";
055: private static final String DOMAIN = "domain";
056: private static final String PROXY = "proxy";
057: private static final String PROXYUSERNAME = "proxy username";
058: private static final String PROXYPASSWORD = "proxy password";
059: private static final String PROXYDOMAIN = "proxy domain";
060: public static final String SOAPUI_ACTION_ID = "DotNetWsdlAction";
061:
062: public DotNetWsdlAction() {
063: super (".NET 2.0 Artifacts",
064: "Generates .NET 2.0 artifacts using wsdl.exe");
065: }
066:
067: protected StringToStringMap initValues(Interface modelItem) {
068: StringToStringMap values = super .initValues(modelItem);
069: values.putIfMissing(LANGUAGE, "CS");
070: return values;
071: }
072:
073: protected XFormDialog buildDialog(Interface modelItem) {
074: XFormDialogBuilder builder = XFormFactory
075: .createDialogBuilder(".NET 2.0 artifacts");
076:
077: XForm mainForm = builder.createForm("Basic");
078: addWSDLFields(mainForm, modelItem);
079:
080: mainForm.addTextField(OUTPUT,
081: "root directory for generated files.",
082: XForm.FieldType.PROJECT_FOLDER);
083: mainForm.addTextField(NAMESPACE,
084: "The namespace for the generated proxy or template",
085: XForm.FieldType.TEXT);
086:
087: mainForm
088: .addCheckBox(
089: SERVER,
090: "(Generates interfaces for server-side implementation of an ASP.Net Web Service)");
091: mainForm.addComboBox(LANGUAGE, new String[] { "CS", "VB", "JS",
092: "VJS", "CPP" }, "add scope to deploy.wsdd");
093:
094: mainForm.addComboBox(PROTOCOL, new String[] { "SOAP", "SOAP12",
095: "HttpGet", "HttpPost" },
096: "override the default protocol to implement");
097:
098: XForm advForm = builder.createForm("Advanced");
099:
100: advForm.addCheckBox(SHARETYPES,
101: "(turns on type sharing feature)");
102: advForm.addCheckBox(FIELDS,
103: "(generate fields instead of properties)");
104: advForm
105: .addCheckBox(ORDER,
106: "(generate explicit order identifiers on particle members)");
107: advForm
108: .addCheckBox(ENABLEDATABINDING,
109: "(implement INotifyPropertyChanged interface on all generated types)");
110: advForm
111: .addTextField(
112: URLKEY,
113: "configuration key to use in the code generation to read the default URL value",
114: XForm.FieldType.URL);
115: advForm.addTextField(BASEURL,
116: "base url to use when calculating the url fragment",
117: XForm.FieldType.URL);
118:
119: XForm httpForm = builder.createForm("HTTP settings");
120: httpForm
121: .addTextField(USERNAME,
122: "username to access the WSDL-URI",
123: XForm.FieldType.TEXT);
124: httpForm
125: .addTextField(PASSWORD,
126: "password to access the WSDL-URI",
127: XForm.FieldType.TEXT);
128: httpForm.addTextField(DOMAIN, "domain to access the WSDL-URI",
129: XForm.FieldType.TEXT);
130: httpForm.addTextField(PROXY, "username to access the WSDL-URI",
131: XForm.FieldType.TEXT);
132: httpForm.addTextField(PROXYUSERNAME,
133: "proxy username to access the WSDL-URI",
134: XForm.FieldType.TEXT);
135: httpForm.addTextField(PROXYPASSWORD,
136: "proxy password to access the WSDL-URI",
137: XForm.FieldType.TEXT);
138: httpForm.addTextField(PROXYDOMAIN,
139: "proxy domain to access the WSDL-URI",
140: XForm.FieldType.TEXT);
141:
142: buildArgsForm(builder, false, "wsdl.exe");
143:
144: return builder.buildDialog(buildDefaultActions(
145: HelpUrls.DOTNET_HELP_URL, modelItem),
146: "Specify arguments for .NET 2 wsdl.exe",
147: UISupport.TOOL_ICON);
148: }
149:
150: protected void generate(StringToStringMap values,
151: ToolHost toolHost, Interface modelItem) throws Exception {
152: String dotnetDir = SoapUI.getSettings().getString(
153: ToolsSettings.DOTNET_WSDL_LOCATION, null);
154: if (Tools.isEmpty(dotnetDir)) {
155: UISupport
156: .showErrorMessage(".NET 2.0 wsdl.exe directory must be set in global preferences");
157: return;
158: }
159:
160: ProcessBuilder builder = new ProcessBuilder();
161: ArgumentBuilder args = buildArgs(values, modelItem);
162: builder.command(args.getArgs());
163: builder.directory(new File(dotnetDir));
164:
165: toolHost.run(new ProcessToolRunner(builder, ".NET wsdl.exe",
166: modelItem));
167: }
168:
169: private ArgumentBuilder buildArgs(StringToStringMap values,
170: Interface modelItem) {
171: values.put(OUTPUT, Tools.ensureDir(values.get(OUTPUT), ""));
172:
173: ArgumentBuilder builder = new ArgumentBuilder(values);
174: builder.addArgs("cmd.exe", "/C", "wsdl.exe", "/nologo",
175: "/verbose");
176:
177: builder.addString(NAMESPACE, "/namespace", ":");
178: builder.addString(OUTPUT, "/out", ":");
179: builder.addString(PROTOCOL, "/protocol", ":");
180: builder.addString(LANGUAGE, "/language", ":");
181:
182: builder.addBoolean(SERVER, "/serverInterface");
183: builder.addBoolean(SHARETYPES, "/sharetypes");
184: builder.addBoolean(FIELDS, "/fields");
185: builder.addBoolean(ORDER, "/order");
186: builder.addBoolean(ENABLEDATABINDING, "/enableDataBinding");
187:
188: builder.addString(URLKEY, "/appsettingurlkey", ":");
189: builder.addString(BASEURL, "/appsettingbaseurl", ":");
190:
191: builder.addString(USERNAME, "/username", ":");
192: builder.addString(PASSWORD, "/password", ":");
193: builder.addString(DOMAIN, "/domain", ":");
194: builder.addString(PROXY, "/proxy", ":");
195: builder.addString(PROXYUSERNAME, "/proxyusername", ":");
196: builder.addString(PROXYPASSWORD, "/proxypassword", ":");
197: builder.addString(PROXYDOMAIN, "/proxydomain", ":");
198:
199: addToolArgs(values, builder);
200:
201: builder.addArgs(getWsdlUrl(values, modelItem));
202:
203: return builder;
204: }
205: }
|