jumpinstaller.java

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

JAVA
1,781
字号
/* * 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.jump.installer;import com.sun.midp.installer.Verifier;import com.sun.midp.installer.InstallListener;import com.sun.midp.installer.InvalidJadException;import com.sun.midp.installer.JadProperties;import com.sun.midp.installer.ManifestProperties;import com.sun.midp.installer.OtaNotifier;import com.sun.midp.installer.InstallState;import com.sun.midp.installer.VerifierImpl;import java.util.Vector;import java.io.IOException;import java.io.InputStream;import java.io.OutputStream;import java.io.ByteArrayInputStream;import javax.microedition.io.ConnectionNotFoundException;import com.sun.j2me.security.AccessController;import com.sun.midp.security.SecurityHandler;import com.sun.midp.security.SecurityToken;import com.sun.midp.security.Permissions;import com.sun.midp.main.MIDletSuiteVerifier;import com.sun.midp.main.MIDletAppImageGenerator;import com.sun.midp.midlet.MIDletSuite;import com.sun.midp.midletsuite.MIDletSuiteStorage;import com.sun.midp.midletsuite.MIDletSuiteImpl;import com.sun.midp.midletsuite.MIDletInfo;import com.sun.midp.midletsuite.MIDletSuiteInfo;import com.sun.midp.midletsuite.InstallInfo;import com.sun.midp.midletsuite.SuiteSettings;import com.sun.midp.midletsuite.MIDletSuiteLockedException;import com.sun.midp.midletsuite.MIDletSuiteCorruptedException;import com.sun.midp.jarutil.JarReader;import com.sun.midp.io.HttpUrl;import com.sun.midp.io.Util;import com.sun.midp.io.j2me.push.PushRegistryInternal;import com.sun.midp.io.j2me.storage.RandomAccessStream;import com.sun.midp.io.j2me.storage.File;import com.sun.midp.rms.RecordStoreFactory;// IMPL_NOTE: sync with cldc installer for CHManager dependency// import com.sun.midp.content.CHManager;import com.sun.midp.log.Logging;import com.sun.midp.log.LogChannels;import com.sun.midp.configurator.Constants;/** * An JUMPInstaller manages MIDlet suites and libraries * present in a Java application environment.  An MIDlet suite * distributed as a descriptor and JAR pair. * The descriptor identifies the configuration and contains security * information and the manifest of the JAR describes the contents. * The implementation of an JUMPInstaller is * specific to the platform and provides access to * procedures that make an MIDlet suite visible to users. * <P> * Each installed package is uniquely identified by a storage name * constructed from the combination * of the values of the <code>MIDlet-Name</code> and * <code>MIDlet-Vendor</code> attributes. * The syntax and content of the strings used to identify * installed packages are implementation dependent. * Only packages installed or upgraded using this API appear * in the list of known packages. * */public abstract class JUMPInstaller {    /** Status code to signal connection to the JAD server was successful. */    public static final int DOWNLOADING_JAD = 1;    /** Status code to signal that another 1K of the JAD has been download. */    public static final int DOWNLOADED_1K_OF_JAD = 2;    /** Status code to signal connection to the JAR server was successful. */    public static final int DOWNLOADING_JAR = 3;    /** Status code to signal that another 1K of the JAR has been download. */    public static final int DOWNLOADED_1K_OF_JAR = 4;    /**     * Status code to signal that download is done and the suite is being     * verified.     */    public static final int VERIFYING_SUITE = 5;    /**     * Status code to signal that application image is being generating.     */    public static final int GENERATING_APP_IMAGE = 6;    /**     * Status code to signal that suite classes are being verified.     */    public static final int VERIFYING_SUITE_CLASSES = 7;    /**     * Status code for local writing of the verified MIDlet suite.     * Stopping the install at this point has no effect, so there user     * should not be given a chance to stop the install.     */    public static final int STORING_SUITE = 8;    /** Status code for corrupted suite */    public static final int CORRUPTED_SUITE = 9;    /** System property containing the supported microedition profiles */    protected static final String MICROEDITION_PROFILES =        "microedition.profiles";    /** System property containing the microedition configuration */    protected static final String MICROEDITION_CONFIG =        "microedition.configuration";    /** System property containing the microedition locale */    protected static final String MICROEDITION_LOCALE = "microedition.locale";    /** Media-Type for valid application descriptor files. */    public static final String JAD_MT = "text/vnd.sun.j2me.app-descriptor";    /** Media-Type for valid Jar file. */    public static final String JAR_MT_1 = "application/java";    /** Media-Type for valid Jar file. */    public static final String JAR_MT_2 = "application/java-archive";    /**     * Filename to save the JAR of the suite temporarily. This is used     * to avoid overwriting an existing JAR prior to verification.     */    protected static final String TMP_FILENAME = "installer.tmp";    /** Midlet suite signature verifier. */    protected Verifier verifier;    /** Holds the install state. */    protected InstallStateImpl state;    /** An alias for more state.installInfo to get more compact record. */    protected InstallInfo info;    /** An alias for more state.suiteSettings to get more compact record. */    protected SuiteSettings settings;    /** Holds the CLDC configuration string. */    protected String cldcConfig;    /** Holds the device's Runtime Execution Environment string. */    protected final String cldcRuntimeEnv = "MIDP.CLDC";    /** Holds the MIDP supported profiles. */    private Vector supportedProfiles;    /** Use this to be the security domain for unsigned suites. */    protected String unsignedSecurityDomain =        Permissions.getUnsignedDomain();    /* SecurityToken provided by the user of the JUMPInstaller */    protected SecurityToken token = null;    /**     * Constructor of the JUMPInstaller.     */    public JUMPInstaller() {        state = getInstallState();        verifier = new VerifierImpl(state);        /* Aliases for more compact record. */        info = state.installInfo;        settings = state.suiteSettings;    }        /**     * Creates an instance of InstallState of the appropriate type     * depending on the installer type. Should be overloaded in the     * inherited classes.     *     * @return an instance of class containing the installation state     */    protected InstallStateImpl getInstallState() {        if (state == null) {            state = new InstallStateImpl();        }        return state;    }    /**     * Installs a software package from the given URL. The URL is assumed     * refer to an application descriptor.     * <p>     * If the component to be installed is the same as an existing     * component (by comparing the <code>MIDlet-Name</code>,     * <code>MIDlet-Vendor</code> attributes)     * then this install is an upgrade if the version number is greater     * than the current version.  If so, the new version replaces in its     * entirety the current version.     * <p>     * It is implementation dependent when the upgraded component is     * made available for use.     * <p>     * The implementation of install must be robust in the presence     * of failures such as running out of memory.  If this method     * throws an exception then the package must <em>not</em> be installed     * and any previous version of the component must be left intact     * and operational.     * <p>     * To receive status updates and installer warnings, provide an install     * listener. If no listener is provided all warnings will be thrown     * as exceptions.     *     * @param location the URL from which the application descriptor can be     *        updated     * @param storageId ID of the storage where the suite should be saved     * @param force if <code>true</code> the MIDlet suite components to be     *              installed will overwrite any existing components without     *              any version comparison     * @param removeRMS if <code>true</code> and existing RMS data will be     *              removed when overwriting an existing suite     * @param installListener object to receive status updates and install     *     warnings, can be null     *     * @return the unique ID of the installed package.     *     * @exception ConnectionNotFoundException if JAD URL is invalid     * @exception IOException is thrown if any error prevents the installation     *   of the MIDlet suite, including being unable to access the application     *   descriptor or JAR     * @exception InvalidJadException if the downloaded application descriptor     *   is invalid     * @exception MIDletSuiteLockedException is thrown, if the MIDletSuite is     * locked     * @exception SecurityException if the caller does not have permission     *   to install software     * @exception IllegalArgumentException is thrown, if the location of the     * descriptor file is not specified     */    public int installJad(String location, int storageId, boolean force,        boolean removeRMS, InstallListener installListener)            throws IOException, InvalidJadException,                   MIDletSuiteLockedException, SecurityException {        info.jadUrl = location;        state.force = force;        state.removeRMS = removeRMS;        state.nextStep = 1;        state.listener = installListener;        // IMPL_NOTE: sync with cldc installer for CHManager dependency        // state.chmanager = CHManager.getManager(null);        state.storageId = storageId;        return performInstall();    }    public int installJad(String location, String jadLocal, String jarLocal,         String encoding, int storageId, boolean force,        boolean removeRMS, InstallListener installListener)            throws IOException, InvalidJadException,                   MIDletSuiteLockedException, SecurityException {        state.localJarUrl = jarLocal;        state.localJadUrl = jadLocal;        state.jadEncoding = encoding;        return installJad(location, storageId, force, removeRMS,			  installListener);    }    /**     * Installs a software package from the given URL. The URL is assumed     * refer to a JAR.     * <p>     * If the component to be installed is the same as an existing     * component (by comparing the <code>MIDlet-Name</code>,     * <code>MIDlet-Vendor</code> attributes)     * then this install is an upgrade if the version number is greater     * than the current version.  If so, the new version replaces in its     * entirety the current version.     * <p>     * It is implementation dependent when the upgraded component is     * made available for use.     * <p>     * The implementation of install must be robust in the presence     * of failures such as running out of memory.  If this method     * throws an exception then the package must <em>not</em> be installed     * and any previous version of the component must be left intact     * and operational.     * <p>     * To receive status updates and installer warnings, provide an install     * listener. If no listener is provided all warnings will be thrown     * as exceptions.     *     * @param location the URL which the JAR originally came from     * @param name the name of the suite to be updated     * @param storageId ID of the storage where the suite should be saved     * @param force if <code>true</code> the MIDlet suite components to be     *              installed will overwrite any existing components without     *              any version comparison     * @param removeRMS if <code>true</code> and existing RMS data will be     *              removed when overwriting an existing suite     * @param installListener object to receive status updates and install     *     warnings, can be null     *     * @return the unique ID of the installed package.     *     * @exception IOException is thrown if any error prevents the installation     *   of the MIDlet suite, including being unable to access the JAR     * @exception InvalidJadException if the downloaded JAR is invalid     * @exception MIDletSuiteLockedException is thrown, if the MIDletSuite is     * locked     * @exception SecurityException if the caller does not have permission     *   to install software     * @exception IllegalArgumentException is thrown, if the location of the     * JAR specified     */    public int installJar(String location, String name, int storageId,            boolean force, boolean removeRMS, InstallListener installListener)                throws IOException, InvalidJadException,

⌨️ 快捷键说明

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