1 package org
.argeo
.slc
.osgiboot
;
3 import java
.lang
.reflect
.Method
;
5 import java
.util
.Properties
;
6 import java
.util
.Vector
;
8 import org
.eclipse
.core
.runtime
.adaptor
.EclipseStarter
;
9 import org
.osgi
.framework
.BundleContext
;
11 public class Launcher
{
13 public static void main(String
[] args
) {
16 BundleContext bundleContext
= null;
18 bundleContext
= EclipseStarter
.startup(args
, null);
19 } catch (Exception e
) {
20 throw new RuntimeException("Cannot start Equinox.", e
);
23 OsgiBoot osgiBoot
= new OsgiBoot(bundleContext
);
27 protected static void startMainClass() {
28 Properties config
= System
.getProperties();
29 String className
= config
.getProperty("slc.osgiboot.appclass");
30 if (className
== null)
33 String
[] uiArgs
= readArgumentsFromLine(config
.getProperty(
34 "slc.osgiboot.appargs", ""));
36 // Launch main method using reflection
37 Class clss
= Class
.forName(className
);
38 Class
[] mainArgsClasses
= new Class
[] { uiArgs
.getClass() };
39 Object
[] mainArgs
= { uiArgs
};
40 Method mainMethod
= clss
.getMethod("main", mainArgsClasses
);
41 mainMethod
.invoke(null, mainArgs
);
42 } catch (Exception e
) {
43 throw new RuntimeException("Cannot start main class.", e
);
49 * Transform a line into an array of arguments, taking "" as single
50 * arguments. (nested \" are not supported)
52 private static String
[] readArgumentsFromLine(String lineOrig
) {
54 String line
= lineOrig
.trim();// remove trailing spaces
55 // System.out.println("line=" + line);
56 List args
= new Vector();
57 StringBuffer curr
= new StringBuffer("");
58 boolean inQuote
= false;
59 char[] arr
= line
.toCharArray();
60 for (int i
= 0; i
< arr
.length
; i
++) {
67 if (!inQuote
) {// otherwise, no break: goes to default
68 if (curr
.length() > 0) {
69 args
.add(curr
.toString());
70 curr
= new StringBuffer("");
81 if (curr
.length() > 0) {
82 args
.add(curr
.toString());
86 String
[] res
= new String
[args
.size()];
87 for (int i
= 0; i
< args
.size(); i
++) {
88 res
[i
] = args
.get(i
).toString();
89 // System.out.println("res[i]=" + res[i]);