|
Lines 12-19
Link Here
|
| 12 |
package org.eclipse.wst.ws.internal.wsfinder; |
12 |
package org.eclipse.wst.ws.internal.wsfinder; |
| 13 |
|
13 |
|
| 14 |
import java.util.Iterator; |
14 |
import java.util.Iterator; |
|
|
15 |
import java.util.LinkedList; |
| 15 |
import java.util.List; |
16 |
import java.util.List; |
| 16 |
import java.util.Vector; |
|
|
| 17 |
import org.eclipse.core.runtime.CoreException; |
17 |
import org.eclipse.core.runtime.CoreException; |
| 18 |
import org.eclipse.core.runtime.IConfigurationElement; |
18 |
import org.eclipse.core.runtime.IConfigurationElement; |
| 19 |
|
19 |
|
|
Lines 26-41
Link Here
|
| 26 |
*/ |
26 |
*/ |
| 27 |
|
27 |
|
| 28 |
public class WebServiceFinder { |
28 |
public class WebServiceFinder { |
| 29 |
|
29 |
|
| 30 |
private static WebServiceFinder instance = null; |
30 |
private static WebServiceFinder instance = null; |
| 31 |
|
31 |
|
| 32 |
private static final String CLASS_ATTRIBUTE= "class"; //$NON-NLS-1$ |
32 |
private static final String ELEMENT_LOCATOR = "webServiceLocator"; //$NON-NLS-1$ |
| 33 |
|
33 |
private static final String ELEMENT_CATEGORY = "webServiceLocatorCategory"; //$NON-NLS-1$ |
| 34 |
public WebServiceFinder() |
34 |
private static final String ATTRIBUTE_ID = "id"; //$NON-NLS-1$ |
|
|
35 |
private static final String ATTRIBUTE_CLASS = "class"; //$NON-NLS-1$ |
| 36 |
private static final String ATTRIBUTE_CATEGORY = "category"; //$NON-NLS-1$ |
| 37 |
// private static final String ATTRIBUTE_LABEL = "label"; //$NON-NLS-1$ |
| 38 |
// private static final String ATTRIBUTE_DESCRIPTION = "description"; //$NON-NLS-1$ |
| 39 |
// private static final String ATTRIBUTE_ICON = "icon"; //$NON-NLS-1$ |
| 40 |
|
| 41 |
/* |
| 42 |
* Public construction is not allowed. |
| 43 |
* Use WebServiceFinder.instance(). |
| 44 |
*/ |
| 45 |
private WebServiceFinder() |
| 35 |
{ |
46 |
{ |
| 36 |
super(); |
47 |
super(); |
| 37 |
} |
48 |
} |
| 38 |
|
49 |
|
|
|
50 |
/** |
| 51 |
* Returns the singleton of <code>WebServiceFinder</code>. |
| 52 |
* @return The singleton of <code>WebServiceFinder</code>. |
| 53 |
*/ |
| 39 |
public static WebServiceFinder instance() |
54 |
public static WebServiceFinder instance() |
| 40 |
{ |
55 |
{ |
| 41 |
if (instance == null) |
56 |
if (instance == null) |
|
Lines 58-84
Link Here
|
| 58 |
*/ |
73 |
*/ |
| 59 |
public Iterator getWebServices() |
74 |
public Iterator getWebServices() |
| 60 |
{ |
75 |
{ |
| 61 |
Vector webServices = new Vector(); |
76 |
return getWebServices(null); |
|
|
77 |
} |
| 62 |
|
78 |
|
|
|
79 |
/** |
| 80 |
* Returns an iterator of WebServiceInfo objects which represent web services found by locators that |
| 81 |
* have registered using the org.eclipse.wst.ws.locator extension point under the given category. |
| 82 |
* Locators must extend {@link AbstractWebServiceLocator}. |
| 83 |
* |
| 84 |
* Callers can use the getter methods on the WebServiceInfo object to retrieve information on the |
| 85 |
* web services found. The WebServiceFinder cannot guarantee the level of detail contained in WebServiceInfo |
| 86 |
* objects returned. This is left to the locator implementations. |
| 87 |
* |
| 88 |
* @return iterator of WebServiceInfo objects |
| 89 |
* @param category The category of locators to use |
| 90 |
*/ |
| 91 |
public Iterator getWebServices(String category) |
| 92 |
{ |
| 93 |
LinkedList webServices = new LinkedList(); |
| 63 |
WebServiceLocatorRegistry wslr = WebServiceLocatorRegistry.getInstance(); |
94 |
WebServiceLocatorRegistry wslr = WebServiceLocatorRegistry.getInstance(); |
| 64 |
|
|
|
| 65 |
IConfigurationElement[] regElements = wslr.getConfigElements(); |
95 |
IConfigurationElement[] regElements = wslr.getConfigElements(); |
| 66 |
for (int i = 0; i < regElements.length; i++) { |
96 |
for (int i = 0; i < regElements.length; i++) |
| 67 |
try{ |
97 |
{ |
| 68 |
Object obj = regElements[i].createExecutableExtension(CLASS_ATTRIBUTE); |
98 |
if (ELEMENT_LOCATOR.equals(regElements[i].getName())) |
| 69 |
|
99 |
{ |
| 70 |
if (obj instanceof IWebServiceLocator) |
100 |
try |
| 71 |
{ |
101 |
{ |
| 72 |
IWebServiceLocator wsl = (IWebServiceLocator)obj; |
102 |
if (category == null || category.equals(regElements[i].getAttributeAsIs(ATTRIBUTE_CATEGORY))) |
| 73 |
List wsList = wsl.getWebServices(); |
103 |
{ |
| 74 |
webServices.addAll(wsList); |
104 |
Object obj = regElements[i].createExecutableExtension(ATTRIBUTE_CLASS); |
| 75 |
} |
105 |
if (obj instanceof IWebServiceLocator) |
| 76 |
} |
106 |
{ |
| 77 |
catch (CoreException ex){ |
107 |
IWebServiceLocator wsl = (IWebServiceLocator)obj; |
| 78 |
|
108 |
List wsList = wsl.getWebServices(); |
| 79 |
} |
109 |
webServices.addAll(wsList); |
|
|
110 |
} |
| 111 |
} |
| 112 |
} |
| 113 |
catch (CoreException ex){ |
| 114 |
// Quietly bypass any IWebServiceLocators that failed to be loaded. |
| 115 |
} |
| 116 |
} |
| 80 |
} |
117 |
} |
| 81 |
return webServices.iterator(); |
118 |
return webServices.iterator(); |
| 82 |
} |
119 |
} |
|
|
120 |
|
| 121 |
/** |
| 122 |
* Returns an array of registered Web Service Category IDs. |
| 123 |
* |
| 124 |
* @return An array, never null but possibly empty, |
| 125 |
* of registered Web Service Category IDs. |
| 126 |
*/ |
| 127 |
public String[] getCategoryIDs() |
| 128 |
{ |
| 129 |
LinkedList categories = new LinkedList(); |
| 130 |
WebServiceLocatorRegistry wslr = WebServiceLocatorRegistry.getInstance(); |
| 131 |
IConfigurationElement[] regElements = wslr.getConfigElements(); |
| 132 |
for (int i = 0; i < regElements.length; i++) |
| 133 |
{ |
| 134 |
if (ELEMENT_CATEGORY.equals(regElements[i].getName())) |
| 135 |
{ |
| 136 |
String id = regElements[i].getAttributeAsIs(ATTRIBUTE_ID); |
| 137 |
if (id != null) |
| 138 |
{ |
| 139 |
categories.add(id); |
| 140 |
} |
| 141 |
} |
| 142 |
} |
| 143 |
return (String[])categories.toArray(new String[0]); |
| 144 |
} |
| 83 |
|
145 |
|
|
|
146 |
//TODO: Need another method to return full Category objects, |
| 147 |
//as in "public WebServiceLocatorCategory getCategories()" |
| 148 |
//where WebServiceLocatorCategory is a new bean class with properties |
| 149 |
//mirroring the attributes of a webServiceLocatorCategory extension. |
| 84 |
} |
150 |
} |