Skip to main content
summaryrefslogtreecommitdiffstats
blob: 210d99f82d6648e2e85f67dccd314b81c3c8ba19 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
/*******************************************************************************
 * Copyright (c) 2005, 2006 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 * IBM Corporation - initial API and implementation
 * yyyymmdd bug      Email and other contact information
 * -------- -------- -----------------------------------------------------------
 * 20060317   127456 cbrealey@ca.ibm.com - Chris Brealey
 * 20060620   147862 cbrealey@ca.ibm.com - Chris Brealey
 *******************************************************************************/

package org.eclipse.wst.ws.internal.wsfinder;

import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IProgressMonitor;

/**
 * @author joan
 *
 * WebServiceFinder is a singleton which finds all extenders and returns a comprehensive list of WebServiceInfo objects.
 * Finds web services by calling locators extending {@link org.eclipse.wst.ws.internal.wsfinder.AbstractWebServiceLocator} 
 * which have been registered with {@link org.eclipse.wst.ws.internal.wsfinder.WebServiceLocatorRegistry}.
 */
public class WebServiceFinder {

	private static WebServiceFinder instance = null;

	private static final String ELEMENT_LOCATOR = "webServiceLocator"; //$NON-NLS-1$
	private static final String ELEMENT_CATEGORY = "webServiceLocatorCategory"; //$NON-NLS-1$
	private static final String ATTRIBUTE_ID = "id"; //$NON-NLS-1$
	private static final String ATTRIBUTE_CLASS = "class"; //$NON-NLS-1$
	private static final String ATTRIBUTE_CATEGORY = "category"; //$NON-NLS-1$
//	private static final String ATTRIBUTE_LABEL = "label"; //$NON-NLS-1$
//	private static final String ATTRIBUTE_DESCRIPTION = "description"; //$NON-NLS-1$
//	private static final String ATTRIBUTE_ICON = "icon"; //$NON-NLS-1$

	/*
	 * Public construction is not allowed.
	 * Use WebServiceFinder.instance().
	 */
	private WebServiceFinder ()	
	{
		super();
	}

	/**
	 * Returns the singleton of <code>WebServiceFinder</code>.
	 * @return The singleton of <code>WebServiceFinder</code>.
	 */
	public static WebServiceFinder instance ()
	{
		if (instance == null)
		{
			instance = new WebServiceFinder();
		}
		return instance;
	}
		
	/**
	 * Returns an iterator of WebServiceInfo objects which represent web services found by locators that
	 * have registered using the org.eclipse.wst.ws.locator extension point.  Currently returns all web 
	 * services found for all registered locators.  Locators must extend {@link AbstractWebServiceLocator}.
	 * Callers can use the getter methods on the WebServiceInfo object to retrieve information on the 
	 * web services found.  The WebServiceFinder cannot guarantee the level of detail contained in WebServiceInfo
	 * objects returned.  This is left to the locator implementations.
	 * @param monitor A progress monitor, or null if progress monitoring is not desired.
	 * @return An iterator of WebServiceInfo objects, never null.
	 */
	public Iterator getWebServices ( IProgressMonitor monitor )
	{
		return getWebServicesByCategoryId(null,monitor);
	}
	
	/**
	 * Returns an iterator of WebServiceInfo objects which represent web services found by locators that
	 * have registered using the org.eclipse.wst.ws.locator extension point.  Currently returns all web 
	 * services found in the context of the given projects for all registered locators.
	 * Locators must extend {@link AbstractWebServiceLocator}.
	 * Callers can use the getter methods on the WebServiceInfo object to retrieve information on the 
	 * web services found.  The WebServiceFinder cannot guarantee the level of detail contained in WebServiceInfo
	 * objects returned.  This is left to the locator implementations.
	 * @param monitor A progress monitor, or null if progress monitoring is not desired.
	 * @return An iterator of WebServiceInfo objects, never null.
	 */
	public Iterator getWebServices ( IProject[] projects, IProgressMonitor monitor )
	{
		return getWebServicesByCategoryId(null,projects,monitor);
	}
	
	/**
	 * Returns an iterator of WebServiceInfo objects which represent web services found by locators that
	 * have registered using the org.eclipse.wst.ws.locator extension point under the given category.
	 * Locators must extend {@link AbstractWebServiceLocator}.
	 * Callers can use the getter methods on the WebServiceInfo object to retrieve information on the 
	 * web services found.  The WebServiceFinder cannot guarantee the level of detail contained in WebServiceInfo
	 * objects returned.  This is left to the locator implementations.
	 * @param category The category of locators to use.
	 * @param monitor A progress monitor, or null if progress monitoring is not desired.
	 * @return An iterator of WebServiceInfo objects, never null.
	 */
	public Iterator getWebServicesByCategory ( WebServiceCategory category, IProgressMonitor monitor  )
	{
		return getWebServicesByCategoryId(category == null ? null : category.getId(),monitor);
	}

	/**
	 * Returns an iterator of WebServiceInfo objects which represent web services found by locators that
	 * have registered using the org.eclipse.wst.ws.locator extension point under the given category.
	 * The search is constrained to the given set of one or more projects.
	 * Locators must extend {@link AbstractWebServiceLocator}.
	 * Callers can use the getter methods on the WebServiceInfo object to retrieve information on the 
	 * web services found.  The WebServiceFinder cannot guarantee the level of detail contained in WebServiceInfo
	 * objects returned.  This is left to the locator implementations.
	 * @param category The category of locators to use.
	 * @param monitor A progress monitor, or null if progress monitoring is not desired.
	 * @return An iterator of WebServiceInfo objects, never null.
	 */
	public Iterator getWebServicesByCategory ( WebServiceCategory category, IProject[] projects, IProgressMonitor monitor  )
	{
		return getWebServicesByCategoryId(category == null ? null : category.getId(),projects,monitor);
	}

	/**
	 * Returns an iterator of WebServiceInfo objects which represent web services found by locators that
	 * have registered using the org.eclipse.wst.ws.locator extension point under the given category.
	 * Locators must extend {@link AbstractWebServiceLocator}.
	 * Callers can use the getter methods on the WebServiceInfo object to retrieve information on the 
	 * web services found.  The WebServiceFinder cannot guarantee the level of detail contained in WebServiceInfo
	 * objects returned.  This is left to the locator implementations.
	 * @param categoryId The category of locators to use.
	 * @param monitor A progress monitor, or null if progress monitoring is not desired.
	 * @return An iterator of WebServiceInfo objects, never null.
	 */
	public Iterator getWebServicesByCategoryId ( String categoryId, IProgressMonitor monitor )
	{
		return getWebServicesByCategoryId(categoryId,null,monitor);	
	} 

	/**
	 * Returns an iterator of WebServiceInfo objects which represent web services found by locators that
	 * have registered using the org.eclipse.wst.ws.locator extension point under the given category.
	 * The search is constrained to the given set of one or more projects.
	 * Locators must extend {@link AbstractWebServiceLocator}.
	 * Callers can use the getter methods on the WebServiceInfo object to retrieve information on the 
	 * web services found.  The WebServiceFinder cannot guarantee the level of detail contained in WebServiceInfo
	 * objects returned.  This is left to the locator implementations.
	 * @param categoryId The category of locators to use.
	 * @param monitor A progress monitor, or null if progress monitoring is not desired.
	 * @return An iterator of WebServiceInfo objects, never null.
	 */
	public Iterator getWebServicesByCategoryId ( String categoryId, IProject[] projects, IProgressMonitor monitor )
	{
		LinkedList webServices = new LinkedList();
		WebServiceLocatorRegistry wslr = WebServiceLocatorRegistry.getInstance();
		IConfigurationElement[] regElements = wslr.getConfigElements();
		for (int i = 0; i < regElements.length; i++)
		{
			if (ELEMENT_LOCATOR.equals(regElements[i].getName()))
			{
				try
				{
					if (categoryId == null || categoryId.equals(regElements[i].getAttributeAsIs(ATTRIBUTE_CATEGORY)))
					{
						Object obj = regElements[i].createExecutableExtension(ATTRIBUTE_CLASS);
						if (obj instanceof IWebServiceLocator)
						{
							IWebServiceLocator wsl = (IWebServiceLocator)obj;
							List wsList = projects == null ? wsl.getWebServices(monitor) : wsl.getWebServices(projects,monitor);
							if (wsList != null)
							{
								webServices.addAll(wsList);
							}
						}
					}
				} 
				catch (CoreException ex)
				{
					// Quietly bypass any IWebServiceLocators that failed to be loaded.
				}
			}
		} 
		return webServices.iterator();	
	} 

	/**
	 * Returns an iterator of WebServiceClientInfo objects which represent web service clients found by locators that
	 * have registered using the org.eclipse.wst.ws.locator extension point.  Currently returns all web 
	 * service clients found for all registered locators.  Locators must extend {@link AbstractWebServiceLocator}.
	 * Callers can use the getter methods on the WebServiceClientInfo object to retrieve information on the 
	 * web service clients found.  The WebServiceFinder cannot guarantee the level of detail contained in WebServiceClientInfo
	 * objects returned.  This is left to the locator implementations.
	 * @param monitor A progress monitor, or null if progress monitoring is not desired.
	 * @return An iterator of WebServiceClientInfo objects, never null.
	 */
	public Iterator getWebServiceClients ( IProgressMonitor monitor )
	{
		return getWebServiceClientsByCategoryId(null,monitor);
	}
	
	/**
	 * Returns an iterator of WebServiceClientInfo objects which represent web service clients found by locators that
	 * have registered using the org.eclipse.wst.ws.locator extension point.  Currently returns all web 
	 * service clients found for all registered locators in the context of the given projects.
	 * Locators must extend {@link AbstractWebServiceLocator}.
	 * Callers can use the getter methods on the WebServiceClientInfo object to retrieve information on the 
	 * web service clients found.  The WebServiceFinder cannot guarantee the level of detail contained in WebServiceClientInfo
	 * objects returned.  This is left to the locator implementations.
	 * @param monitor A progress monitor, or null if progress monitoring is not desired.
	 * @return An iterator of WebServiceClientInfo objects, never null.
	 */
	public Iterator getWebServiceClients ( IProject[] projects, IProgressMonitor monitor )
	{
		return getWebServiceClientsByCategoryId(null,projects,monitor);
	}
	
	/**
	 * Returns an iterator of WebServiceClientInfo objects which represent web service clients found by locators that
	 * have registered using the org.eclipse.wst.ws.locator extension point under the given category.
	 * Locators must extend {@link AbstractWebServiceLocator}. 
	 * Callers can use the getter methods on the WebServiceClientInfo object to retrieve information on the 
	 * web service clients found.  The WebServiceFinder cannot guarantee the level of detail contained in WebServiceClientInfo
	 * objects returned.  This is left to the locator implementations.
	 * @param category The category of locators to use.
	 * @param monitor A progress monitor, or null if progress monitoring is not desired.
	 * @return An iterator of WebServiceClientInfo objects, never null.
	 */
	public Iterator getWebServiceClientsByCategory ( WebServiceCategory category, IProgressMonitor monitor )
	{
		return getWebServiceClientsByCategoryId(category == null ? null : category.getId(),monitor);
	}

	/**
	 * Returns an iterator of WebServiceClientInfo objects which represent web service clients found by locators that
	 * have registered using the org.eclipse.wst.ws.locator extension point under the given category.
	 * The search is constrained to the given set of one or more projects.
	 * Locators must extend {@link AbstractWebServiceLocator}. 
	 * Callers can use the getter methods on the WebServiceClientInfo object to retrieve information on the 
	 * web service clients found.  The WebServiceFinder cannot guarantee the level of detail contained in WebServiceClientInfo
	 * objects returned.  This is left to the locator implementations.
	 * @param category The category of locators to use.
	 * @param monitor A progress monitor, or null if progress monitoring is not desired.
	 * @return An iterator of WebServiceClientInfo objects, never null.
	 */
	public Iterator getWebServiceClientsByCategory ( WebServiceCategory category, IProject[] projects, IProgressMonitor monitor )
	{
		return getWebServiceClientsByCategoryId(category == null ? null : category.getId(),projects,monitor);
	}

	/**
	 * Returns an iterator of WebServiceClientInfo objects which represent web service clients found by locators that
	 * have registered using the org.eclipse.wst.ws.locator extension point under the given category.
	 * Locators must extend {@link AbstractWebServiceLocator}.
	 * Callers can use the getter methods on the WebServiceClientInfo object to retrieve information on the 
	 * web service clients found.  The WebServiceFinder cannot guarantee the level of detail contained in WebServiceClientInfo
	 * objects returned.  This is left to the locator implementations.
	 * @param categoryId The category of locators to use.
	 * @param monitor A progress monitor, or null if progress monitoring is not desired.
	 * @return An iterator of WebServiceClientInfo objects, never null.
	 */
	public Iterator getWebServiceClientsByCategoryId ( String categoryId, IProgressMonitor monitor )
	{
		return getWebServiceClientsByCategoryId(categoryId,null,monitor);
	} 

	/**
	 * Returns an iterator of WebServiceClientInfo objects which represent web service clients found by locators that
	 * have registered using the org.eclipse.wst.ws.locator extension point under the given category.
	 * The search is constrained to the given set of one or more projects.
	 * Locators must extend {@link AbstractWebServiceLocator}.
	 * Callers can use the getter methods on the WebServiceClientInfo object to retrieve information on the 
	 * web service clients found.  The WebServiceFinder cannot guarantee the level of detail contained in WebServiceClientInfo
	 * objects returned.  This is left to the locator implementations.
	 * @param categoryId The category of locators to use.
	 * @param monitor A progress monitor, or null if progress monitoring is not desired.
	 * @return An iterator of WebServiceClientInfo objects, never null.
	 */
	public Iterator getWebServiceClientsByCategoryId ( String categoryId, IProject[] projects, IProgressMonitor monitor )
	{
		LinkedList webServiceClients = new LinkedList();
		WebServiceLocatorRegistry wslr = WebServiceLocatorRegistry.getInstance();
		IConfigurationElement[] regElements = wslr.getConfigElements();
		for (int i = 0; i < regElements.length; i++)
		{
			if (ELEMENT_LOCATOR.equals(regElements[i].getName()))
			{
				try
				{
					if (categoryId == null || categoryId.equals(regElements[i].getAttributeAsIs(ATTRIBUTE_CATEGORY)))
					{
						Object obj = regElements[i].createExecutableExtension(ATTRIBUTE_CLASS);
						if (obj instanceof IWebServiceLocator)
						{
							IWebServiceLocator wsl = (IWebServiceLocator)obj;
							List wsList = projects == null ? wsl.getWebServiceClients(monitor) : wsl.getWebServiceClients(projects,monitor);
							if (wsList != null)
							{
								webServiceClients.addAll(wsList);
							}
						}
					}
				} 
				catch (CoreException ex)
				{
					// Quietly bypass any IWebServiceLocators that failed to be loaded.
				}
			}
		} 
		return webServiceClients.iterator();	
	} 

	/**
	 * Returns an array of registered Web Service Category IDs.
	 * @return An array, never null but possibly empty,
	 * of registered Web Service Category descriptors.
	 */
	public WebServiceCategory[] getWebServiceCategories ()
	{
		LinkedList categories = new LinkedList();
		WebServiceLocatorRegistry wslr = WebServiceLocatorRegistry.getInstance();
		IConfigurationElement[] regElements = wslr.getConfigElements();
		for (int i = 0; i < regElements.length; i++)
		{
			if (ELEMENT_CATEGORY.equals(regElements[i].getName()))
			{
				categories.add(new WebServiceCategory(regElements[i]));
			}
		}
		return (WebServiceCategory[])categories.toArray(new WebServiceCategory[0]);

	}	

	/**
	 * Returns an array of registered Web Service Category IDs.
	 * @return An array, never null but possibly empty,
	 * of registered Web Service Category IDs.
	 */
	public String[] getWebServiceCategoryIds ()
	{
		LinkedList categories = new LinkedList();
		WebServiceLocatorRegistry wslr = WebServiceLocatorRegistry.getInstance();
		IConfigurationElement[] regElements = wslr.getConfigElements();
		for (int i = 0; i < regElements.length; i++)
		{
			if (ELEMENT_CATEGORY.equals(regElements[i].getName()))
			{
				String id = regElements[i].getAttributeAsIs(ATTRIBUTE_ID);
				if (id != null)
				{
					categories.add(id);
				}
			}
		}
		return (String[])categories.toArray(new String[0]);
	}
	
	/**
	 * Returns the WebServiceCategory with the given ID,
	 * or null if there is none.
	 * @param categoryId The ID of the category to find.
	 * @return The matching category descriptor, or null if there is none.
	 */
	public WebServiceCategory getWebServiceCategoryById ( String categoryId )
	{
		WebServiceCategory category = null;
		if (categoryId != null)
		{
			WebServiceLocatorRegistry wslr = WebServiceLocatorRegistry.getInstance();
			IConfigurationElement[] regElements = wslr.getConfigElements();
			for (int i = 0; i < regElements.length; i++)
			{
				if (ELEMENT_CATEGORY.equals(regElements[i].getName()))
				{
					String id = regElements[i].getAttributeAsIs(ATTRIBUTE_ID);
					if (categoryId.equals(id))
					{
						return new WebServiceCategory(regElements[i]);
					}
				}
			}
		}
		return category;
	}
}

Back to the top