]> git.argeo.org Git - gpl/argeo-slc.git/blobdiff - org.argeo.slc.autoui.launcher/src/main/java/org/argeo/slc/autoui/launcher/Main.java
Use SLC Detached (aka. SLC AutoUI) as a bundle.
[gpl/argeo-slc.git] / org.argeo.slc.autoui.launcher / src / main / java / org / argeo / slc / autoui / launcher / Main.java
index 987a675e66c0a3135b58f7fc63e6a5d16edd29e2..1d719cf299d5de9e8a92d4a76f68ded1e7b6d932 100644 (file)
@@ -3,58 +3,44 @@ package org.argeo.slc.autoui.launcher;
 import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
-import java.net.URL;
+import java.lang.reflect.Method;
 import java.util.ArrayList;
 import java.util.Enumeration;
 import java.util.List;
 import java.util.Properties;
 import java.util.Vector;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.apache.felix.framework.Felix;
 import org.apache.felix.framework.cache.BundleCache;
 import org.apache.felix.main.AutoActivator;
 import org.argeo.slc.autoui.AutoUiActivator;
-import org.argeo.slc.autoui.AutoUiApplication;
-import org.netbeans.jemmy.ClassReference;
-import org.osgi.framework.Bundle;
+import org.argeo.slc.autoui.DetachedExecutionServer;
+import org.argeo.slc.autoui.DetachedStep;
+import org.argeo.slc.autoui.DetachedStepRequest;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceReference;
-import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
-import org.springframework.context.ApplicationContext;
-import org.springframework.context.support.GenericApplicationContext;
-import org.springframework.core.io.UrlResource;
 
 public class Main {
+       private final static Log log = LogFactory.getLog(Main.class);
 
        public static void main(String[] args) {
                try {
-                       // Start OSGi system
+                       // Load properties
                        Properties config = prepareConfig();
-                       Felix felix = startSystem(config);
-
-                       // GenericApplicationContext context = new
-                       // GenericApplicationContext();
-                       // XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(
-                       // context);
-                       // Bundle[] bundles = felix.getBundleContext().getBundles();
-                       // for (int i = 0; i < bundles.length; i++) {
-                       // Bundle bundle = bundles[i];
-                       // 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));
-                       // }
-                       // }
 
                        // Start UI (in main class loader)
                        startUi(config);
+                       //Thread.sleep(10000);
+                       
+                       // Start OSGi system
+                       Felix felix = startSystem(config);
 
                        // Automate
-                       automateUi(felix.getBundleContext());
+                       //automateUi(felix.getBundleContext());
 
-                       felix.stop();
+                       // felix.stop();
                } catch (Exception e) {
                        e.printStackTrace();
                        System.exit(-1);
@@ -109,7 +95,7 @@ public class Main {
                // Add activator to process auto-start/install properties.
                list.add(new AutoActivator(config));
                // Add our own activator.
-               list.add(new AutoUiActivator());
+               //list.add(new AutoUiActivator());
 
                // Now create an instance of the framework.
                Felix felix = new Felix(config, list);
@@ -122,21 +108,27 @@ public class Main {
                String className = config.getProperty("argeo.scl.autoui.uiclass");
                String[] uiArgs = readArgumentsFromLine(config.getProperty(
                                "argeo.slc.autoui.uiargs", ""));
-               ClassReference classReference = new ClassReference(className);
-               classReference.startApplication(uiArgs);
+
+               // Launch main method using reflection
+               Class clss = Class.forName(className);
+               Class[] mainArgsClasses = new Class[] { uiArgs.getClass() };
+               Object[] mainArgs = { uiArgs };
+               Method mainMethod = clss.getMethod("main", mainArgsClasses);
+               mainMethod.invoke(null, mainArgs);
        }
 
        protected static void automateUi(BundleContext bundleContext)
                        throws Exception {
                // Retrieve service and execute it
                ServiceReference ref = bundleContext
-                               .getServiceReference("org.argeo.slc.autoui.AutoUiApplication");
+                               .getServiceReference(DetachedExecutionServer.class.getName());
                Object service = bundleContext.getService(ref);
 
-               // Object service = applicationContext.getBean("jemmyTest");
-               AutoUiActivator.stdOut("service.class=" + service.getClass());
-               AutoUiApplication app = (AutoUiApplication) service;
-               app.execute(null);
+               log.debug("service.class=" + service.getClass());
+               DetachedExecutionServer app = (DetachedExecutionServer) service;
+               DetachedStepRequest request = new DetachedStepRequest();
+               request.setStepRef("jemmyTest");
+               app.executeStep(request);
        }
 
        /* UTILITIES */