001: /*
002: *
003: * Copyright 1990-2006 Sun Microsystems, Inc. All Rights Reserved.
004: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
005: *
006: * This program is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU General Public License version
008: * 2 only, as published by the Free Software Foundation.
009: *
010: * This program is distributed in the hope that it will be useful, but
011: * WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * General Public License version 2 for more details (a copy is
014: * included at /legal/license.txt).
015: *
016: * You should have received a copy of the GNU General Public License
017: * version 2 along with this work; if not, write to the Free Software
018: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
019: * 02110-1301 USA
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
022: * Clara, CA 95054 or visit www.sun.com if you need additional
023: * information or have any questions.
024: */
025:
026: /*
027: * This is a standalone launcher that launches MIDP using
028: * the MIDPImplementationClassLoader.
029: */
030:
031: package sun.misc;
032:
033: import java.lang.reflect.Method;
034: import java.lang.reflect.InvocationTargetException;
035: import java.io.File;
036: import java.util.StringTokenizer;
037:
038: public final class MIDPLauncher {
039: static private String suitePath[] = new String[0];
040:
041: public static String[] getMidletSuitePath() {
042: return suitePath;
043: }
044:
045: public static void main(String args[]) {
046: int i, j, num;
047: File midppath[] = new File[0];
048: String midppathString = null;
049: String suitepathString = null;
050: StringTokenizer components;
051: String mainArgs[];
052: int numMainArgs = args.length;
053:
054: /* Process arguments */
055: for (i = 0; i < args.length; i++) {
056: String arg = args[i];
057: if (arg.equals("-midppath")) {
058: midppathString = args[++i];
059: components = new StringTokenizer(midppathString, System
060: .getProperty("path.separator", ":"));
061: num = components.countTokens();
062: midppath = new File[num];
063: for (j = 0; j < num; j++) {
064: midppath[j] = new File(components.nextToken());
065: }
066: args[i - 1] = args[i] = null;
067: numMainArgs -= 2;
068: } else if (arg.equals("-suitepath")) {
069: suitepathString = args[++i];
070: components = new StringTokenizer(suitepathString,
071: System.getProperty("path.separator", ":"));
072: num = components.countTokens();
073: suitePath = new String[num];
074: for (j = 0; j < num; j++) {
075: suitePath[j] = components.nextToken();
076: }
077: args[i - 1] = args[i] = null;
078: numMainArgs -= 2;
079: }
080: }
081:
082: /* Prepare args for the MIDletSuiteLoader.main() */
083: int k = 0;
084: mainArgs = new String[numMainArgs];
085: for (j = 0; j < args.length; j++) {
086: if (args[j] != null) {
087: mainArgs[k++] = args[j];
088: }
089: }
090:
091: /* Create MIDPImplementationClassLoader */
092: MIDPImplementationClassLoader midpImplCL = MIDPConfig
093: .newMIDPImplementationClassLoader(midppath);
094:
095: /* Load MIDletSuiteLoader using MIDPImplementationClassLoader
096: * and invoke it's main() method. */
097: String loaderName = null;
098: try {
099: loaderName = System.getProperty(
100: "com.sun.midp.mainClass.name",
101: "com.sun.midp.main.CdcMIDletSuiteLoader");
102: Class suiteloader = midpImplCL.loadClass(loaderName);
103: Class loaderArgs[] = { mainArgs.getClass() };
104: Method mainMethod = suiteloader.getMethod("main",
105: loaderArgs);
106: Object args2[] = { mainArgs };
107: mainMethod.invoke(null, args2);
108: } catch (ClassNotFoundException ce) {
109: System.err.println("Can't find " + loaderName);
110: } catch (NoSuchMethodException ne) {
111: System.err.println("Can't access MIDletSuiteLoader main()");
112: } catch (IllegalAccessException ie) {
113: System.err.println("Can't invoke MIDletSuiteLoader main()");
114: } catch (InvocationTargetException ite) {
115: ite.printStackTrace();
116: }
117: }
118: }
|