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 definition
27 *
28 * @author ole.matzura
29 */
30
31 public class RecreateMockResponseAction extends AbstractAction
32 {
33 private final WsdlMockResponse mockResponse;
34
35 public RecreateMockResponseAction( WsdlMockResponse mockResponse )
36 {
37 super( "Recreate response" );
38 this.mockResponse = mockResponse;
39 putValue( Action.SMALL_ICON, UISupport.createImageIcon( "/recreate_request.gif" ) );
40 putValue( Action.SHORT_DESCRIPTION, "Recreates a default response from the schema" );
41 }
42
43 public void actionPerformed( ActionEvent arg0 )
44 {
45 WsdlOperation operation = mockResponse.getMockOperation().getOperation();
46 if( operation == null )
47 {
48 UISupport.showErrorMessage( "Missing operation for this mock response" );
49 return;
50 }
51
52 String response = mockResponse.getResponseContent();
53 if( response != null && response.trim().length() > 0 &&
54 !UISupport.confirm( "Overwrite current response?", "Recreate response" ))
55 return;
56
57 boolean createOptional = mockResponse.getSettings().getBoolean(
58 WsdlSettings.XML_GENERATION_ALWAYS_INCLUDE_OPTIONAL_ELEMENTS );
59 if( !createOptional )
60 createOptional = UISupport.confirm( "Create optional elements in schema?",
61 "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 }