View Javadoc

    1   /*
    2    *  soapUI, copyright (C) 2004-2007 eviware.com
    3    *
    4    *  soapUI is free software; you can redistribute it and/or modify it under the
    5    *  terms of version 2.1 of the GNU Lesser General Public License as published by
    6    *  the Free Software Foundation.
    7    *
    8    *  soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
    9    *  even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    10   *  See the GNU Lesser General Public License for more details at gnu.org.
    11   */
    12
    13  package com.eviware.soapui.impl.wsdl.actions.iface.tools.xmlbeans;
    14
    15  import java.io.File;
    16
    17  import com.eviware.soapui.SoapUI;
    18  import com.eviware.soapui.impl.wsdl.actions.iface.tools.support.AbstractToolsAction;
    19  import com.eviware.soapui.impl.wsdl.actions.iface.tools.support.ArgumentBuilder;
    20  import com.eviware.soapui.impl.wsdl.actions.iface.tools.support.ProcessToolRunner;
    21  import com.eviware.soapui.impl.wsdl.actions.iface.tools.support.ToolHost;
    22  import com.eviware.soapui.impl.wsdl.support.HelpUrls;
    23  import com.eviware.soapui.model.ModelItem;
    24  import com.eviware.soapui.model.iface.Interface;
    25  import com.eviware.soapui.model.project.Project;
    26  import com.eviware.soapui.settings.ToolsSettings;
    27  import com.eviware.soapui.settings.ToolsSupport;
    28  import com.eviware.soapui.support.Tools;
    29  import com.eviware.soapui.support.UISupport;
    30  import com.eviware.soapui.support.types.StringToStringMap;
    31  import com.eviware.x.form.XForm;
    32  import com.eviware.x.form.XFormDialog;
    33  import com.eviware.x.form.XFormDialogBuilder;
    34  import com.eviware.x.form.XFormFactory;
    35
    36  /***
    37   * Generates XMLBeans for given interface
    38   *
    39   * @author Ole.Matzura
    40   */
    41
    42  public class XmlBeans2Action extends AbstractToolsAction<Interface>
    43  {
    44  	private final static String XSBTARGET = "class/xsb target";
    45  	private final static String SRCTARGET = "src target";
    46  	private final static String SRCONLY = "src only";
    47  	private final static String JARFILE = "out jar";
    48  	private final static String DOWNLOADS = "downloads";
    49  	private final static String NOUPA = "noupa";
    50  	private final static String NOPVR = "nopvr";
    51  	private final static String NOANN = "noann";
    52  	private final static String NOVDOC = "novdoc";
    53  	private final static String VERBOSE = "verbose";
    54  	private final static String JAVASOURCE = "javasource";
    55  	private final static String DEBUG = "debug";
    56  	private final static String ALLOWMDEF = "allowmdef";
    57  	private final static String CATALOG = "catalog file";
    58  	private final static String XSDCONFIG = "xsdconfig";
    59  	public static final String SOAPUI_ACTION_ID = "XmlBeans2Action";
    60  	private String output;
    61
    62     public XmlBeans2Action()
    63     {
    64        super( "XmlBeans Classes", "Generates XmlBeans classes");
    65     }
    66
    67     @Override
    68     public boolean applies( ModelItem target )
    69     {
    70        Interface iface = (Interface) target;
    71        return !iface.getProject().hasNature(Project.JBOSSWS_NATURE_ID);
    72     }
    73
    74  	protected StringToStringMap initValues(Interface modelItem)
    75  	{
    76  		StringToStringMap values = super.initValues(modelItem);
    77  		if( output != null )
    78  			values.put( SRCTARGET, output );
    79
    80  		return values;
    81  	}
    82
    83  	protected XFormDialog buildDialog(Interface modelItem)
    84  	{
    85        XFormDialogBuilder builder = XFormFactory.createDialogBuilder("XmlBeans Classes");
    86
    87  		XForm mainForm = builder.createForm( "Basic" );
    88  		addWSDLFields( mainForm, modelItem  );
    89
    90  		mainForm.addTextField( XSBTARGET, "Target directory for CLASS and XSB files", XForm.FieldType.PROJECT_FOLDER );
    91  		mainForm.addTextField( SRCTARGET, "Target directory for generated JAVA files", XForm.FieldType.PROJECT_FOLDER );
    92  		mainForm.addTextField( JARFILE, "The name of the output JAR that will contain the result of compilation", XForm.FieldType.PROJECT_FILE );
    93
    94  		mainForm.addCheckBox( SRCONLY, "(Do not compile JAVA files or jar the output)" );
    95  		mainForm.addCheckBox( DOWNLOADS, "(Permit network downloads for imports and includes)" );
    96  		mainForm.addCheckBox( NOUPA, "(Do not enforce the unique particle attribution rule)" );
    97  		mainForm.addCheckBox( NOPVR, "(Do not enforce the particle valid (restriction) rule)" );
    98  		mainForm.addCheckBox( NOANN, "(Ignore annotations)" );
    99  		mainForm.addCheckBox( NOVDOC, "(Do not validate contents of <documentation> elements)" );
    100 		mainForm.addCheckBox( DEBUG, "(Compile with debug symbols)" );
    101
    102 		mainForm.addComboBox( JAVASOURCE, new String[] {"1.5", "1.4" }, "Generate Java source compatible for the specified Java version" );
    103
    104 		mainForm.addTextField( ALLOWMDEF, "Ignore multiple defs in given namespaces. Use  ##local  to specify the no-namespace in that list", XForm.FieldType.TEXT );
    105 		mainForm.addTextField( CATALOG, "Catalog file to use for resolving external entities", XForm.FieldType.PROJECT_FILE );
    106 		mainForm.addTextField( XSDCONFIG, "Path to .xsdconfig file containing type-mapping information", XForm.FieldType.PROJECT_FILE );
    107
    108 		mainForm.addCheckBox( VERBOSE, "(Print more informational messages)" );
    109
    110       buildArgsForm( builder, false, "scomp");
    111
    112 		return builder.buildDialog( buildDefaultActions(HelpUrls.XMLBEANS_HELP_URL, modelItem ),
    113       		"Specify arguments for XmlBeans 2.X scomp", UISupport.TOOL_ICON );
    114 	}
    115
    116 	protected void generate(StringToStringMap values, ToolHost toolHost, Interface modelItem) throws Exception
    117 	{
    118 		String xbDir = SoapUI.getSettings().getString( ToolsSettings.XMLBEANS_LOCATION, null );
    119 		if( Tools.isEmpty( xbDir ))
    120 		{
    121 			UISupport.showErrorMessage( "XmlBeans location must be set in global preferences" );
    122 			return;
    123 		}
    124
    125 		ProcessBuilder builder = new ProcessBuilder();
    126 		builder.command( buildArgs( modelItem ).getArgs() );
    127 		builder.directory( new File( xbDir + File.separatorChar + "bin" ));
    128
    129 		toolHost.run( new ProcessToolRunner( builder, "XmlBeans", modelItem ));
    130 	}
    131
    132 	private ArgumentBuilder buildArgs(Interface modelItem)
    133 	{
    134 		StringToStringMap values = dialog.getValues();
    135 		ArgumentBuilder builder = new ArgumentBuilder( values );
    136
    137 		values.put( XSBTARGET, Tools.ensureDir( values.get( XSBTARGET ), "" ));
    138 		values.put( SRCTARGET, Tools.ensureDir( values.get( SRCTARGET ), "" ));
    139
    140 		builder.startScript( "scomp", ".cmd", "" );
    141
    142 		builder.addString( XSBTARGET, "-d" );
    143 		builder.addString( SRCTARGET, "-src" );
    144 		builder.addString( JARFILE, "-out" );
    145
    146 		builder.addBoolean( SRCONLY, "-srconly" );
    147 		builder.addBoolean( DOWNLOADS, "-dl" );
    148 		builder.addBoolean( NOUPA, "-noupa" );
    149 		builder.addBoolean( NOPVR, "-nopvr" );
    150 		builder.addBoolean( NOANN, "-noann" );
    151 		builder.addBoolean( NOVDOC, "-novdoc" );
    152 		builder.addBoolean( DEBUG, "-debug" );
    153
    154 		builder.addString( JAVASOURCE, "-javasource" );
    155 		builder.addString( ALLOWMDEF, "-allowmdef" );
    156 		builder.addString( CATALOG, "-catalog" );
    157 		builder.addBoolean( VERBOSE, "-verbose" );
    158
    159       String javac = ToolsSupport.getToolLocator().getJavacLocation(false);
    160
    161 		if( javac != null )
    162 		{
    163 			builder.addArgs( "-compiler", javac + File.separatorChar + "javac" );
    164 		}
    165 		addToolArgs( values, builder );
    166
    167 		builder.addString( XSDCONFIG, null );
    168 		builder.addArgs( getWsdlUrl( values, modelItem ) );
    169
    170 		return builder;
    171 	}
    172
    173 	public void setOutput(String output)
    174 	{
    175 		this.output = output;
    176 	}
    177 }