1
2
3
4
5
6
7
8
9
10
11
12
13 package com.eviware.soapui.impl.wsdl;
14
15 import java.util.ArrayList;
16 import java.util.List;
17
18 import javax.swing.ImageIcon;
19 import javax.swing.JOptionPane;
20 import javax.wsdl.BindingOperation;
21 import javax.wsdl.Definition;
22
23 import com.eviware.soapui.SoapUI;
24 import com.eviware.soapui.config.CallConfig;
25 import com.eviware.soapui.config.OperationConfig;
26 import com.eviware.soapui.impl.wsdl.actions.operation.NewRequestAction;
27 import com.eviware.soapui.impl.wsdl.actions.operation.RelabelOperationAction;
28 import com.eviware.soapui.impl.wsdl.panels.operation.WsdlOperationPanelBuilder;
29 import com.eviware.soapui.impl.wsdl.support.SoapRequestBuilder;
30 import com.eviware.soapui.model.PanelBuilder;
31 import com.eviware.soapui.model.iface.Interface;
32 import com.eviware.soapui.model.iface.Operation;
33 import com.eviware.soapui.model.iface.Request;
34 import com.eviware.soapui.model.tree.SoapUITreeNode;
35 import com.eviware.soapui.model.tree.nodes.OperationTreeNode;
36
37 /***
38 * WSDL implementation of Operation, maps to a WSDL BindingOperation
39 *
40 * @author Ole.Matzura
41 */
42
43 public class WsdlOperation extends AbstractWsdlModelItem implements Operation
44 {
45 private OperationConfig operationConfig;
46 private List<WsdlRequest> requests = new ArrayList<WsdlRequest>();
47 private WsdlInterface iface;
48 private ImageIcon operationIcon;
49 private PanelBuilder wsdlOperationPanelBuilder;
50
51 public WsdlOperation( WsdlInterface iface, OperationConfig operationConfig )
52 {
53 this.iface = iface;
54 this.operationConfig = operationConfig;
55
56 CallConfig[] requestConfigs = operationConfig.getCallArray();
57 for (int i = 0; i < requestConfigs.length; i++)
58 {
59 requests.add( new WsdlRequest( this, requestConfigs[i] ));
60 }
61
62 addAction( new NewRequestAction( this ));
63 addAction( new RelabelOperationAction( this ));
64
65 operationIcon = SoapUI.createImageIcon("/operation.gif");
66 wsdlOperationPanelBuilder = new WsdlOperationPanelBuilder( this );
67 }
68
69 public String getAction()
70 {
71 return operationConfig.getAction();
72 }
73
74 public Request getRequestAt(int index)
75 {
76 return requests.get( index );
77 }
78
79 public int getRequestCount()
80 {
81 return requests.size();
82 }
83
84 public String getName()
85 {
86 return operationConfig.getName();
87 }
88
89 public void setName(String name)
90 {
91 String old = getName();
92 operationConfig.setName( name );
93 notifyPropertyChanged( NAME_PROPERTY, old, name );
94 }
95
96 public WsdlRequest addNewRequest( String name )
97 {
98 WsdlRequest requestImpl = new WsdlRequest( this, operationConfig.addNewCall() );
99 requestImpl.setName( name );
100 requests.add( requestImpl );
101 ((WsdlInterface)getInterface()).notifyRequestAdded( requestImpl );
102 return requestImpl;
103 }
104
105 public Interface getInterface()
106 {
107 return iface;
108 }
109
110 public OperationConfig getOperationConfig()
111 {
112 return operationConfig;
113 }
114
115 public void setAction(String soapAction)
116 {
117 String old = getAction();
118 operationConfig.setAction( soapAction );
119 notifyPropertyChanged( ACTION_PROPERTY, old, soapAction );
120 }
121
122 public String createRequest( boolean buildOptional )
123 {
124 if( iface.getBindingName() == null )
125 {
126 JOptionPane.showMessageDialog( SoapUI.getInstance().getFrame(), "Missing binding name, refresh " +
127 "Interface\nfor request generation to work correctly",
128 "Create Request", JOptionPane.ERROR_MESSAGE );
129 return null;
130 }
131
132 if( getBindingOperationName() == null )
133 {
134 JOptionPane.showMessageDialog( SoapUI.getInstance().getFrame(), "Missing bindingOperation name, refresh " +
135 "Interface\nfor request generation to work correctly",
136 "Create Request", JOptionPane.ERROR_MESSAGE);
137 return null;
138 }
139
140 try
141 {
142 SoapRequestBuilder builder = (SoapRequestBuilder) iface.getRequestBuilder();
143 return builder.buildSoapRequest( findBindingOperation( iface.getWsdlContext().getDefinition() ), buildOptional );
144 }
145 catch (Exception e)
146 {
147 e.printStackTrace();
148 return null;
149 }
150 }
151
152 public BindingOperation findBindingOperation(Definition definition)
153 {
154 return definition.getBinding( iface.getBindingName() ).getBindingOperation(
155 operationConfig.getBindingOperationName(), null, null );
156 }
157
158 public void removeRequest( WsdlRequest request )
159 {
160 ((WsdlInterface)getInterface()).notifyRequestRemoved( request );
161
162 request.release();
163
164 int ix = requests.indexOf( request );
165 requests.remove( ix );
166 operationConfig.removeCall( ix );
167 }
168
169 public String getBindingOperationName()
170 {
171 return operationConfig.getBindingOperationName();
172 }
173
174 public void setBindingOperationName( String name )
175 {
176 operationConfig.setBindingOperationName( name );
177 }
178
179 public ImageIcon getIcon()
180 {
181 return operationIcon;
182 }
183
184 protected SoapUITreeNode createTreeNode()
185 {
186 return new OperationTreeNode( this );
187 }
188
189 public PanelBuilder getPanelBuilder()
190 {
191 return wsdlOperationPanelBuilder;
192 }
193 }