]> git.argeo.org Git - gpl/argeo-slc.git/blobdiff - org.argeo.slc.autoui/src/main/java/org/argeo/slc/autoui/AbstractDetachedActivator.java
Introduce detached execution server.
[gpl/argeo-slc.git] / org.argeo.slc.autoui / src / main / java / org / argeo / slc / autoui / AbstractDetachedActivator.java
index 7f18d50a4d0c6c652432bddcc5c64a56459ee7af..b1fe56922695f39f6c55141a557cfa20b38fc665 100644 (file)
@@ -1,6 +1,7 @@
 package org.argeo.slc.autoui;
 
 import java.net.URL;
+import java.util.Properties;
 
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleActivator;
@@ -12,11 +13,12 @@ import org.springframework.context.support.GenericApplicationContext;
 import org.springframework.core.io.UrlResource;
 
 public class AbstractDetachedActivator implements BundleActivator {
-       private AbstractApplicationContext applicationContext;
+       private SpringStaticRefProvider staticRefProvider;
 
        public final void start(BundleContext context) throws Exception {
                ClassLoader classLoader = getClass().getClassLoader();
 
+               // Creates application context
                Thread cur = Thread.currentThread();
                ClassLoader save = cur.getContextClassLoader();
                cur.setContextClassLoader(classLoader);
@@ -25,7 +27,7 @@ public class AbstractDetachedActivator implements BundleActivator {
                        // applicationContext = new ClassPathXmlApplicationContext(
                        // "/slc/conf/applicationContext.xml");
 
-                       applicationContext = new GenericApplicationContext();
+                       AbstractApplicationContext applicationContext = new GenericApplicationContext();
                        XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(
                                        (BeanDefinitionRegistry) applicationContext);
                        Bundle bundle = context.getBundle();
@@ -38,6 +40,14 @@ public class AbstractDetachedActivator implements BundleActivator {
                                xmlReader.loadBeanDefinitions(new UrlResource(url));
                        }
 
+                       // Register static ref provider
+                       staticRefProvider = new SpringStaticRefProvider(applicationContext);
+                       Properties properties = new Properties();
+                       properties.setProperty("slc.detached.bundle", bundle
+                                       .getSymbolicName());
+                       context.registerService(StaticRefProvider.class.getName(),
+                                       staticRefProvider, properties);
+
                } catch (Exception e) {
                        e.printStackTrace();
                        throw new Exception("Could not initialize application context");
@@ -56,8 +66,8 @@ public class AbstractDetachedActivator implements BundleActivator {
        public final void stop(BundleContext context) throws Exception {
                stopAutoBundle(context);
 
-               if (applicationContext != null) {
-                       applicationContext.close();
+               if (staticRefProvider != null) {
+                       staticRefProvider.close();
                }
 
        }
@@ -67,8 +77,7 @@ public class AbstractDetachedActivator implements BundleActivator {
 
        }
 
-       public Object getStaticRef(String id) {
-               return applicationContext.getBean(id);
+       protected StaticRefProvider getStaticRefProvider() {
+               return staticRefProvider;
        }
-
 }