I'm have a class that makes dynamic contributions while my plugin is loading. I've looked at this article (www.ibm.com/developerworks/opensource/library/os-ecl-dynext/?ca=dgr-lnxw07OSGi) for reference. The method that adds the contributions is:
void addExtension(Bundle bundle, String xmlsrc) throws Exception {
// use Eclipse Dynamic Extension API
IExtensionRegistry reg = RegistryFactory.getRegistry();
Object key = ((ExtensionRegistry) reg).getTemporaryUserToken();
IContributor contributor = ContributorFactoryOSGi.createContributor(bundle);
ByteArrayInputStream is = new ByteArrayInputStream(xmlsrc.getBytes("UTF-8"));
if (!reg.addContribution(is, contributor, false, null, null, key)) {
throw new Exception("Error while adding contribution: " + xmlsrc);
}
}
The code works fine, and my contributions are added. But since the contributions are added asynchronously, i wanted to know when my contributions were being added, therefore i implemented the IRegistryEventListener interface and did this:
IExtensionRegistry reg = RegistryFactory.getRegistry();
reg.addListener(this);
And the event i'm interested is the "added". I've implemented like this:
public void added(IExtension[] extensions) {
if (extensions != null && extensions.length > 0) {
for (IExtension extension : extensions) {
String extId = extension.getUniqueIdentifier();
}
}
}
The code is called, but while debugging the code, I noticed that the all the IExtension objects supplied as argument are a handle and all the important attributes that I need to check return null (On this example the getUniqueIdentifier() returns null). And I'm sure that i provide the extension id, otherwise the IExtensionRegistry.addContribution method would throw an error.
I don't know if this is the desired behavior but it is strange to receive notifications about registry change and not having any idea what did change.
Just for the record, I've tested some variants, but all of them had the same effect:
- IExtensionRegistry.addRegistryChangeListener
- ExtensionTracker class.
My machine:
* Windows 7
* Java 1.6.0_25
Eclipse versions tested:
* Eclipse 3.6.2
* Indigo Service Release 1
[Updated on: Mon, 02 January 2012 19:29]
Report message to a moderator