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.axis1;
    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 axis 1.X WSDL2Java
    35   *
    36   * @author Ole.Matzura
    37   */
    38
    39  public class Axis1XWSDL2JavaAction extends AbstractToolsAction<Interface>
    40  {
    41  	private static final String NAMESPACE_MAPPING = "namespace mapping";
    42  	private static final String FACTORY = "factory";
    43  	private static final String OUTPUT = "output directory";
    44  	private static final String PACKAGE = "target package";
    45  	private static final String TYPE_MAPPING_VERSION = "typeMappingVersion";
    46  	private static final String DEPLOY_SCOPE = "deployScope";
    47  	private static final String SKELETON_DEPLOY = "skeletonDeploy";
    48  	private static final String WRAP_ARRAYS = "wrapArrays";
    49  	private static final String HELPER_GEN = "helperGen";
    50  	private static final String ALL = "all";
    51  	private static final String TEST_CASE = "testCase";
    52  	private static final String SERVER_SIDE = "server-side";
    53  	private static final String NO_WRAPPED = "noWrapped";
    54  	private static final String NO_IMPORTS = "noImports";
    55
    56  	private static final String IMPLCLASS = "implementationClassName";
    57  	private static final String USERNAME = "user";
    58  	private static final String PASSWORD = "password";
    59  	public static final String SOAPUI_ACTION_ID = "Axis1XWSDL2JavaAction";
    60
    61  	public Axis1XWSDL2JavaAction()
    62     {
    63        super("Axis 1.X Artifacts", "Generates Axis 1.X artifacts using WSDL2Java" );
    64     }
    65
    66  	protected StringToStringMap initValues( Interface iface, Object param )
    67  	{
    68  		StringToStringMap values = super.initValues( iface, param );
    69
    70        values.putIfMissing( SKELETON_DEPLOY, "none" );
    71        values.putIfMissing( DEPLOY_SCOPE, "none" );
    72        values.putIfMissing( TYPE_MAPPING_VERSION, "1.2" );
    73
    74  		return values;
    75  	}
    76
    77  	protected XFormDialog buildDialog( Interface modelItem )
    78  	{
    79        XFormDialogBuilder builder = XFormFactory.createDialogBuilder( "Axis 1.X WSDL2Java" );
    80
    81        XForm mainForm = builder.createForm( "Basic" );
    82  		addWSDLFields(mainForm, modelItem );
    83
    84  		mainForm.addTextField( OUTPUT, "The root directory for all emitted files.", XForm.FieldType.PROJECT_FOLDER );
    85  		mainForm.addCheckBox( SERVER_SIDE, "(emit server-side bindings for web service)" );
    86  		mainForm.addCheckBox( ALL, "(generate code for all elements, even unreferenced ones)" );
    87
    88  		mainForm.addComboBox( DEPLOY_SCOPE, new String[] { "none", "Application", "Session", "Request"},
    89  			"add scope to deploy.wsdd");
    90
    91  		mainForm.addComboBox( SKELETON_DEPLOY, new String[] { "none", "true", "false"},
    92  			"deploy skeleton (true) or implementation (false) in deploy.wsdd");
    93
    94  		mainForm.addCheckBox( NO_IMPORTS, "(only generate code for immediate WSDL document)" );
    95  		mainForm.addCheckBox( NO_WRAPPED, "(turn off support for \"wrapped\" document/literal)" );
    96  		mainForm.addCheckBox( TEST_CASE, "(emit junit testcase class for web service)" );
    97  		mainForm.addCheckBox( HELPER_GEN, "(emits separate Helper classes for meta data)" );
    98  		mainForm.addCheckBox( WRAP_ARRAYS, "(Prefer generating JavaBean classes for certain schema array patterns)" );
    99
    100       XForm advForm = builder.createForm( "Advanced" );
    101 		advForm.addComboBox( TYPE_MAPPING_VERSION, new String[] { "1.2", "1.1"},
    102 				"typeMapping version to use");
    103
    104 		advForm.addTextField( IMPLCLASS, "use this as the implementation class", XForm.FieldType.JAVA_CLASS );
    105 		advForm.addTextField( FACTORY, "the name of a class which extends JavaWriterFactory", XForm.FieldType.JAVA_CLASS );
    106
    107 		advForm.addTextField( PACKAGE, "maps all namespaces in a WSDL document to the same Java package name", XForm.FieldType.JAVA_PACKAGE );
    108       advForm.addNameSpaceTable( NAMESPACE_MAPPING, modelItem );
    109
    110 		advForm.addTextField( USERNAME, "username to access the WSDL-URI", XForm.FieldType.TEXT );
    111 		advForm.addTextField( PASSWORD, "password to access the WSDL-URI", XForm.FieldType.TEXT );
    112
    113       buildArgsForm( builder, true, "WSDL2Java" );
    114
    115       return builder.buildDialog( buildDefaultActions( HelpUrls.AXIS1X_HELP_URL, modelItem ),
    116       		"Specify arguments for Axis 1.X Wsdl2Java", UISupport.TOOL_ICON );
    117 	}
    118
    119 	protected void generate(StringToStringMap values, ToolHost toolHost, Interface modelItem ) throws Exception
    120 	{
    121 		String axisDir = SoapUI.getSettings().getString( ToolsSettings.AXIS_1_X_LOCATION, null );
    122 		if( Tools.isEmpty( axisDir ))
    123 		{
    124 			UISupport.showErrorMessage( "Axis 1.X location must be set in global preferences" );
    125 			return;
    126 		}
    127
    128 		File axisLibDir = new File( axisDir + File.separatorChar + "lib" );
    129 		if( !axisLibDir.exists() )
    130 		{
    131 			UISupport.showErrorMessage( "Could not find Axis 1.X lib directory [" + axisLibDir + "]" );
    132 			return;
    133 		}
    134
    135 		String classpath = buildClasspath(axisLibDir);
    136
    137 		ProcessBuilder builder = new ProcessBuilder();
    138 		ArgumentBuilder args = buildArgs(classpath, values, modelItem );
    139
    140 		builder.command( args.getArgs() );
    141 		builder.directory(axisLibDir);
    142
    143 		toolHost.run( new ProcessToolRunner( builder, "Axis 1.x wsdl2java", modelItem ) );
    144 	}
    145
    146 	private ArgumentBuilder buildArgs(String classpath, StringToStringMap values, Interface modelItem )
    147 	{
    148 		ArgumentBuilder builder = new ArgumentBuilder( values );
    149 		builder.addArgs( "java" );
    150
    151 		addJavaArgs( values, builder );
    152
    153 		builder.addArgs( "-cp", classpath, "org.apache.axis.wsdl.WSDL2Java", "-v" );
    154
    155 		builder.addBoolean( NO_IMPORTS, "-n" );
    156 		builder.addBoolean( NO_WRAPPED, "-W" );
    157 		builder.addBoolean( SERVER_SIDE, "-s" );
    158 		builder.addBoolean( TEST_CASE, "-t" );
    159 		builder.addBoolean( ALL, "-a" );
    160 		builder.addBoolean( HELPER_GEN, "-H" );
    161 		builder.addBoolean( WRAP_ARRAYS, "-w" );
    162
    163 		if( !values.get( SKELETON_DEPLOY ).equals( "none" ))
    164 			builder.addString( SKELETON_DEPLOY, "-S" );
    165
    166 		if( !values.get( DEPLOY_SCOPE ).equals( "none" ))
    167 			builder.addString( DEPLOY_SCOPE, "-d" );
    168
    169 		values.put( OUTPUT, Tools.ensureDir( values.get( OUTPUT )));
    170
    171 		builder.addString( TYPE_MAPPING_VERSION, "-T" );
    172 		builder.addString( PACKAGE, "-p" );
    173 		builder.addString( OUTPUT, "-o" );
    174 		builder.addString( FACTORY, "-F" );
    175 		builder.addString( IMPLCLASS, "-c" );
    176 		builder.addString( USERNAME, "-U" );
    177 		builder.addString( PASSWORD, "-P" );
    178
    179 		try
    180 		{
    181 			StringToStringMap nsMappings = StringToStringMap.fromXml(values.get(NAMESPACE_MAPPING));
    182 			for (String namespace : nsMappings.keySet())
    183 			{
    184 				builder.addArgs( "-N" + namespace + "=" + nsMappings.get(namespace));
    185 			}
    186 		}
    187 		catch (Exception e)
    188 		{
    189 			SoapUI.logError( e );
    190 		}
    191
    192 		addToolArgs( values, builder );
    193
    194 		builder.addArgs( getWsdlUrl( values, modelItem ) );
    195 		return builder;
    196 	}
    197 }