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.xmlbeans;
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.ModelItem;
024: import com.eviware.soapui.model.iface.Interface;
025: import com.eviware.soapui.model.project.Project;
026: import com.eviware.soapui.settings.ToolsSettings;
027: import com.eviware.soapui.settings.ToolsSupport;
028: import com.eviware.soapui.support.Tools;
029: import com.eviware.soapui.support.UISupport;
030: import com.eviware.soapui.support.types.StringToStringMap;
031: import com.eviware.x.form.XForm;
032: import com.eviware.x.form.XFormDialog;
033: import com.eviware.x.form.XFormDialogBuilder;
034: import com.eviware.x.form.XFormFactory;
035:
036: /**
037: * Generates XMLBeans for given interface
038: *
039: * @author Ole.Matzura
040: */
041:
042: public class XmlBeans2Action extends AbstractToolsAction<Interface> {
043: private final static String XSBTARGET = "class/xsb target";
044: private final static String SRCTARGET = "src target";
045: private final static String SRCONLY = "src only";
046: private final static String JARFILE = "out jar";
047: private final static String DOWNLOADS = "downloads";
048: private final static String NOUPA = "noupa";
049: private final static String NOPVR = "nopvr";
050: private final static String NOANN = "noann";
051: private final static String NOVDOC = "novdoc";
052: private final static String VERBOSE = "verbose";
053: private final static String JAVASOURCE = "javasource";
054: private final static String DEBUG = "debug";
055: private final static String ALLOWMDEF = "allowmdef";
056: private final static String CATALOG = "catalog file";
057: private final static String XSDCONFIG = "xsdconfig";
058: public static final String SOAPUI_ACTION_ID = "XmlBeans2Action";
059: private String output;
060:
061: public XmlBeans2Action() {
062: super ("XmlBeans Classes", "Generates XmlBeans classes");
063: }
064:
065: @Override
066: public boolean applies(ModelItem target) {
067: Interface iface = (Interface) target;
068: return !iface.getProject().hasNature(Project.JBOSSWS_NATURE_ID);
069: }
070:
071: protected StringToStringMap initValues(Interface modelItem) {
072: StringToStringMap values = super .initValues(modelItem);
073: if (output != null)
074: values.put(SRCTARGET, output);
075:
076: return values;
077: }
078:
079: protected XFormDialog buildDialog(Interface modelItem) {
080: XFormDialogBuilder builder = XFormFactory
081: .createDialogBuilder("XmlBeans Classes");
082:
083: XForm mainForm = builder.createForm("Basic");
084: addWSDLFields(mainForm, modelItem);
085:
086: mainForm.addTextField(XSBTARGET,
087: "Target directory for CLASS and XSB files",
088: XForm.FieldType.PROJECT_FOLDER);
089: mainForm.addTextField(SRCTARGET,
090: "Target directory for generated JAVA files",
091: XForm.FieldType.PROJECT_FOLDER);
092: mainForm
093: .addTextField(
094: JARFILE,
095: "The name of the output JAR that will contain the result of compilation",
096: XForm.FieldType.PROJECT_FILE);
097:
098: mainForm.addCheckBox(SRCONLY,
099: "(Do not compile JAVA files or jar the output)");
100: mainForm.addCheckBox(DOWNLOADS,
101: "(Permit network downloads for imports and includes)");
102: mainForm
103: .addCheckBox(NOUPA,
104: "(Do not enforce the unique particle attribution rule)");
105: mainForm
106: .addCheckBox(NOPVR,
107: "(Do not enforce the particle valid (restriction) rule)");
108: mainForm.addCheckBox(NOANN, "(Ignore annotations)");
109: mainForm
110: .addCheckBox(NOVDOC,
111: "(Do not validate contents of <documentation> elements)");
112: mainForm.addCheckBox(DEBUG, "(Compile with debug symbols)");
113:
114: mainForm
115: .addComboBox(JAVASOURCE, new String[] { "1.5", "1.4" },
116: "Generate Java source compatible for the specified Java version");
117:
118: mainForm
119: .addTextField(
120: ALLOWMDEF,
121: "Ignore multiple defs in given namespaces. Use ##local to specify the no-namespace in that list",
122: XForm.FieldType.TEXT);
123: mainForm.addTextField(CATALOG,
124: "Catalog file to use for resolving external entities",
125: XForm.FieldType.PROJECT_FILE);
126: mainForm
127: .addTextField(
128: XSDCONFIG,
129: "Path to .xsdconfig file containing type-mapping information",
130: XForm.FieldType.PROJECT_FILE);
131:
132: mainForm.addCheckBox(VERBOSE,
133: "(Print more informational messages)");
134:
135: buildArgsForm(builder, false, "scomp");
136:
137: return builder.buildDialog(buildDefaultActions(
138: HelpUrls.XMLBEANS_HELP_URL, modelItem),
139: "Specify arguments for XmlBeans 2.X scomp",
140: UISupport.TOOL_ICON);
141: }
142:
143: protected void generate(StringToStringMap values,
144: ToolHost toolHost, Interface modelItem) throws Exception {
145: String xbDir = SoapUI.getSettings().getString(
146: ToolsSettings.XMLBEANS_LOCATION, null);
147: if (Tools.isEmpty(xbDir)) {
148: UISupport
149: .showErrorMessage("XmlBeans location must be set in global preferences");
150: return;
151: }
152:
153: ProcessBuilder builder = new ProcessBuilder();
154: builder.command(buildArgs(modelItem).getArgs());
155: builder.directory(new File(xbDir + File.separatorChar + "bin"));
156:
157: toolHost.run(new ProcessToolRunner(builder, "XmlBeans",
158: modelItem));
159: }
160:
161: private ArgumentBuilder buildArgs(Interface modelItem) {
162: StringToStringMap values = dialog.getValues();
163: ArgumentBuilder builder = new ArgumentBuilder(values);
164:
165: values.put(XSBTARGET, Tools
166: .ensureDir(values.get(XSBTARGET), ""));
167: values.put(SRCTARGET, Tools
168: .ensureDir(values.get(SRCTARGET), ""));
169:
170: builder.startScript("scomp", ".cmd", "");
171:
172: builder.addString(XSBTARGET, "-d");
173: builder.addString(SRCTARGET, "-src");
174: builder.addString(JARFILE, "-out");
175:
176: builder.addBoolean(SRCONLY, "-srconly");
177: builder.addBoolean(DOWNLOADS, "-dl");
178: builder.addBoolean(NOUPA, "-noupa");
179: builder.addBoolean(NOPVR, "-nopvr");
180: builder.addBoolean(NOANN, "-noann");
181: builder.addBoolean(NOVDOC, "-novdoc");
182: builder.addBoolean(DEBUG, "-debug");
183:
184: builder.addString(JAVASOURCE, "-javasource");
185: builder.addString(ALLOWMDEF, "-allowmdef");
186: builder.addString(CATALOG, "-catalog");
187: builder.addBoolean(VERBOSE, "-verbose");
188:
189: String javac = ToolsSupport.getToolLocator().getJavacLocation(
190: false);
191:
192: if (javac != null) {
193: builder.addArgs("-compiler", javac + File.separatorChar
194: + "javac");
195: }
196: addToolArgs(values, builder);
197:
198: builder.addString(XSDCONFIG, null);
199: builder.addArgs(getWsdlUrl(values, modelItem));
200:
201: return builder;
202: }
203:
204: public void setOutput(String output) {
205: this.output = output;
206: }
207: }
|