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;
14  
15  import java.io.File;
16  
17  import com.eviware.soapui.impl.wsdl.WsdlInterface;
18  import com.eviware.soapui.impl.wsdl.support.wsdl.CachedWsdlLoader;
19  import com.eviware.soapui.support.UISupport;
20  import com.eviware.soapui.support.action.support.AbstractSoapUIAction;
21  
22  /***
23   * Exports the definition (wsdls and xsds) of a WsdlInterface to the file system
24   * 
25   * @author Ole.Matzura
26   */
27  
28  public class ExportDefinitionAction extends AbstractSoapUIAction<WsdlInterface>
29  {
30     public static final String SOAPUI_ACTION_ID = "ExportDefinitionAction";
31  
32  	public ExportDefinitionAction()
33     {
34        super("Export Definition", "Exports the entire WSDL and included/imported files to a local directory");
35     }
36     
37     public void perform( WsdlInterface iface, Object param )
38  	{
39       	try
40  		{
41  			if( exportDefinition( null, iface ) != null )
42  				UISupport.showInfoMessage( "Definition exported succesfully" );
43  		}
44  		catch (Exception e1)
45  		{
46  			UISupport.showErrorMessage( e1 );
47  		}
48     }
49  
50  	public String exportDefinition( String location, WsdlInterface iface ) throws Exception
51  	{
52  		File folderName =location == null ? UISupport.getFileDialogs().openDirectory( this, "Select output directory", null ) 
53  				: new File( location );
54  		
55       	if( folderName == null )
56       		return null; 
57  		
58       	CachedWsdlLoader loader = null;
59       	
60       	if( iface.isCached() )
61       	{
62       		loader = (CachedWsdlLoader) iface.createWsdlLoader();
63       	}
64       	else
65       	{
66  			loader = new CachedWsdlLoader( iface.getDefinition() );
67       	}
68       	
69  		return loader.saveDefinition( folderName.getAbsolutePath() );
70  	} 
71  }