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.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: private final WsdlRequest request;
34:
35: public RecreateRequestAction(WsdlRequest request) {
36: super ("Recreate request");
37: this .request = request;
38: putValue(Action.SMALL_ICON, UISupport
39: .createImageIcon("/recreate_request.gif"));
40: putValue(Action.SHORT_DESCRIPTION,
41: "Recreates a default request from the schema");
42: }
43:
44: public void actionPerformed(ActionEvent e) {
45: boolean createOptional = request
46: .getSettings()
47: .getBoolean(
48: WsdlSettings.XML_GENERATION_ALWAYS_INCLUDE_OPTIONAL_ELEMENTS);
49: if (!createOptional) {
50: Boolean create = UISupport.confirmOrCancel(
51: "Create optional elements in schema?",
52: "Create Request");
53: if (create == null)
54: return;
55:
56: createOptional = create.booleanValue();
57: }
58:
59: String req = ((WsdlOperation) request.getOperation())
60: .createRequest(createOptional);
61: if (req == null) {
62: UISupport.showErrorMessage("Request creation failed");
63: return;
64: }
65:
66: if (request.getRequestContent() != null
67: && request.getRequestContent().trim().length() > 0) {
68: if (UISupport.confirm("Keep existing values",
69: "Recreate Request")) {
70: req = XmlUtils.transferValues(request
71: .getRequestContent(), req);
72: }
73: }
74:
75: request.setRequestContent(req);
76: }
77: }
|