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

📄 devmidletsuiteimpl.java

📁 有关j2me的很好的例子可以研究一下
💻 JAVA
字号:
/** * * @(#)DevMIDletSuiteImpl.java	1.13 01/08/29 * * Copyright 2001 by Sun Microsystems, Inc., * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A. * All rights reserved. */package com.sun.midp.dev;import java.io.*;import javax.microedition.io.Connector;import com.sun.midp.security.SecurityDomain;import com.sun.midp.security.Actions;import com.sun.midp.midlet.MIDletSuite;import com.sun.midp.midlet.Scheduler;import com.sun.midp.midlet.MIDletInfo;import com.sun.midp.io.j2me.storage.RandomAccessStream;import com.sun.midp.io.j2me.storage.File;import com.sun.midp.midletsuite.JadProperties;import com.sun.midp.midletsuite.ManifestProperties;import com.sun.midp.midletsuite.MIDletSuiteImpl;import com.sun.midp.midletsuite.InvalidJadException;/** * Implements a the required MIDletSuite functionality needed by the * Scheduler. The class is only need for development environments. */public class DevMIDletSuiteImpl extends MIDletSuiteImpl {    /** Buffered properties from the application descriptor */    private JadProperties bufferedJadProps = null;    /** Initial midlet class name. */    private String initialMIDletClassName = null;    /** Storage path for this MIDlet suite */    private String storageRoot = null;    /**     * number of midlets in this suite. less than 0 mean they need to     * counted     */    private int numberOfMidlets = -1;    /**     * Constructs MIDletSuiteImpl from a raw JAD.     * Assumes the suite is super trusted.     *     * @param jadFilename filename of the descriptor for the suite     * @param midletClassName class name of the MIDlet to run when this     *                        suite is scheduled     * @param storageName name to separate this suite's storage from others     * @exception IOException is thrown if any error prevents the installation     *   of the MIDlet suite     * @exception InvalidJadException if the downloaded application descriptor     *   is invalid     */    public DevMIDletSuiteImpl(String jadFilename, String midletClassName,                              String storageName) throws IOException,            InvalidJadException {        initialize(jadFilename, midletClassName, storageName);        // without a jad we must assume at least one MIDlet        if (jadFilename == null) {            numberOfMidlets = 1;        }    }    /**     * Constructs MIDletSuiteImpl from a raw JAD.     * Assumes the suite is super trusted.     *     * @param jadFilename filename of the descriptor for the suite     * @param midletClassName class name of the MIDlet to run when this     *                        suite is scheduled     * @exception IOException is thrown if any error prevents the installation     *   of the MIDlet suite     * @exception InvalidJadException if the downloaded application descriptor     *   is invalid     */    public DevMIDletSuiteImpl(String jadFilename, String midletClassName)            throws IOException, InvalidJadException {        initialize(jadFilename, midletClassName, "run_by_class_storage_");    }    /**     * Initialize the MIDletSuite.     * Assumes the suite is super trusted.     *     * @param jadFilename filename of the descriptor for the suite     * @param midletClassName class name of the MIDlet to run when this     *                        suite is scheduled     * @param storageName name to separate this suite's storage from others     */    private void initialize(String jadFilename, String midletClassName,                       String storageName) throws IOException,            InvalidJadException {        MIDletSuite midletSuite;        RandomAccessStream storage;        InputStream jadStream;        midletSuite = Scheduler.getScheduler().getMIDletSuite();        // if a MIDlet suite is not scheduled, assume the JAM is calling.        if (midletSuite != null) {            midletSuite.checkIfPermitted(Actions.DEVICE_CORE_FUNCTION);        }        if (jadFilename != null) {            storage = new RandomAccessStream();            storage.connect(jadFilename, Connector.READ);            try {                jadStream = storage.openInputStream();                bufferedJadProps = new JadProperties();                bufferedJadProps.load(jadStream);            } finally {                storage.disconnect();            }        }        storageRoot = File.getStorageRoot() + storageName;        initialMIDletClassName = midletClassName;        numberOfMidlets = countMIDlets();    }    /**     * Get a property of the suite. A property is an attribute from     * the application descriptor.     *     * @param key the name of the property     * @return A string with the value of the property.     * 		<code>null</code> is returned if no value is available for     *          the key.     */    public String getProperty(String key) {        String prop;        if (bufferedJadProps == null) {            return null;        }        return bufferedJadProps.getProperty(key);    }    /**     * Provides the number of of MIDlets in this suite.     *     * @return number of MIDlet in the suite     */    public int getNumberOfMIDlets() {        return numberOfMidlets;    }    /**     * Loads the initial midlet to run.     *     * @exception ClassNotFoundException if one of the MIDlet classes cannot     * be found     * @exception InstantiationException if an instance cannot be created     * @exception IllegalAccessException if an instance cannot be accessed     */      public void loadInitialMIDlet() throws            ClassNotFoundException, InstantiationException,            IllegalAccessException {        loadInitialMIDlet(initialMIDletClassName, false);    }    /**     * Gets the name of the security domain for the suite.     * This method will always return "untrusted".     *     * @return name of security domain     */    public String getSecurityDomainName() {        return "untrusted";    }    /**     * Check to see the domain permitted to perform a specific action.     * This method will always throw a security exception.     *     * @param action an action code from com.sun.midp.security.Action     * @exception SecurityException if the domain is not     *            permitted to perform the specified action.     */    public void checkIfPermitted(int action) {        throw new SecurityException();    }    /**     * Schedules this MIDlet suite to run.     * Returns after the last midlet has been destroyed.     * @exception ClassNotFoundException if one of the MIDlet classes cannot     * be found.     * @exception InstantiationException if an instance can not be created.     */    public void schedule() throws            ClassNotFoundException, InstantiationException,            IllegalAccessException {        // assume the default scheduler        Scheduler.getScheduler().schedule(this);    }    /**     * Gets the path root of any file this suite.     * Has any needed file separators appended.     *     * @return storage path root     */    public String getStorageRoot() {        return storageRoot;    }    /**     * Get a named resource out of the JAR of this MIDlet suite.     *     * @param name name of the resource     * @return raw bytes of the resource or null if not available     */    public byte[] getResource(String name) {        return null;    }    /**     * Get the amount of storage on the device that this suite is using.     * This includes the JAD, JAR, management data, and RMS.     *     * @return number of bytes of storage the suite is using.     */    public int getStorageUsed() {        return 0;    }    /**     * The URL that the JAD of the suite was downloaded from.     *     * @return URL of the JAD, never null, even in development environments     */    public String getJadUrl() {        return "None";    }}

⌨️ 快捷键说明

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