Showing posts with label extension point with parameters. Show all posts
Showing posts with label extension point with parameters. Show all posts

Sunday, September 13, 2015

How can I pass arguments to an extension point constructor/ createExecutableExtension with parameters in eclipse

Please also refer to my previous post.
http://exploreeclipse.blogspot.in/2015/09/reading-extension-point-from-eclipse.html


public void readExtensionPoint(String myjsonString) {
IExtensionRegistry registry = Platform.getExtensionRegistry();
IConfigurationElement[] elements = registry.getConfigurationElementsFor("com.kk.myplugin", "services");
for (IConfigurationElement iConfigurationElement : elements)
{
iConfigurationElement.getAttribute("service_id");
iConfigurationElement.getAttribute("name");
try
{
try
{
String attribute = iConfigurationElement.getAttribute("class");
String contributorName = iConfigurationElement.getDeclaringExtension().getContributor().getName();
Class<?> javaClass = Platform.getBundle(contributorName).loadClass(attribute);
Constructor<?> ctor = javaClass.getDeclaredConstructor(String.class);
IService service = (IService) ctor.newInstance(myjsonString);
return service;
}
catch (Exception e)
{
}
}
catch (CoreException e)
{
e.printStackTrace();
}
}


}