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.jbossws;
014:
015: import java.io.File;
016: import java.io.IOException;
017:
018: import com.eviware.soapui.SoapUI;
019: import com.eviware.soapui.impl.wsdl.actions.iface.tools.support.AbstractToolsAction;
020: import com.eviware.soapui.impl.wsdl.actions.iface.tools.support.ArgumentBuilder;
021: import com.eviware.soapui.impl.wsdl.actions.iface.tools.support.ProcessToolRunner;
022: import com.eviware.soapui.impl.wsdl.actions.iface.tools.support.ToolHost;
023: import com.eviware.soapui.impl.wsdl.support.HelpUrls;
024: import com.eviware.soapui.model.iface.Interface;
025: import com.eviware.soapui.settings.ToolsSettings;
026: import com.eviware.soapui.support.Tools;
027: import com.eviware.soapui.support.UISupport;
028: import com.eviware.soapui.support.types.StringToStringMap;
029: import com.eviware.x.form.XForm;
030: import com.eviware.x.form.XFormDialog;
031: import com.eviware.x.form.XFormDialogBuilder;
032: import com.eviware.x.form.XFormFactory;
033:
034: /**
035: * Invokes JBossWS-specific JAX-WS WSImport
036: *
037: * @author Ole.Matzura
038: */
039:
040: public class JBossWSConsumeAction extends
041: AbstractToolsAction<Interface> {
042: private static final String PACKAGE = "Package";
043: private static final String OUTPUT = "Target Directory";
044: private static final String SOURCE_OUTPUT = "Source Directory";
045: private static final String WSDLLOCATION = "wsdlLocation";
046: private static final String BINDING_FILES = "Binding files";
047: private static final String KEEP = "Keep";
048: private static final String CATALOG = "Catalog";
049: private static final String STACKTRACE = "Stacktrace";
050: public static final String SOAPUI_ACTION_ID = "JBossWSConsumeAction";
051:
052: public JBossWSConsumeAction() {
053: super ("JBossWS JAX-WS Artifacts",
054: "Generates JAX-WS artifacts using JBossWS wsconsume");
055: }
056:
057: protected XFormDialog buildDialog(Interface modelItem) {
058: XFormDialogBuilder builder = XFormFactory
059: .createDialogBuilder("JBossWS JAX-WS Artifacts");
060:
061: XForm mainForm = builder.createForm("Basic");
062: addWSDLFields(mainForm, modelItem);
063:
064: mainForm.addTextField(OUTPUT,
065: "target directory for generated files.",
066: XForm.FieldType.PROJECT_FOLDER);
067: mainForm.addTextField(PACKAGE, "target package nam",
068: XForm.FieldType.JAVA_PACKAGE);
069: mainForm.addTextField(SOURCE_OUTPUT,
070: "target directory for generated source files",
071: XForm.FieldType.PROJECT_FOLDER);
072: mainForm.addTextField(CATALOG,
073: "catalog file to resolve external entity references",
074: XForm.FieldType.PROJECT_FILE);
075: mainForm
076: .addTextField(
077: BINDING_FILES,
078: "comma-separated list of external JAX-WS or JAXB binding files",
079: XForm.FieldType.TEXT);
080: mainForm
081: .addTextField(
082: WSDLLOCATION,
083: "@WebService.wsdlLocation and @WebServiceClient.wsdlLocation value",
084: XForm.FieldType.TEXT);
085:
086: mainForm.addCheckBox(KEEP, "(keep generated files)");
087: mainForm
088: .addCheckBox(STACKTRACE, "(show stacktrace for errors)");
089:
090: buildArgsForm(builder, false, "WSImport");
091:
092: return builder.buildDialog(buildDefaultActions(
093: HelpUrls.JBOSSWS_WSCONSUME_HELP_URL, modelItem),
094: "Specify arguments for JBossWS wsconsume",
095: UISupport.TOOL_ICON);
096: }
097:
098: protected void generate(StringToStringMap values,
099: ToolHost toolHost, Interface modelItem) throws Exception {
100: String wsimportDir = SoapUI.getSettings().getString(
101: ToolsSettings.JBOSSWS_WSTOOLS_LOCATION, null);
102: if (Tools.isEmpty(wsimportDir)) {
103: UISupport
104: .showErrorMessage("JBossWS wstools/wsconsume directory must be set in global preferences");
105: return;
106: }
107:
108: String wsimportExtension = UISupport.isWindows() ? ".bat"
109: : ".sh";
110:
111: File wscompileFile = new File(wsimportDir + File.separatorChar
112: + "wsconsume" + wsimportExtension);
113: if (!wscompileFile.exists()) {
114: UISupport
115: .showErrorMessage("Could not find wsconsume script at ["
116: + wscompileFile + "]");
117: return;
118: }
119:
120: ProcessBuilder builder = new ProcessBuilder();
121: ArgumentBuilder args = buildArgs(UISupport.isWindows(),
122: modelItem);
123: builder.command(args.getArgs());
124: builder.directory(new File(wsimportDir));
125:
126: toolHost.run(new ProcessToolRunner(builder,
127: "JBossWS wsconsume", modelItem));
128: }
129:
130: private ArgumentBuilder buildArgs(boolean isWindows,
131: Interface modelItem) throws IOException {
132: StringToStringMap values = dialog.getValues();
133: values.put(OUTPUT, Tools.ensureDir(values.get(OUTPUT), ""));
134: values.put(SOURCE_OUTPUT, Tools.ensureDir(values
135: .get(SOURCE_OUTPUT), values.get(OUTPUT)));
136:
137: ArgumentBuilder builder = new ArgumentBuilder(values);
138: builder.startScript("wsconsume");
139:
140: builder.addString(OUTPUT, "-d");
141: builder.addString(CATALOG, "-c");
142: builder.addString(PACKAGE, "-p");
143: builder.addString(SOURCE_OUTPUT, "-s");
144: builder.addString(WSDLLOCATION, "-w");
145: builder.addBoolean(KEEP, "-k");
146: builder.addBoolean(STACKTRACE, "-t");
147:
148: String[] bindingFiles = values.get(BINDING_FILES).split(",");
149: for (String file : bindingFiles) {
150: if (file.trim().length() > 0)
151: builder.addArgs("-b", file.trim());
152: }
153:
154: addToolArgs(values, builder);
155: builder.addArgs(getWsdlUrl(values, modelItem));
156:
157: return builder;
158: }
159: }
|