1
2
3
4
5
6
7
8
9
10
11
12
13 package com.eviware.soapui.impl.support;
14
15 import com.eviware.soapui.SoapUI;
16 import com.eviware.soapui.config.EndpointsConfig;
17 import com.eviware.soapui.config.InterfaceConfig;
18 import com.eviware.soapui.impl.wsdl.AbstractWsdlModelItem;
19 import com.eviware.soapui.impl.wsdl.WsdlProject;
20 import com.eviware.soapui.model.ModelItem;
21 import com.eviware.soapui.model.iface.Interface;
22 import com.eviware.soapui.model.iface.InterfaceListener;
23 import com.eviware.soapui.model.iface.Operation;
24 import com.eviware.soapui.model.iface.Request;
25
26 import java.util.Arrays;
27 import java.util.HashSet;
28 import java.util.List;
29 import java.util.Set;
30
31 public abstract class AbstractInterface<T extends InterfaceConfig> extends AbstractWsdlModelItem<T> implements Interface
32 {
33 private Set<InterfaceListener> interfaceListeners = new HashSet<InterfaceListener>();
34
35 protected AbstractInterface(T config, ModelItem parent, String icon)
36 {
37 super(config, parent, icon);
38
39 if (config.getEndpoints() == null)
40 config.addNewEndpoints();
41
42 for (InterfaceListener listener : SoapUI.getListenerRegistry().getListeners(InterfaceListener.class))
43 {
44 addInterfaceListener(listener);
45 }
46
47 if (!config.isSetDefinitionCache())
48 config.addNewDefinitionCache();
49 }
50
51 public WsdlProject getProject()
52 {
53 return (WsdlProject) getParent();
54 }
55
56 public T getConfig()
57 {
58 return super.getConfig();
59 }
60
61 public List<? extends ModelItem> getChildren()
62 {
63 return getOperationList();
64 }
65
66 public String[] getEndpoints()
67 {
68 EndpointsConfig endpoints = getConfig().getEndpoints();
69 List<String> endpointArray = endpoints.getEndpointList();
70 return endpointArray.toArray(new String[endpointArray.size()]);
71 }
72
73 public void addEndpoint(String endpoint)
74 {
75 if (endpoint == null || endpoint.trim().length() == 0)
76 return;
77
78 endpoint = endpoint.trim();
79 String[] endpoints = getEndpoints();
80
81
82 if (Arrays.asList(endpoints).contains(endpoint))
83 return;
84
85 getConfig().getEndpoints().addNewEndpoint().setStringValue(endpoint);
86
87 notifyPropertyChanged(ENDPOINT_PROPERTY, null, endpoint);
88 }
89
90 public void changeEndpoint(String oldEndpoint, String newEndpoint)
91 {
92 if (oldEndpoint == null || oldEndpoint.trim().length() == 0)
93 return;
94 if (newEndpoint == null || newEndpoint.trim().length() == 0)
95 return;
96
97 EndpointsConfig endpoints = getConfig().getEndpoints();
98
99 for (int c = 0; c < endpoints.sizeOfEndpointArray(); c++)
100 {
101 if (endpoints.getEndpointArray(c).equals(oldEndpoint))
102 {
103 endpoints.setEndpointArray(c, newEndpoint);
104 notifyPropertyChanged(ENDPOINT_PROPERTY, oldEndpoint, newEndpoint);
105 break;
106 }
107 }
108 }
109
110 public void removeEndpoint(String endpoint)
111 {
112 EndpointsConfig endpoints = getConfig().getEndpoints();
113
114 for (int c = 0; c < endpoints.sizeOfEndpointArray(); c++)
115 {
116 if (endpoints.getEndpointArray(c).equals(endpoint))
117 {
118 endpoints.removeEndpoint(c);
119 notifyPropertyChanged(ENDPOINT_PROPERTY, endpoint, null);
120 break;
121 }
122 }
123 }
124
125
126 public void fireOperationAdded(Operation operation)
127 {
128 InterfaceListener[] a = interfaceListeners.toArray(new InterfaceListener[interfaceListeners.size()]);
129
130 for (int c = 0; c < a.length; c++)
131 {
132 a[c].operationAdded(operation);
133 }
134 }
135
136 public void fireOperationUpdated(Operation operation)
137 {
138 InterfaceListener[] a = interfaceListeners.toArray(new InterfaceListener[interfaceListeners.size()]);
139
140 for (int c = 0; c < a.length; c++)
141 {
142 a[c].operationUpdated(operation);
143 }
144 }
145
146 public void fireOperationRemoved(Operation operation)
147 {
148 InterfaceListener[] a = interfaceListeners.toArray(new InterfaceListener[interfaceListeners.size()]);
149
150 for (int c = 0; c < a.length; c++)
151 {
152 a[c].operationRemoved(operation);
153 }
154 }
155
156 public void fireRequestAdded(Request request)
157 {
158 InterfaceListener[] a = interfaceListeners.toArray(new InterfaceListener[interfaceListeners.size()]);
159
160 for (int c = 0; c < a.length; c++)
161 {
162 a[c].requestAdded(request);
163 }
164 }
165
166 public void fireRequestRemoved(Request request)
167 {
168 InterfaceListener[] a = interfaceListeners.toArray(new InterfaceListener[interfaceListeners.size()]);
169
170 for (int c = 0; c < a.length; c++)
171 {
172 a[c].requestRemoved(request);
173 }
174 }
175
176 public void addInterfaceListener(InterfaceListener listener)
177 {
178 interfaceListeners.add(listener);
179 }
180
181 public void removeInterfaceListener(InterfaceListener listener)
182 {
183 interfaceListeners.remove(listener);
184 }
185
186 @Override
187 public void release()
188 {
189 super.release();
190
191 interfaceListeners.clear();
192 }
193
194 public abstract DefinitionContext getDefinitionContext();
195
196 /***
197 * Return the URL for the current definition (ie a WSDL or WADL url)
198 */
199
200 public abstract String getDefinition();
201
202 public abstract String getType();
203
204 public abstract boolean isDefinitionShareble();
205 }