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.actions;
14  
15  import java.io.File;
16  
17  import com.eviware.soapui.SoapUI;
18  import com.eviware.soapui.impl.WorkspaceImpl;
19  import com.eviware.soapui.impl.wsdl.WsdlProject;
20  import com.eviware.soapui.support.MessageSupport;
21  import com.eviware.soapui.support.UISupport;
22  import com.eviware.soapui.support.action.support.AbstractSoapUIAction;
23  
24  /***
25   * Actions for importing an existing soapUI project file into the current workspace
26   * 
27   * @author Ole.Matzura
28   */
29  
30  public class ImportWsdlProjectAction extends AbstractSoapUIAction<WorkspaceImpl>
31  {
32  	public static final String SOAPUI_ACTION_ID = "ImportWsdlProjectAction"; 
33  	public static final MessageSupport messages = MessageSupport.getMessages( ImportWsdlProjectAction.class );
34  
35  	public ImportWsdlProjectAction()
36     {
37        super( messages.get( "title"), messages.get( "description") ); 
38     }
39  
40  	public void perform( WorkspaceImpl workspace, Object param )
41  	{
42  		File file = null;
43  		
44  		if( param == null )
45  		{
46  			file = UISupport.getFileDialogs().openXML(this, messages.get( "prompt.title"));
47  		}
48  		else
49  		{
50  			file = new File( param.toString() );
51  		}
52  		
53        if( file == null ) return;
54        
55        String fileName = file.getAbsolutePath();
56        if( fileName == null ) return;
57        
58        ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
59     	Thread.currentThread().setContextClassLoader( SoapUI.class.getClassLoader() );
60     	
61  		try
62  		{
63  			WsdlProject project = (WsdlProject) workspace.importProject(fileName);
64  			if( project != null )
65  				UISupport.select(project);
66  		}
67  		catch (Exception ex)
68  		{
69  			UISupport.showErrorMessage( ex );
70  		}      
71  		finally
72     	{
73     		Thread.currentThread().setContextClassLoader( contextClassLoader );
74     	}
75     }
76  }