]> git.argeo.org Git - gpl/argeo-slc.git/blobdiff - sandbox/argeo.slc.jemmytest/src/main/java/org/argeo/slc/jemmytest/JemmyTestActivator.java
Use Activator's classloader
[gpl/argeo-slc.git] / sandbox / argeo.slc.jemmytest / src / main / java / org / argeo / slc / jemmytest / JemmyTestActivator.java
index f33855fbc32cec44c859989a39e0bd768e39a68c..c8c0e357c3cf4ee4407661a0d33c6fb6a9b63c2d 100644 (file)
@@ -5,38 +5,57 @@ import java.util.Properties;
 import org.argeo.slc.autoui.AutoUiApplication;
 import org.osgi.framework.BundleActivator;
 import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceEvent;
-import org.osgi.framework.ServiceListener;
+import org.springframework.context.support.AbstractApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
 
-public class JemmyTestActivator implements BundleActivator, ServiceListener {
+public class JemmyTestActivator implements BundleActivator {
+       private AbstractApplicationContext applicationContext;
 
        public void start(BundleContext context) throws Exception {
-               stdOut("JemmyTest started");
+               ClassLoader classLoader = getClass().getClassLoader();
+
+               Thread cur = Thread.currentThread();
+               ClassLoader save = cur.getContextClassLoader();
+               cur.setContextClassLoader(classLoader);
+
+               try {
+                       // FIXME: make it more generic
+                       applicationContext = new ClassPathXmlApplicationContext(
+                                       "/slc/conf/applicationContext.xml");
+               } catch (Exception e) {
+                       e.printStackTrace();
+                       throw new Exception("Could not initialize application context");
+               } finally {
+                       cur.setContextClassLoader(save);
+               }
+
+               // applicationContext = new GenericApplicationContext();
+               // XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(
+               // (BeanDefinitionRegistry) applicationContext);
+               // Bundle bundle = context.getBundle();
+               //
+               // URL url = bundle
+               // .getResource("META-INF/slc/conf/applicationContext.xml");
+               // if (url != null) {
+               // System.out.println("Loads application context from bundle "
+               // + bundle.getSymbolicName());
+               // xmlReader.loadBeanDefinitions(new UrlResource(url));
+               // }
+
                Properties properties = new Properties();
-               AutoUiApplicationJemmy applicationJemmy = new AutoUiApplicationJemmy();
+               // AutoUiApplicationJemmy applicationJemmy = new
+               // AutoUiApplicationJemmy();
+               AutoUiApplicationJemmy applicationJemmy = (AutoUiApplicationJemmy) applicationContext
+                               .getBean("jemmyTest");
                context.registerService(AutoUiApplication.class.getName(),
                                applicationJemmy, properties);
-               context.registerService(Runnable.class.getName(), applicationJemmy,
-                               properties);
-
-//             ServiceReference ref = context
-//                             .getServiceReference("org.argeo.slc.autoui.AutoUiApplication");
-//             Object service = context.getService(ref);
-//             // JemmyTestActivator.stdOut("service=" + service.getClass());
-//             AutoUiApplication app = (AutoUiApplication) service;
-//             app.execute(null);
-
+               stdOut("JemmyTest started");
        }
 
        public void stop(BundleContext context) throws Exception {
                stdOut("JemmyTest stopped");
        }
 
-       public void serviceChanged(ServiceEvent serviceEvent) {
-               stdOut("serviceEvent=" + serviceEvent);
-
-       }
-
        public static void stdOut(Object obj) {
                System.out.println(obj);
        }