package org.argeo.eclipse.spring;\r
\r
-import org.argeo.eclipse.ui.ArgeoUiPlugin;\r
import org.eclipse.core.runtime.CoreException;\r
import org.eclipse.core.runtime.IConfigurationElement;\r
import org.eclipse.core.runtime.IExecutableExtension;\r
import org.eclipse.core.runtime.IExecutableExtensionFactory;\r
import org.eclipse.core.runtime.IExtension;\r
-import org.eclipse.core.runtime.Platform;\r
-import org.osgi.framework.Bundle;\r
-import org.osgi.framework.BundleException;\r
import org.springframework.context.ApplicationContext;\r
\r
/**\r
* spring extension factory uses the id of the extension itself to identify the\r
* bean.\r
* \r
+ * original code from: <a href="http://martinlippert.blogspot.com/2008/10/new-version-of-spring-extension-factory.html"\r
+ * >Blog entry</a>\r
+ * \r
* @author Martin Lippert\r
+ * @author mbaudier\r
*/\r
public class SpringExtensionFactory implements IExecutableExtensionFactory,\r
IExecutableExtension {\r
public void setInitializationData(IConfigurationElement config,\r
String propertyName, Object data) throws CoreException {\r
String beanName = getBeanName(data, config);\r
- ApplicationContext appContext = getApplicationContext(config);\r
+ ApplicationContext appContext = ApplicationContextTracker\r
+ .getApplicationContext(config.getContributor().getName());\r
\r
if (beanName != null && appContext != null) {\r
this.bean = appContext.getBean(beanName);\r
}\r
\r
private String getBeanName(Object data, IConfigurationElement config) {\r
- \r
+\r
// try the specific bean id the extension defines\r
if (data != null && data.toString().length() > 0) {\r
return data.toString();\r
return null;\r
}\r
\r
- private ApplicationContext getApplicationContext(\r
- IConfigurationElement config) {\r
- String contributorName = config.getContributor().getName();\r
- Bundle contributorBundle = Platform.getBundle(contributorName);\r
-\r
- if (contributorBundle.getState() != Bundle.ACTIVE && contributorBundle.getState() != Bundle.STARTING) {\r
- try {\r
- System.out.println("starting bundle: " + contributorBundle.getSymbolicName());\r
- contributorBundle.start();\r
- } catch (BundleException e) {\r
- e.printStackTrace();\r
- }\r
- }\r
-\r
- final ApplicationContextTracker applicationContextTracker = new ApplicationContextTracker(\r
- contributorBundle, ArgeoUiPlugin.getDefault().getBundleContext());\r
- ApplicationContext applicationContext = null;\r
- try {\r
- applicationContext = applicationContextTracker\r
- .getApplicationContext();\r
- } finally {\r
- applicationContextTracker.close();\r
- }\r
- return applicationContext;\r
- }\r
-\r
}\r