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.dotnet;
    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.iface.Interface;
    24  import com.eviware.soapui.settings.ToolsSettings;
    25  import com.eviware.soapui.support.Tools;
    26  import com.eviware.soapui.support.UISupport;
    27  import com.eviware.soapui.support.types.StringToStringMap;
    28  import com.eviware.x.form.XForm;
    29  import com.eviware.x.form.XFormDialog;
    30  import com.eviware.x.form.XFormDialogBuilder;
    31  import com.eviware.x.form.XFormFactory;
    32
    33  /***
    34   * Invokes .NET wsdl.exe
    35   *
    36   * @author Ole.Matzura
    37   */
    38
    39  public class DotNetWsdlAction extends AbstractToolsAction<Interface>
    40  {
    41  	private static final String OUTPUT = "output directory";
    42  	private static final String LANGUAGE = "language";
    43  	private static final String SERVER = "serverInterface";
    44  	private static final String NAMESPACE = "namespace";
    45  	private static final String PROTOCOL = "protocol";
    46
    47  	private static final String SHARETYPES = "sharetypes";
    48  	private static final String FIELDS = "fields";
    49  	private static final String ORDER = "order";
    50  	private static final String ENABLEDATABINDING = "enableDataBinding";
    51  	private static final String URLKEY = "url key";
    52  	private static final String BASEURL = "base url";
    53
    54  	private static final String USERNAME = "username";
    55  	private static final String PASSWORD = "password";
    56  	private static final String DOMAIN = "domain";
    57  	private static final String PROXY = "proxy";
    58  	private static final String PROXYUSERNAME = "proxy username";
    59  	private static final String PROXYPASSWORD = "proxy password";
    60  	private static final String PROXYDOMAIN = "proxy domain";
    61  	public static final String SOAPUI_ACTION_ID = "DotNetWsdlAction";
    62
    63     public DotNetWsdlAction()
    64     {
    65        super( ".NET 2.0 Artifacts", "Generates .NET 2.0 artifacts using wsdl.exe");
    66     }
    67
    68  	protected StringToStringMap initValues( Interface modelItem, Object param )
    69  	{
    70  		StringToStringMap values = super.initValues(modelItem, param);
    71  		values.putIfMissing( LANGUAGE, "CS" );
    72  		return values;
    73  	}
    74
    75  	protected XFormDialog buildDialog(Interface modelItem)
    76  	{
    77        XFormDialogBuilder builder = XFormFactory.createDialogBuilder(".NET 2.0 artifacts");
    78
    79        XForm mainForm = builder.createForm( "Basic" );
    80        addWSDLFields( mainForm, modelItem );
    81
    82  		mainForm.addTextField( OUTPUT, "root directory for generated files.", XForm.FieldType.PROJECT_FOLDER );
    83  		mainForm.addTextField( NAMESPACE, "The namespace for the generated proxy or template", XForm.FieldType.TEXT );
    84
    85  		mainForm.addCheckBox( SERVER, "(Generates interfaces for server-side implementation of an ASP.Net Web Service)" );
    86  		mainForm.addComboBox( LANGUAGE, new String[] { "CS", "VB", "JS", "VJS", "CPP" },
    87  			"add scope to deploy.wsdd");
    88
    89  		mainForm.addComboBox( PROTOCOL, new String[] { "SOAP", "SOAP12", "HttpGet", "HttpPost" },
    90  			"override the default protocol to implement" );
    91
    92  		XForm advForm = builder.createForm( "Advanced" );
    93
    94  		advForm.addCheckBox( SHARETYPES, "(turns on type sharing feature)" );
    95  		advForm.addCheckBox( FIELDS, "(generate fields instead of properties)" );
    96  		advForm.addCheckBox( ORDER, "(generate explicit order identifiers on particle members)" );
    97  		advForm.addCheckBox( ENABLEDATABINDING, "(implement INotifyPropertyChanged interface on all generated types)" );
    98  		advForm.addTextField( URLKEY, "configuration key to use in the code generation to read the default URL value", XForm.FieldType.URL );
    99  		advForm.addTextField( BASEURL, "base url to use when calculating the url fragment", XForm.FieldType.URL );
    100
    101 		XForm httpForm = builder.createForm( "HTTP settings" );
    102 		httpForm.addTextField( USERNAME, "username to access the WSDL-URI", XForm.FieldType.TEXT );
    103 		httpForm.addTextField( PASSWORD, "password to access the WSDL-URI", XForm.FieldType.TEXT );
    104 		httpForm.addTextField( DOMAIN, "domain to access the WSDL-URI", XForm.FieldType.TEXT );
    105 		httpForm.addTextField( PROXY, "username to access the WSDL-URI", XForm.FieldType.TEXT );
    106 		httpForm.addTextField( PROXYUSERNAME, "proxy username to access the WSDL-URI", XForm.FieldType.TEXT );
    107 		httpForm.addTextField( PROXYPASSWORD, "proxy password to access the WSDL-URI", XForm.FieldType.TEXT );
    108 		httpForm.addTextField( PROXYDOMAIN, "proxy domain to access the WSDL-URI", XForm.FieldType.TEXT );
    109
    110       buildArgsForm( builder, false, "wsdl.exe" );
    111
    112 		return builder.buildDialog( buildDefaultActions( HelpUrls.DOTNET_HELP_URL, modelItem ),
    113       		"Specify arguments for .NET 2 wsdl.exe", UISupport.TOOL_ICON );
    114 	}
    115
    116 	protected void generate(StringToStringMap values, ToolHost toolHost, Interface modelItem) throws Exception
    117 	{
    118 		String dotnetDir = SoapUI.getSettings().getString( ToolsSettings.DOTNET_WSDL_LOCATION, null );
    119 		if( Tools.isEmpty( dotnetDir ) )
    120 		{
    121 			UISupport.showErrorMessage( ".NET 2.0 wsdl.exe directory must be set in global preferences" );
    122 			return;
    123 		}
    124
    125 		ProcessBuilder builder = new ProcessBuilder();
    126 		ArgumentBuilder args = buildArgs( values, modelItem );
    127 		builder.command(args.getArgs());
    128 		builder.directory(new File(dotnetDir));
    129
    130 		toolHost.run( new ProcessToolRunner( builder, ".NET wsdl.exe", modelItem ));
    131 	}
    132
    133 	private ArgumentBuilder buildArgs(StringToStringMap values, Interface modelItem )
    134 	{
    135 		values.put( OUTPUT, Tools.ensureDir( values.get( OUTPUT ), "" ));
    136
    137 		ArgumentBuilder builder = new ArgumentBuilder( values );
    138 		builder.addArgs( "cmd.exe", "/C", "wsdl.exe", "/nologo", "/verbose" );
    139
    140 		builder.addString( NAMESPACE, "/namespace", ":" );
    141 		builder.addString( OUTPUT, "/out", ":" );
    142 		builder.addString( PROTOCOL, "/protocol", ":" );
    143 		builder.addString( LANGUAGE, "/language", ":" );
    144
    145 		builder.addBoolean( SERVER, "/serverInterface" );
    146 		builder.addBoolean( SHARETYPES, "/sharetypes" );
    147 		builder.addBoolean( FIELDS, "/fields" );
    148 		builder.addBoolean( ORDER, "/order" );
    149 		builder.addBoolean( ENABLEDATABINDING, "/enableDataBinding" );
    150
    151 		builder.addString( URLKEY, "/appsettingurlkey", ":" );
    152 		builder.addString( BASEURL, "/appsettingbaseurl", ":" );
    153
    154 		builder.addString( USERNAME, "/username", ":" );
    155 		builder.addString( PASSWORD, "/password", ":" );
    156 		builder.addString( DOMAIN, "/domain", ":" );
    157 		builder.addString( PROXY, "/proxy", ":" );
    158 		builder.addString( PROXYUSERNAME, "/proxyusername", ":" );
    159 		builder.addString( PROXYPASSWORD, "/proxypassword", ":" );
    160 		builder.addString( PROXYDOMAIN, "/proxydomain", ":" );
    161
    162 		addToolArgs( values, builder );
    163
    164 		builder.addArgs( getWsdlUrl( values, modelItem ) );
    165
    166 		return builder;
    167 	}
    168 }