dynamiccomponentinstaller.java

来自「This is a resource based on j2me embedde」· Java 代码 · 共 187 行

JAVA
187
字号
/* * * * 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.installer;import java.io.IOException;import com.sun.midp.midletsuite.MIDletSuiteLockedException;import com.sun.midp.midletsuite.DynamicComponentStorage;import com.sun.midp.services.ComponentInfo;import com.sun.midp.configurator.Constants;/** * Installer for dynamic components. */public class DynamicComponentInstaller extends HttpInstaller {    DynamicComponentStorage componentStorage;    /**     * Constructor of the DynamicComponentInstaller.     */    public DynamicComponentInstaller() {        super();        componentStorage = DynamicComponentStorage.getComponentStorage();    }    /**     * Installs the component pointed by the given URL.     *     * @param suiteId ID of the suite that owns the component being installed     * @param url HTTP URL pointing to the application descriptor     *            or to the jar file of the component that must     *            be installed     * @param name user-friendly name of the component     *     * @return unique component identifier     *     * @throws java.io.IOException if the installation failed     * @throws InvalidJadException if the downloaded JAR is invalid     * @throws com.sun.midp.midletsuite.MIDletSuiteLockedException is thrown,     *            if the MIDletSuite is locked     * @throws SecurityException if the caller does not have permission     *            to install components     */    public int installComponent(int suiteId, String url, String name)            throws IOException, MIDletSuiteLockedException,                InvalidJadException, SecurityException {        int componentId;        info.id = suiteId;        info.isSuiteComponent = true;        try {            componentId = installJad(url, Constants.INTERNAL_STORAGE_ID,                                     true, true, null);        } catch (InvalidJadException ije) {            int reason = ije.getReason();            if (reason != InvalidJadException.INVALID_JAD_TYPE) {                throw ije;            }            // media type of JAD was wrong, it could be a JAR            String mediaType = ije.getExtraData();            if (Installer.JAR_MT_1.equals(mediaType) ||                Installer.JAR_MT_2.equals(mediaType)) {                // re-run as a JAR only install                componentId = installJar(url, name,                    Constants.INTERNAL_STORAGE_ID, true, true, null);            } else {                throw ije;            }        }        return componentId;    }    /**     * Checks that all necessary attributes are present in JAD and are valid.     *     * May be overloaded by subclasses that require presence of     * different attributes in JAD during the installation.     *     * @throws InvalidJadException if any mandatory attribute is missing in     *                             the JAD file or its value is invalid     */    protected void checkJadAttributes() throws InvalidJadException {        // don't check MIDlet-* attributes if this is a dynamic component    }    /**     * Checks that all necessary attributes are present in the manifest     * in the JAR file and are valid.     *     * May be overloaded by subclasses that require presence of     * different attributes in manifest during the installation.     *     * @throws InvalidJadException if any mandatory attribute is missing in     *                             the manifest or its value is invalid     */    protected void checkJarAttributes() throws InvalidJadException {        // don't check MIDlet-* attributes if this is a dynamic component    }    /**     * Assigns a new ID to the dynamic component being installed.     */    protected void assignNewId() {        info.componentId = componentStorage.createComponentId();    }    /**     * Stores the midlet suite being installed in the midlet suite storage.     *     * @throws IOException if an I/O error occured when storing the suite     * @throws MIDletSuiteLockedException if the suite is locked     */    protected void storeUnit() throws IOException, MIDletSuiteLockedException {        componentStorage.storeComponent(state.midletSuiteStorage, info,            settings, state.getDisplayName(), state.jadProps, state.jarProps);    }    /**     * See if there is an installed version of the component being installed     * and if so, make an necessary checks. Will set state fields, including     * the exception field for warning the user.     *     * @exception InvalidJadException if the new version is formated     * incorrectly     * @exception MIDletSuiteLockedException is thrown, if the MIDletSuite is     * locked     */    protected void checkPreviousVersion()            throws InvalidJadException, MIDletSuiteLockedException {        int id;        DynamicComponentStorage dcs =                DynamicComponentStorage.getComponentStorage();        id = dcs.getComponentId(info.suiteVendor, info.suiteName);        if (id == ComponentInfo.UNUSED_COMPONENT_ID) {            // there is no previous version            return;        }        info.componentId = id;        if (state.force) {            // do not ask questions, force an overwrite            return;        }        /*         * Don't check version, just inform the user that the         * component is already installed.         */        state.exception = new InvalidJadException(                          InvalidJadException.ALREADY_INSTALLED,                          "n/a");    }}

⌨️ 快捷键说明

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