Added support to search extension by extension point id + extension id. Enhance search of "class" attribute.
This commit is contained in:
parent
836c789066
commit
9a3b1f3a4c
|
|
@ -30,9 +30,9 @@ import org.eclipse.core.runtime.Platform;
|
||||||
* This List looks up services as extensions in equinox.
|
* This List looks up services as extensions in equinox.
|
||||||
* The extension point must be the class name of the service interface.
|
* The extension point must be the class name of the service interface.
|
||||||
* The query attributes are checked against the attributes
|
* The query attributes are checked against the attributes
|
||||||
* of the extension configuration element.
|
* of the extension configuration element.
|
||||||
*
|
*
|
||||||
* In order to minimize equinox lookups, a filtering iterator is used.
|
* In order to minimize equinox lookups, a filtering iterator is used.
|
||||||
* @author viola
|
* @author viola
|
||||||
*
|
*
|
||||||
* @param <T> The service this list holds implementations of.
|
* @param <T> The service this list holds implementations of.
|
||||||
|
|
@ -59,9 +59,15 @@ public class ExtensionList<T> implements Iterable<T>{
|
||||||
private boolean accept(IConfigurationElement element) {
|
private boolean accept(IConfigurationElement element) {
|
||||||
for (String name : filters.keySet()) {
|
for (String name : filters.keySet()) {
|
||||||
String expected = filters.get(name);
|
String expected = filters.get(name);
|
||||||
String actual = element.getAttribute(name);
|
if (name.equals("Extension.ID")) {
|
||||||
if (!expected.equals(actual))
|
String id = element.getDeclaringExtension().getUniqueIdentifier();
|
||||||
return false;
|
if (!expected.equals(id))
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
String actual = element.getAttribute(name);
|
||||||
|
if (!expected.equals(actual))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -70,6 +76,17 @@ public class ExtensionList<T> implements Iterable<T>{
|
||||||
public T next() {
|
public T next() {
|
||||||
iterateUntilAccepted();
|
iterateUntilAccepted();
|
||||||
IConfigurationElement e = elements[index++];
|
IConfigurationElement e = elements[index++];
|
||||||
|
if (e.getAttribute("class") == null) {
|
||||||
|
IConfigurationElement[] childs = e.getChildren();
|
||||||
|
if (childs != null && childs.length > 0) {
|
||||||
|
for(IConfigurationElement child : childs) {
|
||||||
|
if (child.getAttribute("class") != null) {
|
||||||
|
e = child;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
return (T) e.createExecutableExtension("class");
|
return (T) e.createExecutableExtension("class");
|
||||||
} catch (CoreException ex) {
|
} catch (CoreException ex) {
|
||||||
|
|
@ -93,7 +110,7 @@ public class ExtensionList<T> implements Iterable<T>{
|
||||||
System.out.println(ex.getMessage());
|
System.out.println(ex.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public ExtensionList(Class<T> type, String extensionPointId, ServiceQuery query) {
|
public ExtensionList(Class<T> type, String extensionPointId, ServiceQuery query) {
|
||||||
this(type, extensionPointId);
|
this(type, extensionPointId);
|
||||||
for (String key : query.keySet()) {
|
for (String key : query.keySet()) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue