View Javadoc

1   /*
2    *  soapUI, copyright (C) 2004-2009 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.project;
14  
15  import java.io.File;
16  
17  import com.eviware.soapui.impl.WsdlInterfaceFactory;
18  import com.eviware.soapui.impl.wsdl.WsdlProject;
19  import com.eviware.soapui.model.iface.Interface;
20  import com.eviware.soapui.model.propertyexpansion.resolvers.providers.ProjectDirProvider;
21  import com.eviware.soapui.support.UISupport;
22  import com.eviware.soapui.support.action.support.AbstractSoapUIAction;
23  
24  /***
25   * Adds a WsdlInterface to a WsdlProject from a wsdl file
26   * 
27   * @author Ole.Matzura
28   */
29  
30  public class AddInterfaceActionFromFile extends AbstractSoapUIAction<WsdlProject>
31  {
32  	public static final String SOAPUI_ACTION_ID = "AddInterfaceActionFromFile";
33  
34  	public AddInterfaceActionFromFile()
35  	{
36  		super( "Add WSDL from File", "Adds all interfaces in a specified local WSDL file to the current project" );
37  	}
38  
39  	public void perform( WsdlProject project, Object param )
40  	{
41  		File file = UISupport.getFileDialogs().open( this, "Select WSDL file", ".wsdl", "WSDL Files (*.wsdl)",
42  				ProjectDirProvider.getProjectFolder( project ) );
43  		if( file == null )
44  			return;
45  
46  		String path = file.getAbsolutePath();
47  		if( path == null )
48  			return;
49  
50  		try
51  		{
52  			Boolean createRequests = UISupport.confirmOrCancel( "Create default requests for all operations",
53  					"Import WSDL" );
54  			if( createRequests == null )
55  				return;
56  
57  			Interface[] ifaces = WsdlInterfaceFactory
58  					.importWsdl( project, file.toURI().toURL().toString(), createRequests );
59  			if( ifaces.length > 0 )
60  				UISupport.select( ifaces[0] );
61  		}
62  		catch( Exception ex )
63  		{
64  			UISupport.showErrorMessage( ex.getMessage() + ":" + ex.getCause() );
65  		}
66  	}
67  }