1
2
3
4
5
6
7
8
9
10
11
12
13 package com.eviware.soapui.impl.wsdl.panels.mockoperation.actions;
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.mock.WsdlMockResponse;
22 import com.eviware.soapui.settings.WsdlSettings;
23 import com.eviware.soapui.support.UISupport;
24
25 /***
26 * Recreates an SOAP response message for WsdlMockResponse from its WSDL/XSD
27 * definition
28 *
29 * @author ole.matzura
30 */
31
32 public class RecreateMockResponseAction extends AbstractAction
33 {
34 private final WsdlMockResponse mockResponse;
35
36 public RecreateMockResponseAction( WsdlMockResponse mockResponse )
37 {
38 super( "Recreate response" );
39 this.mockResponse = mockResponse;
40 putValue( Action.SMALL_ICON, UISupport.createImageIcon( "/recreate_request.gif" ) );
41 putValue( Action.SHORT_DESCRIPTION, "Recreates a default response from the schema" );
42 }
43
44 public void actionPerformed( ActionEvent arg0 )
45 {
46 WsdlOperation operation = mockResponse.getMockOperation().getOperation();
47 if( operation == null )
48 {
49 UISupport.showErrorMessage( "Missing operation for this mock response" );
50 return;
51 }
52
53 String response = mockResponse.getResponseContent();
54 if( response != null && response.trim().length() > 0
55 && !UISupport.confirm( "Overwrite current response?", "Recreate response" ) )
56 return;
57
58 boolean createOptional = mockResponse.getSettings().getBoolean(
59 WsdlSettings.XML_GENERATION_ALWAYS_INCLUDE_OPTIONAL_ELEMENTS );
60 if( !createOptional )
61 createOptional = UISupport.confirm( "Create optional elements in schema?", "Create Request" );
62
63 String req = operation.createResponse( createOptional );
64 if( req == null )
65 {
66 UISupport.showErrorMessage( "Response creation failed" );
67 return;
68 }
69
70 mockResponse.setResponseContent( req );
71 }
72
73 }