midletsuitestorage.java

来自「This is a resource based on j2me embedde」· Java 代码 · 共 774 行 · 第 1/2 页

JAVA
774
字号
/* * * * Copyright  1990-2007 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER *  * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License version * 2 only, as published by the Free Software Foundation. *  * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License version 2 for more details (a copy is * included at /legal/license.txt). *  * You should have received a copy of the GNU General Public License * version 2 along with this work; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA *  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa * Clara, CA 95054 or visit www.sun.com if you need additional * information or have any questions. */package com.sun.midp.midletsuite;import java.io.IOException;import com.sun.j2me.security.AccessController;import com.sun.midp.security.SecurityToken;import com.sun.midp.security.Permissions;import com.sun.midp.midlet.MIDletSuite;import com.sun.midp.content.CHManager;import com.sun.midp.jarutil.JarReader;import com.sun.midp.util.Properties;import com.sun.midp.configurator.Constants;import com.sun.midp.rms.RecordStoreImpl;import com.sun.midp.log.Logging;import com.sun.midp.log.LogChannels;/** * This class manages the persistent data for MIDlet suites. * <P> * Each installed package is uniquely identified by a unique ID. * Only suites installed or updated using this API appear * in the list of known suites. */public class MIDletSuiteStorage {    /** This class has a different security domain than the MIDlet suite. */    private static SecurityToken classSecurityToken;    /** This is the master storage object to synchronize all accesses */    private static MIDletSuiteStorage masterStorage;    /**     * Initializes the security token for this class, so it can     * perform actions that a normal MIDlet Suite cannot.     *     * @param token security token for this class.     */    public static void initSecurityToken(SecurityToken token) {        if (classSecurityToken != null) {            return;        }        classSecurityToken = token;        MIDletSuiteImpl.initSecurityToken(classSecurityToken);    }    /**     * Returns a reference to the singleton MIDlet suite storage object.     * <p>     * Method requires the com.sun.midp.ams permission.     *     * @return the storage reference     *     * @exception SecurityException if the caller does not have permission     *   to install software     */    public static MIDletSuiteStorage getMIDletSuiteStorage()            throws SecurityException {        AccessController.checkPermission(Permissions.AMS_PERMISSION_NAME);        return getMasterStorage();    }    /**     * Returns a reference to the singleton MIDlet suite storage object.     *     * @param securityToken security token of the calling class     *     * @return the storage reference     *     * @exception SecurityException if the caller does not have permission     *   to manage midlets     */    public static MIDletSuiteStorage getMIDletSuiteStorage(           SecurityToken securityToken) throws SecurityException {        securityToken.checkIfPermissionAllowed(Permissions.AMS);        return getMasterStorage();    }    /**     * Java interface for midp_suiteid2pcsl_string().     *     * @param suiteId unique ID of the suite     *     * @return string representation of the given suiteId     */    public static native String suiteIdToString(int suiteId);    /**     * Returns a reference to the singleton storage object.     *     * @return the storage reference     */    private static MIDletSuiteStorage getMasterStorage() {        if (masterStorage == null) {            masterStorage    = new MIDletSuiteStorage();            int status = loadSuitesIcons0();            if (Logging.REPORT_LEVEL <= Logging.ERROR) {                if (status != 0) {                    Logging.report(Logging.ERROR, LogChannels.LC_AMS,                        "Can't load the cached icons, error code: " + status);                }            }        }        return masterStorage;    }    /**     * Private constructor to prevent outside instantiation.     */    private MIDletSuiteStorage() {    }    /**     * Gets the MIDlet Suite from storage, and selects one midlet to be run.     *     * @param id the unique ID of the suite given     *        by the installer when it was downloaded     * @param update true is this MIDletSuite need to be updated     *     * @exception MIDletSuiteLockedException is thrown, if the MIDletSuite is     * locked; MIDletSuiteCorruptedException is thrown if the MIDletSuite is     * corrupted     * @exception MIDletSuiteCorruptedException if the suite is corrupted     *     * @return MIDlet Suite reference or null if the suite doesn't exist     */    public synchronized MIDletSuiteImpl getMIDletSuite(int id,            boolean update)            throws MIDletSuiteLockedException, MIDletSuiteCorruptedException {        if (!suiteExists(id)) {            return null;        }        MIDletSuiteImpl.lockMIDletSuite(id, update);        /*         * save on startup time, get the properties at first getProperty call         * and fill permissions on getPermission         */        return new MIDletSuiteImpl(id);    }    /**     * Reads the basic information about the midlet suite from the storage.     *     * @param id unique ID of the suite     *     * @exception IOException if an the information cannot be read     * @exception IllegalArgumentException if suiteId is invalid     *     * @return MIDletSuiteInfo object with the suite's attributes     */    public synchronized MIDletSuiteInfo getMIDletSuiteInfo(int id)            throws IOException, IllegalArgumentException {        MIDletSuiteInfo msi = new MIDletSuiteInfo(id);        getMIDletSuiteInfoImpl0(id, msi);        return msi;    }    /**     * Retrieves an icon for the given midlet suite.     *     * @param suiteId unique identifier of the suite     * @param iconName the name of the icon to retrieve     *     * @return image of the icon as a byte array     */    public synchronized byte[] getMIDletSuiteIcon(int suiteId,                                                  String iconName) {        byte[] iconBytes = null;        if (iconName == null) {            return null;        }        try {            iconBytes = getMIDletSuiteIcon0(suiteId, iconName);            if (iconBytes == null) {                /* Search for icon in the image cache */                iconBytes = loadCachedIcon0(suiteId, iconName);            }            if (iconBytes == null) {                /* Search for icon in the suite JAR */                iconBytes = JarReader.readJarEntry(                    getMidletSuiteJarPath(suiteId), iconName);            }        } catch (Exception e) {            iconBytes = null;        }        return iconBytes;    }    /**     * Get the midlet suite's class path including a path to the MONET     * image of the specified suite and a path to the suite's jar file.     *     * @param id unique ID of the suite     *     * @return class path or null if the suite does not exist     */    public synchronized String[] getMidletSuiteClassPath(int id) {        String jarFile = getMidletSuiteJarPath(id);        if (Constants.MONET_ENABLED && id != MIDletSuite.INTERNAL_SUITE_ID) {            String bunFile = getMidletSuiteAppImagePath(id);            return new String[] {bunFile, jarFile};        }        return new String[] {jarFile};    }    /**     * Loads the cached icons from the permanent storage into memory.     *     * @return status code (0 if no errors)      */    public static native int loadSuitesIcons0();    /**     * Retrieves the cached icon from the icon cache.     *     * @param suiteId unique identifier of the suite     * @param iconName the name of the icon to retrieve     *     * @return cached image data if available, otherwise null     */    private static native byte[] getMIDletSuiteIcon0(int suiteId,                                                     String iconName);    /**     * Loads suite icon data from image cache.     *     * @param suiteId the ID of suite the icon belongs to     * @param iconName the name of the icon to be loaded     *     * @return cached image data if available, otherwise null     */    private static native byte[] loadCachedIcon0(int suiteId, String iconName);    /**     * Reads the basic information about the midlet suite from the storage.     *     * @param id unique ID of the suite     * @param msi object to fill     *     * @exception IOException if an the information cannot be read     * @exception IllegalArgumentException if suiteId is invalid     */    public native void getMIDletSuiteInfoImpl0(int id,        MIDletSuiteInfo msi) throws IOException, IllegalArgumentException;    /**     * Get the path for the MONET image of the specified suite.     *     * @param id unique ID of the suite     *     * @return image path or null if the suite does not exist     */    public synchronized native String getMidletSuiteAppImagePath(int id);    /**     * Get the class path for a suite.     *     * @param id unique ID of the suite     *     * @return class path or null if the suite does not exist     */    public synchronized native String getMidletSuiteJarPath(int id);    /**     * Get the storage id for a suite.     *     * @param id unique ID of the suite     *     * @return storage id or null if the suite does not exist     */    public native static int getMidletSuiteStorageId(int id);    /**     * Get the folder id for a suite.     *     * @param id unique ID of the suite     *     * @return folder id or -1 if the suite does not exist     */    public native static int getMidletSuiteFolderId(int id);    /**     * Gets the unique identifier of MIDlet suite.     *     * @param vendor name of the vendor that created the application, as     *        given in a JAD file     * @param name name of the suite, as given in a JAD file     *     * @return suite ID of the midlet suite given by vendor and name     *         or MIDletSuite.UNUSED_SUITE_ID if the suite does not exist     */    public static native int getSuiteID(String vendor, String name);    // -------------- Installer related functionality ---------------    /**     * Get the installation information of a suite.     *     * @param midletSuite Suite object     *     * @return installation information     *     * @exception IOException if an the information cannot be read     */    InstallInfo getInstallInfo(MIDletSuiteImpl midletSuite)            throws IOException {        return midletSuite.getInstallInfo();    }    /**     * Tells if a suite exists.     *     * @param id ID of a suite     *     * @return true if a suite of the given storage name     *          already exists on the system     *     * @exception MIDletSuiteCorruptedException is thrown if the     * MIDletSuite is corrupted     */    public native boolean suiteExists(int id)        throws MIDletSuiteCorruptedException;    /**     * Returns a unique identifier of MIDlet suite.     *     * @return the platform-specific storage name of the application     *          given by vendorName and appName     */    public native int createSuiteID();    /**     * Stores or updates a midlet suite.     *     * @param installInfo structure containing the following information:<br>     * <pre>     *     id - unique ID of the suite;     *     jadUrl - where the JAD came from, can be null;     *     jarUrl - where the JAR came from;

⌨️ 快捷键说明

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