⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.java

📁 用于移动设备上的java虚拟机源代码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * @(#)Main.java	1.62 02/10/03 @(#) * * Copyright (c) 2001-2002 Sun Microsystems, Inc.  All rights reserved. * PROPRIETARY/CONFIDENTIAL * Use is subject to license terms. */package com.sun.midp.main;import java.io.IOException;import java.io.ByteArrayInputStream;import java.lang.String;import java.util.Vector;import com.sun.midp.dev.DevMIDletSuiteImpl;import com.sun.midp.io.j2me.storage.File;import com.sun.midp.io.j2me.push.PushRegistryImpl;import com.sun.midp.lcdui.Resource;import com.sun.midp.midlet.MIDletInfo;import com.sun.midp.midlet.MIDletSuite;import com.sun.midp.midlet.Scheduler;import com.sun.midp.midletsuite.Installer;import com.sun.midp.midletsuite.InvalidJadException;import com.sun.midp.security.*;import com.sun.midp.lcdui.DisplayManagerFactory;/** * The first class loaded in VM by main.c to initialize internal security and * perform a MIDP command. * <p> * This class performs 6 basic commands: * <ul> * <li>Application installation * <li>Application removal * <li>Application listing * <li>Application execution * <li>Graphical Application Management * <li>Execute a single MIDlet from the classpath * </ul> */public class Main {    /**     * Prefix for storage files that classes that do not belong to a suite.     */    private static final String DEV_STORAGE_NAME = "run_by_class_storage_";    /** This class has a different security domain than the MIDlet suite. */    private static SecurityToken internalSecurityToken;    /**     * Initializes internal security, performs the next     * command indicated in the command state, and sets up the next command     * to be performed. The command loop is in main.c.     *     * When done exitInternal is called with a special constant so     * main.c knows that this was the last method run, as opposed to the VM     * aborting.     * @param args not used, instead a {@link CommandState} object is obtained     *             using a native method.     */    public static void main(String args[]) {        CommandState state = new CommandState();	/*	 * pass resource strings down to the native system menu and	 * popup choice group methods...	 */	initSystemLabels();        /*         * We will try to handle any printing at this level, because         * displaying JAM command line errors is device specific.         */        try {            initializeInternalSecurity();	    /* Start a inbound connection watcher thread. */	    new Thread(new PushRegistryImpl()).start();            restoreCommandState(state);            // handle any development machine only functions at this level            switch (state.nextCommand) {            case CommandProcessor.RUN_CLASS:                runLocalClass(state);                state.nextCommand = CommandProcessor.EXIT;                break;            case CommandProcessor.MANAGE:                manage(state);                break;            case CommandProcessor.LIST:            case CommandProcessor.STORAGE_NAMES:                list(state);                state.nextCommand = CommandProcessor.EXIT;                break;            case CommandProcessor.REMOVE:                if (DEV_STORAGE_NAME.equals(state.suiteStorageName)) {                    removeDevStorage(state);                    state.nextCommand = CommandProcessor.EXIT;                    break;                }                // fall through            default:                CommandProcessor.perform(state);                if (state.status == CommandProcessor.MIDLET_SUITE_NOT_FOUND) {                    System.out.println("The MIDlet suite was not found.");                } else if (state.initialCommand == CommandProcessor.INSTALL &&                        state.status == CommandProcessor.OK) {                    System.out.println("Storage name: " +                                       state.suiteStorageName);                }            }        } catch (InvalidJadException ije) {            System.out.println("** Error installing suite (" +                               ije.getReason() + "): " +                                messageForInvalidJadException(ije));        } catch (IOException ioe) {            System.out.println("** Error installing suite: " +                               ioe.getMessage());        } catch (ClassNotFoundException ex) {            if (state.initialCommand == CommandProcessor.MANAGE) {              state.runExceptionMessage =                    Resource.getString("The application cannot be launched. " +                    "One of the application classes appears to be missing. " +                    "This could be due to a mis-named class. Contact the " +                    "application provider to resolve the issue.");            } else {                System.out.println("MIDlet class(s) not found: " +                                    ex.getMessage());            }        } catch (InstantiationException ex) {            if (state.initialCommand == CommandProcessor.MANAGE) {               state.runExceptionMessage = Resource.getString(                   "The application cannot be launched. The application " +                   "may have done an illegal operation. Contact the " +                   "application provider to resolve the issue.") + "\n\n" +                   ex.getMessage();            } else {                System.out.println(                    "MIDlet instance(s) could not be created: " +                                  ex.getMessage());            }        } catch (IllegalAccessException ex) {            if (state.initialCommand == CommandProcessor.MANAGE) {                state.runExceptionMessage = Resource.getString(                   "The application cannot be launched. The application " +                   "may have done an illegal operation. Contact the " +                   "application provider to resolve the issue.") + "\n\n" +                   ex.getMessage();            } else {                System.out.println(                    "MIDlet class(s) could not be accessed: " +                     ex.getMessage());            }        } catch (OutOfMemoryError ex) {            if (state.initialCommand == CommandProcessor.MANAGE) {                state.runExceptionMessage = Resource.getString(                    "The application has unexpectedly quit because it ran " +                    "out of memory.");            } else {                System.out.println("The MIDlet has run out of memory");            }        } catch (IllegalArgumentException ex) {            System.out.println(ex.getMessage());        } catch (Throwable t) {            if (state.initialCommand == CommandProcessor.MANAGE) {               state.runExceptionMessage =                    Resource.getString("The application has unexpectedly " +                    " quit. Contact the application provider to resolve " +                    "the issue.") + "\n\n" + t.getMessage();            } else {                System.out.println("Exception caught in main:");                t.printStackTrace();                state.nextCommand = CommandProcessor.EXIT;            }        }        saveCommandState(state);        /*         * return any non-zero number so the native main can know that         * this is graceful exit and not the power button on the phone.         */        exitInternal(CommandProcessor.MAIN_EXIT);    }    /** Initialize the internal security for MIDP */    private static void initializeInternalSecurity() {        /*         * As the first caller to create a token we can pass in null         * for the security token.         */        internalSecurityToken =            new SecurityToken(null,               Permissions.forDomain(null, Permissions.INTERNAL_DOMAIN_NAME));        com.sun.midp.midletsuite.Installer.initSecurityToken(            internalSecurityToken);        com.sun.midp.rms.RecordStoreFile.initSecurityToken(            internalSecurityToken);        com.sun.midp.publickeystore.WebPublicKeyStore.initSecurityToken(            internalSecurityToken);        com.sun.midp.io.j2me.http.Protocol.initSecurityToken(            internalSecurityToken);        com.sun.midp.io.j2me.https.Protocol.initSecurityToken(            internalSecurityToken);        com.sun.midp.io.j2me.ssl.Protocol.initSecurityToken(            internalSecurityToken);        com.sun.midp.io.j2me.datagram.Protocol.initSecurityToken(            internalSecurityToken);	DisplayManagerFactory.initSecurityToken(internalSecurityToken);        com.sun.midp.midlet.MIDletState.initSecurityToken(            internalSecurityToken);	try {            ImplicitlyTrustedClass trustedClass;	    trustedClass = (ImplicitlyTrustedClass)		Class.forName("com.sun.midp.io.j2me.push.PushRegistryImpl").		newInstance();            trustedClass.initSecurityToken(internalSecurityToken);        } catch (Exception e) {            // Push is optional for now	    e.printStackTrace();        }    }    /**     * Runs a MIDlet that Manages installed MIDlet Suites.     *     * @param state command state to put the status and next command in     */    private static void manage(CommandState state) {        Installer installer;        MIDletSuite midletSuite;        String nextMidletSuiteToRun;        String[] propKeys;        String[] propValues;        // we need to get the installer now, before the security level drops        installer = Installer.getInstaller();        if (state.runExceptionMessage != null) {            propKeys = new String[2];            propValues = new String[2];            propKeys[1] = "run-message";            propValues[1] = state.runExceptionMessage;        } else {            propKeys = new String[1];            propValues = new String[1];        }                    // assume a class name of a MIDlet in the classpath        propKeys[0] = "logo-displayed";        if (state.logoDisplayed) {            propValues[0] = "T";        } else {            propValues[0] = "F";        }        state.logoDisplayed = true;        state.runExceptionMessage = null;        try {            ImplicitlyTrustedClass trustedClass;            String nameOfManager;            /*             * In internal.config an alternate graphical manager             * can be specified.             */            nameOfManager =            Configuration.getProperty("com.sun.midp.graphicalmanager");            if (nameOfManager == null) {                nameOfManager = "com.sun.midp.dev.Manager";            }            /* set trusted to false so, the trust icon will not show */            midletSuite =                DevMIDletSuiteImpl.create(internalSecurityToken, null,                nameOfManager, "manager_storage_", propKeys, propValues,                Permissions.INTERNAL_DOMAIN_NAME, false,                "Information is arriving for %1. " +                "Is it OK to launch %1?",                "%1 needs to start itself to check to see if it has " +                "received information. Is that OK?");            if (!Scheduler.getScheduler().schedule(midletSuite)) {                // shutdown, by push or the power button                state.nextCommand = CommandProcessor.EXIT;            }            // Check to see if we need to run a selected suite next            nextMidletSuiteToRun = installer.getNextMIDletSuiteToRun();            if (nextMidletSuiteToRun != null) {                state.nextCommand = CommandProcessor.RUN;                state.suiteStorageName = nextMidletSuiteToRun;                state.midletName = installer.getNextMIDletToRun();            }            state.status = CommandProcessor.OK;            return;        } catch (Throwable e) {            state.status = CommandProcessor.ERROR;            state.nextCommand = CommandProcessor.EXIT;            e.printStackTrace();        }    }    /**     * Lists the installed MIDlet Suites.     *     * @param state command state to put the status in     */    private static void list(CommandState state) {        Installer installer = Installer.getInstaller();        String[] appList;        MIDletSuite midletSuite;        String temp;        MIDletInfo midletInfo;                appList = installer.list();        if ((appList == null) || (appList.length == 0)) {            System.out.println("** No MIDlet Suites installed on phone");        } else {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -