1 package org
.argeo
.slc
.autoui
;
5 import org
.osgi
.framework
.Bundle
;
6 import org
.osgi
.framework
.BundleActivator
;
7 import org
.osgi
.framework
.BundleContext
;
8 import org
.springframework
.beans
.factory
.support
.BeanDefinitionRegistry
;
9 import org
.springframework
.beans
.factory
.xml
.XmlBeanDefinitionReader
;
10 import org
.springframework
.context
.support
.AbstractApplicationContext
;
11 import org
.springframework
.context
.support
.GenericApplicationContext
;
12 import org
.springframework
.core
.io
.UrlResource
;
14 public class AbstractAutoActivator
implements BundleActivator
{
15 private AbstractApplicationContext applicationContext
;
17 public final void start(BundleContext context
) throws Exception
{
18 ClassLoader classLoader
= getClass().getClassLoader();
20 Thread cur
= Thread
.currentThread();
21 ClassLoader save
= cur
.getContextClassLoader();
22 cur
.setContextClassLoader(classLoader
);
25 // applicationContext = new ClassPathXmlApplicationContext(
26 // "/slc/conf/applicationContext.xml");
28 applicationContext
= new GenericApplicationContext();
29 XmlBeanDefinitionReader xmlReader
= new XmlBeanDefinitionReader(
30 (BeanDefinitionRegistry
) applicationContext
);
31 Bundle bundle
= context
.getBundle();
34 .getResource("META-INF/slc/conf/applicationContext.xml");
36 System
.out
.println("Loads application context from bundle "
37 + bundle
.getSymbolicName() + " (url=" + url
+ ")");
38 xmlReader
.loadBeanDefinitions(new UrlResource(url
));
41 } catch (Exception e
) {
43 throw new Exception("Could not initialize application context");
45 cur
.setContextClassLoader(save
);
48 startAutoBundle(context
);
51 /** Does nothing by default. */
52 protected void startAutoBundle(BundleContext context
) throws Exception
{
56 public final void stop(BundleContext context
) throws Exception
{
57 stopAutoBundle(context
);
59 if (applicationContext
!= null) {
60 applicationContext
.close();
65 /** Does nothing by default. */
66 protected void stopAutoBundle(BundleContext context
) throws Exception
{
70 public Object
getStaticRef(String id
) {
71 return applicationContext
.getBean(id
);