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: * @(#)AMSmain.java 1.5 06/10/10
028: */
029: package com.sun.javax.microedition.midlet;
030:
031: import sun.misc.MIDPImplementationClassLoader;
032: import sun.misc.MIDPConfig;
033: import sun.misc.MemberFilter;
034: import javax.microedition.midlet.*;
035: import java.io.*;
036:
037: public class AMSmain {
038:
039: /* Important parameters */
040: final static String AMSclassName = "com.sun.javax.microedition.midlet.AMS";
041: final static String MIDPimplProperty = "com.sun.javax.microedition.implementation";
042:
043: /*
044: * Some places we want a file name,
045: * some places we want a URL.
046: * Duplicated from javax.microedition.midlet.AMS.
047: */
048: static String filenameToURL(String filename) {
049: java.io.File f = new File(filename);
050: String longname;
051: try {
052: longname = f.getCanonicalPath();
053: } catch (IOException e) {
054: throw new Error("IOException");
055: }
056: return longname;
057: }
058:
059: /*
060: * MAIN:
061: * Instantiate class loader & com.sun.javax.microedition.midlet.AMS class.
062: * initialze shared structures,
063: * instantiate just one AMS instance to go do the work.
064: * First and only parameter is URL to MIDlet suite JAR.
065: */
066:
067: public static void main(String args[]) {
068: String suitePath = args[0];
069: String midImplPath = System.getProperty(MIDPimplProperty);
070:
071: MIDPImplementationClassLoader midpImpl = MIDPConfig
072: .newMIDPImplementationClassLoader(new String[] { filenameToURL(midImplPath) });
073: MemberFilter mf = MIDPConfig.newMemberFilter();
074: MidletAMS suiteRunner;
075:
076: try {
077: Class myAMSClass = midpImpl.loadClass(AMSclassName, true);
078: suiteRunner = (MidletAMS) (myAMSClass.newInstance());
079: } catch (Exception e) {
080: System.err.println("Instantiating AMS");
081: e.printStackTrace();
082: return;
083: }
084: /*
085: * setupSharedState would most logically be a
086: * static method. But calling a static method on a
087: * dynamically loaded class is more work than this
088: * and not very enlightening.
089: */
090: try {
091: if (!suiteRunner.setupSharedState(midpImpl, mf)) {
092: return; // error message already printed.
093: }
094: } catch (SecurityException e) {
095: System.err.println("Suite Runner AMS SecurityException");
096: e.printStackTrace();
097: return;
098: }
099: /*
100: * Setup each suiteRunner with the path of the JAR
101: * containing the suite of midlets for it to manage.
102: * In this case there is only one, so we only see
103: * one such call.
104: */
105: if (!suiteRunner.initializeSuite(suitePath)) {
106: return; // error message already printed.
107: }
108: /*
109: * Start the suiteRunner. It will return when there
110: * is nothing more for it to do.
111: */
112: suiteRunner.runSuite();
113: }
114: }
|