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.axis1;
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 axis 1.X WSDL2Java
035: *
036: * @author Ole.Matzura
037: */
038:
039: public class Axis1XWSDL2JavaAction extends
040: AbstractToolsAction<Interface> {
041: private static final String NAMESPACE_MAPPING = "namespace mapping";
042: private static final String FACTORY = "factory";
043: private static final String OUTPUT = "output directory";
044: private static final String PACKAGE = "target package";
045: private static final String TYPE_MAPPING_VERSION = "typeMappingVersion";
046: private static final String DEPLOY_SCOPE = "deployScope";
047: private static final String SKELETON_DEPLOY = "skeletonDeploy";
048: private static final String WRAP_ARRAYS = "wrapArrays";
049: private static final String HELPER_GEN = "helperGen";
050: private static final String ALL = "all";
051: private static final String TEST_CASE = "testCase";
052: private static final String SERVER_SIDE = "server-side";
053: private static final String NO_WRAPPED = "noWrapped";
054: private static final String NO_IMPORTS = "noImports";
055:
056: private static final String IMPLCLASS = "implementationClassName";
057: private static final String USERNAME = "user";
058: private static final String PASSWORD = "password";
059: public static final String SOAPUI_ACTION_ID = "Axis1XWSDL2JavaAction";
060:
061: public Axis1XWSDL2JavaAction() {
062: super ("Axis 1.X Artifacts",
063: "Generates Axis 1.X artifacts using WSDL2Java");
064: }
065:
066: protected StringToStringMap initValues(Interface iface) {
067: StringToStringMap values = super .initValues(iface);
068:
069: values.putIfMissing(SKELETON_DEPLOY, "none");
070: values.putIfMissing(DEPLOY_SCOPE, "none");
071: values.putIfMissing(TYPE_MAPPING_VERSION, "1.2");
072:
073: return values;
074: }
075:
076: protected XFormDialog buildDialog(Interface modelItem) {
077: XFormDialogBuilder builder = XFormFactory
078: .createDialogBuilder("Axis 1.X WSDL2Java");
079:
080: XForm mainForm = builder.createForm("Basic");
081: addWSDLFields(mainForm, modelItem);
082:
083: mainForm.addTextField(OUTPUT,
084: "The root directory for all emitted files.",
085: XForm.FieldType.PROJECT_FOLDER);
086: mainForm.addCheckBox(SERVER_SIDE,
087: "(emit server-side bindings for web service)");
088: mainForm
089: .addCheckBox(ALL,
090: "(generate code for all elements, even unreferenced ones)");
091:
092: mainForm.addComboBox(DEPLOY_SCOPE, new String[] { "none",
093: "Application", "Session", "Request" },
094: "add scope to deploy.wsdd");
095:
096: mainForm
097: .addComboBox(SKELETON_DEPLOY, new String[] { "none",
098: "true", "false" },
099: "deploy skeleton (true) or implementation (false) in deploy.wsdd");
100:
101: mainForm.addCheckBox(NO_IMPORTS,
102: "(only generate code for immediate WSDL document)");
103: mainForm.addCheckBox(NO_WRAPPED,
104: "(turn off support for \"wrapped\" document/literal)");
105: mainForm.addCheckBox(TEST_CASE,
106: "(emit junit testcase class for web service)");
107: mainForm.addCheckBox(HELPER_GEN,
108: "(emits separate Helper classes for meta data)");
109: mainForm
110: .addCheckBox(WRAP_ARRAYS,
111: "(Prefer generating JavaBean classes for certain schema array patterns)");
112:
113: XForm advForm = builder.createForm("Advanced");
114: advForm.addComboBox(TYPE_MAPPING_VERSION, new String[] { "1.2",
115: "1.1" }, "typeMapping version to use");
116:
117: advForm.addTextField(IMPLCLASS,
118: "use this as the implementation class",
119: XForm.FieldType.JAVA_CLASS);
120: advForm.addTextField(FACTORY,
121: "the name of a class which extends JavaWriterFactory",
122: XForm.FieldType.JAVA_CLASS);
123:
124: advForm
125: .addTextField(
126: PACKAGE,
127: "maps all namespaces in a WSDL document to the same Java package name",
128: XForm.FieldType.JAVA_PACKAGE);
129: advForm.addNameSpaceTable(NAMESPACE_MAPPING, modelItem);
130:
131: advForm
132: .addTextField(USERNAME,
133: "username to access the WSDL-URI",
134: XForm.FieldType.TEXT);
135: advForm
136: .addTextField(PASSWORD,
137: "password to access the WSDL-URI",
138: XForm.FieldType.TEXT);
139:
140: buildArgsForm(builder, true, "WSDL2Java");
141:
142: return builder.buildDialog(buildDefaultActions(
143: HelpUrls.AXIS1X_HELP_URL, modelItem),
144: "Specify arguments for Axis 1.X Wsdl2Java",
145: UISupport.TOOL_ICON);
146: }
147:
148: protected void generate(StringToStringMap values,
149: ToolHost toolHost, Interface modelItem) throws Exception {
150: String axisDir = SoapUI.getSettings().getString(
151: ToolsSettings.AXIS_1_X_LOCATION, null);
152: if (Tools.isEmpty(axisDir)) {
153: UISupport
154: .showErrorMessage("Axis 1.X location must be set in global preferences");
155: return;
156: }
157:
158: File axisLibDir = new File(axisDir + File.separatorChar + "lib");
159: if (!axisLibDir.exists()) {
160: UISupport
161: .showErrorMessage("Could not find Axis 1.X lib directory ["
162: + axisLibDir + "]");
163: return;
164: }
165:
166: String classpath = buildClasspath(axisLibDir);
167:
168: ProcessBuilder builder = new ProcessBuilder();
169: ArgumentBuilder args = buildArgs(classpath, values, modelItem);
170:
171: builder.command(args.getArgs());
172: builder.directory(axisLibDir);
173:
174: toolHost.run(new ProcessToolRunner(builder,
175: "Axis 1.x wsdl2java", modelItem));
176: }
177:
178: private ArgumentBuilder buildArgs(String classpath,
179: StringToStringMap values, Interface modelItem) {
180: ArgumentBuilder builder = new ArgumentBuilder(values);
181: builder.addArgs("java");
182:
183: addJavaArgs(values, builder);
184:
185: builder.addArgs("-cp", classpath,
186: "org.apache.axis.wsdl.WSDL2Java", "-v");
187:
188: builder.addBoolean(NO_IMPORTS, "-n");
189: builder.addBoolean(NO_WRAPPED, "-W");
190: builder.addBoolean(SERVER_SIDE, "-s");
191: builder.addBoolean(TEST_CASE, "-t");
192: builder.addBoolean(ALL, "-a");
193: builder.addBoolean(HELPER_GEN, "-H");
194: builder.addBoolean(WRAP_ARRAYS, "-w");
195:
196: if (!values.get(SKELETON_DEPLOY).equals("none"))
197: builder.addString(SKELETON_DEPLOY, "-S");
198:
199: if (!values.get(DEPLOY_SCOPE).equals("none"))
200: builder.addString(DEPLOY_SCOPE, "-d");
201:
202: values.put(OUTPUT, Tools.ensureDir(values.get(OUTPUT)));
203:
204: builder.addString(TYPE_MAPPING_VERSION, "-T");
205: builder.addString(PACKAGE, "-p");
206: builder.addString(OUTPUT, "-o");
207: builder.addString(FACTORY, "-F");
208: builder.addString(IMPLCLASS, "-c");
209: builder.addString(USERNAME, "-U");
210: builder.addString(PASSWORD, "-P");
211:
212: try {
213: StringToStringMap nsMappings = StringToStringMap
214: .fromXml(values.get(NAMESPACE_MAPPING));
215: for (String namespace : nsMappings.keySet()) {
216: builder.addArgs("-N" + namespace + "="
217: + nsMappings.get(namespace));
218: }
219: } catch (Exception e) {
220: SoapUI.logError(e);
221: }
222:
223: addToolArgs(values, builder);
224:
225: builder.addArgs(getWsdlUrl(values, modelItem));
226: return builder;
227: }
228: }
|