View Javadoc

1   /*
2    *  soapUI, copyright (C) 2004-2008 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.oracle;
14  
15  import java.io.File;
16  import java.io.IOException;
17  
18  import com.eviware.soapui.SoapUI;
19  import com.eviware.soapui.impl.wsdl.actions.iface.tools.support.AbstractToolsAction;
20  import com.eviware.soapui.impl.wsdl.actions.iface.tools.support.ArgumentBuilder;
21  import com.eviware.soapui.impl.wsdl.actions.iface.tools.support.ProcessToolRunner;
22  import com.eviware.soapui.impl.wsdl.actions.iface.tools.support.ToolHost;
23  import com.eviware.soapui.impl.wsdl.support.HelpUrls;
24  import com.eviware.soapui.model.iface.Interface;
25  import com.eviware.soapui.settings.ToolsSettings;
26  import com.eviware.soapui.support.Tools;
27  import com.eviware.soapui.support.UISupport;
28  import com.eviware.soapui.support.action.swing.ActionList;
29  import com.eviware.soapui.support.types.StringToStringMap;
30  import com.eviware.x.form.XForm;
31  import com.eviware.x.form.XFormDialog;
32  import com.eviware.x.form.XFormDialogBuilder;
33  import com.eviware.x.form.XFormFactory;
34  
35  /***
36   * Invokes oracle genproxy
37   * 
38   * @author Ole.Matzura
39   */
40  
41  public class OracleWsaGenProxyAction extends AbstractToolsAction<Interface>
42  {
43  	private static final String OUTPUT = "Output Directory";
44  	private static final String PACKAGE = "Destination Package";
45  	public static final String SOAPUI_ACTION_ID = "OracleWsaGenProxyAction";
46  	
47     public OracleWsaGenProxyAction()
48     {
49        super( "Oracle Proxy Artifacts", "Generates Oracle Proxy artifacts using the wsa.jar utility");
50     }
51  
52     protected XFormDialog buildDialog( Interface modelItem )
53  	{
54        XFormDialogBuilder builder = XFormFactory.createDialogBuilder("Oracle Artifacts");
55  
56  		XForm mainForm = builder.createForm( "Basic" );
57  		addWSDLFields( mainForm, modelItem );
58  		
59  		mainForm.addTextField( OUTPUT, "The root directory for all emitted files.", XForm.FieldType.PROJECT_FOLDER );
60  		mainForm.addTextField( PACKAGE, "The target package for generated classes", XForm.FieldType.JAVA_PACKAGE );
61  
62        buildArgsForm( builder, true, "wsa" );
63        
64  		ActionList actions = buildDefaultActions(HelpUrls.ORACLEWSA_HELP_URL, modelItem);
65  		return builder.buildDialog( actions,
66        		"Specify arguments for Oracle wsa.jar genProxy functionality", UISupport.TOOL_ICON );
67  	}
68     
69  	protected void generate(StringToStringMap values, ToolHost toolHost, Interface modelItem) throws Exception
70  	{
71  		String wsaDir = SoapUI.getSettings().getString( ToolsSettings.ORACLE_WSA_LOCATION, null );
72  		if( Tools.isEmpty( wsaDir ))
73  		{
74  			UISupport.showErrorMessage( "wsa.jar directory must be set in global preferences" );
75  			return;
76  		}
77  		
78  		File wsaFile = new File( wsaDir + File.separatorChar + "wsa.jar" );
79  		if( !wsaFile.exists() )
80  		{
81  			UISupport.showErrorMessage( "Could not find wsa.jar at [" + wsaFile + "]" );
82  			return;
83  		}
84  		
85  		ProcessBuilder builder = new ProcessBuilder();
86  		ArgumentBuilder args = buildArgs(modelItem);
87  		builder.command(args.getArgs());
88  		builder.directory(new File(wsaDir));
89  		
90  		toolHost.run( new ProcessToolRunner( builder, "Oracle wsa.jar", modelItem ));
91  	}
92  
93  	private ArgumentBuilder buildArgs(Interface modelItem) throws IOException
94  	{
95  		StringToStringMap values = dialog.getValues();
96  		
97  		values.put( OUTPUT, Tools.ensureDir( values.get( OUTPUT ), "" ));
98  		
99  		ArgumentBuilder builder = new ArgumentBuilder( values );
100 		builder.addArgs( "java", "-jar", "wsa.jar", "-genProxy" );
101 		addJavaArgs( values, builder );
102 		
103 		builder.addArgs( "-wsdl", getWsdlUrl( values, modelItem ) );
104 		builder.addString( OUTPUT, "-output" );
105 		builder.addString( PACKAGE, "-packageName" );
106 		
107 		addToolArgs( values, builder );
108 		return builder;
109 	}
110 }