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.request;
    14
    15  import java.awt.event.ActionEvent;
    16
    17  import javax.swing.AbstractAction;
    18  import javax.swing.Action;
    19
    20  import com.eviware.soapui.impl.wsdl.WsdlOperation;
    21  import com.eviware.soapui.impl.wsdl.WsdlRequest;
    22  import com.eviware.soapui.settings.WsdlSettings;
    23  import com.eviware.soapui.support.UISupport;
    24  import com.eviware.soapui.support.xml.XmlUtils;
    25
    26  /***
    27   * Recreates a WsdlRequest from its WsdlOperations schema definition
    28   *
    29   * @author Ole.Matzura
    30   */
    31
    32  public class RecreateRequestAction extends AbstractAction
    33  {
    34     private final WsdlRequest request;
    35
    36  	public RecreateRequestAction( WsdlRequest request )
    37     {
    38        super( "Recreate request" );
    39  		this.request = request;
    40        putValue( Action.SMALL_ICON, UISupport.createImageIcon( "/recreate_request.gif"));
    41        putValue( Action.SHORT_DESCRIPTION, "Recreates a default request from the schema" );
    42     }
    43
    44     public void actionPerformed(ActionEvent e)
    45     {
    46  	   boolean createOptional = request.getSettings().getBoolean(WsdlSettings.XML_GENERATION_ALWAYS_INCLUDE_OPTIONAL_ELEMENTS);
    47        if (!createOptional)
    48        {
    49      	   Boolean create = UISupport.confirmOrCancel(	"Create optional elements in schema?", "Create Request" );
    50      	   if( create == null )
    51      	   	return;
    52
    53      	   createOptional = create.booleanValue();
    54        }
    55
    56        String req = ((WsdlOperation)request.getOperation()).createRequest( createOptional );
    57        if( req == null )
    58        {
    59        	UISupport.showErrorMessage( "Request creation failed" );
    60        	return;
    61        }
    62
    63        if( request.getRequestContent() != null && request.getRequestContent().trim().length() > 0 )
    64     	{
    65           if( UISupport.confirm( "Keep existing values", "Recreate Request" ))
    66           {
    67          		req = XmlUtils.transferValues( request.getRequestContent(), req );
    68           }
    69     	}
    70
    71        request.setRequestContent( req );
    72     }
    73  }