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