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