01: /*
02: * soapUI, copyright (C) 2004-2007 eviware.com
03: *
04: * soapUI is free software; you can redistribute it and/or modify it under the
05: * terms of version 2.1 of the GNU Lesser General Public License as published by
06: * the Free Software Foundation.
07: *
08: * soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
09: * 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.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: private final WsdlMockResponse mockResponse;
33:
34: public RecreateMockResponseAction(WsdlMockResponse mockResponse) {
35: super ("Recreate response");
36: this .mockResponse = mockResponse;
37: putValue(Action.SMALL_ICON, UISupport
38: .createImageIcon("/recreate_request.gif"));
39: putValue(Action.SHORT_DESCRIPTION,
40: "Recreates a default response from the schema");
41: }
42:
43: public void actionPerformed(ActionEvent arg0) {
44: WsdlOperation operation = mockResponse.getMockOperation()
45: .getOperation();
46: if (operation == null) {
47: UISupport
48: .showErrorMessage("Missing operation for this mock response");
49: return;
50: }
51:
52: String response = mockResponse.getResponseContent();
53: if (response != null
54: && response.trim().length() > 0
55: && !UISupport.confirm("Overwrite current response?",
56: "Recreate response"))
57: return;
58:
59: boolean createOptional = mockResponse
60: .getSettings()
61: .getBoolean(
62: WsdlSettings.XML_GENERATION_ALWAYS_INCLUDE_OPTIONAL_ELEMENTS);
63: if (!createOptional)
64: createOptional = UISupport.confirm(
65: "Create optional elements in schema?",
66: "Create Request");
67:
68: String req = operation.createResponse(createOptional);
69: if (req == null) {
70: UISupport.showErrorMessage("Response creation failed");
71: return;
72: }
73:
74: mockResponse.setResponseContent(req);
75: }
76:
77: }
|