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

📄 installer.java

📁 有关j2me的很好的例子可以研究一下
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
/** * * @(#)Installer.java	1.31 01/08/22 * * Copyright 2001 by Sun Microsystems, Inc., * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A. * All rights reserved. */package com.sun.midp.midletsuite;import java.util.Vector;import java.io.IOException;import java.io.InputStream;import java.io.OutputStream;import java.io.ByteArrayOutputStream;import java.io.ByteArrayInputStream;import java.io.DataOutputStream;import java.io.DataInputStream;import java.lang.String;import java.lang.IllegalArgumentException;import javax.microedition.io.Connector;import javax.microedition.io.Connection;import javax.microedition.io.HttpConnection;import javax.microedition.io.ConnectionNotFoundException;import com.sun.midp.security.SecurityDomain;import com.sun.midp.security.Actions;import com.sun.midp.Configuration;import com.sun.midp.midlet.Scheduler;import com.sun.midp.midlet.MIDletSuite;import com.sun.midp.io.Base64;import com.sun.midp.io.Properties;import com.sun.midp.io.HttpUrl;import com.sun.midp.io.j2me.storage.RandomAccessStream;import com.sun.midp.io.j2me.storage.File;/** * An Installer manages MIDlet suites and libraries * present in a Java application environment.  An MIDlet suite * or extension library is 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 Installer 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 class Installer {    /**     * 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 = 1;    /** Filename of Manifest inside the application archive. */    public static final String JAR_MANIFEST       = "META-INF/MANIFEST.MF";    /** MIDlet property for the size of the application data. */    public static final String DATA_SIZE_PROP     = "MIDlet-Data-Size";    /** MIDlet property for the size of the application archive. */    public static final String JAR_SIZE_PROP      = "MIDlet-Jar-Size";    /** MIDlet property for the application archive URL. */    public static final String JAR_URL_PROP       = "MIDlet-Jar-URL";    /** MIDlet property for the suite name. */    public static final String SUITE_NAME_PROP    = "MIDlet-Name";    /** MIDlet property for the suite vendor. */    public static final String VENDOR_PROP        = "MIDlet-Vendor";    /** MIDlet property for the suite version. */    public static final String VERSION_PROP       = "MIDlet-Version";    /** MIDlet property for the install notify URL. */    public static final String NOTIFY_PROP        = "MIDlet-Install-Notify";    /** MIDlet property for the microedition configuration. */    public static final String CONFIGURATION_PROP =        "MicroEdition-Configuration";    /** MIDlet property for the profile. */    public static final String PROFILE_PROP       = "MicroEdition-Profile";    /** Max number of bytes to download at one time. */    private static final int MAX_DL_SIZE = 1024;    /** Tag that signals that the HTTP server supports basic auth. */    private static final String BASIC_TAG = "basic";    /** Tag that marks the version in cookie. */    private static final String VERSION_TAG = "version";    /** Tag that marks the domain in cookie. */    private static final String DOMAIN_TAG = "domain";    /** Tag that marks the path in cookie. */    private static final String PATH_TAG = "path";    /** Media-Type for valid application descriptor files. */    static final String JAD_MT = "text/vnd.sun.j2me.app-descriptor";    /** Media-Type for valid Jar file. */    static final String JAR_MT_1 = "application/java";    /** Media-Type for valid Jar file. */    static final String JAR_MT_2 = "application/java-archive";    /** Filename to save the domain owner of the suite. */    static final String DOMAIN_OWNER_FILENAME  = "domainOwner.utf";    /** Filename to save the URL of the JAD. */    static final String JAD_URL_FILENAME  = "jadUrl.utf";    /** Filename to save the encoding of the JAD. */    static final String JAD_ENCODING_FILENAME  = "jadEncoding.utf";    /** Filename to suite JAR. */    static final String JAR_FILENAME = "suite.jar";    /** Filename to save the suite application descriptor. */    static final String JAD_FILENAME = "suite.jad";    /**     * Filename to save the JAR of the suite temporarily. This is used     * to avoid overwriting an existing JAR prior to     * verification.     */    static final String TMP_FILENAME      = "installer.tmp";    /** Filename to save the application manifest. */    static final String MANIFEST_FILENAME = "suite.mf";    /** Filename of the list of installed suites. */    static final String SUITE_LIST_FILENAME = "suites.utf";    /** Success message for the suite provider. */    static final String SUCCESS_MSG = "900 Success";    /** Error message for the suite provider. */    static final String INSUFFICIENT_MEM_MSG = "901 Insufficient Memory";    /** Error message for the suite provider. */    static final String USER_CANCELLED_MSG = "902 User Cancelled";    /** Error message for the suite provider. */    static final String JAR_SIZE_MISMATCH_MSG = "904 JAR Size Mismatch";    /** Error message for the suite provider. */    static final String ATTRIBUTE_MISMATCH_MSG = "905 Attribute Mismatch";    /** Error message for the suite provider. */    static final String INVALID_JAD_MSG = "906 Invalid Descriptor";    /** Error message for the suite provider. */    static final String INVALID_JAR_MSG = "907 Invalid JAR";    /** Error message for the suite provider. */    static final String INCOMPATIBLE_MSG =        "908 Incompatible Configration or Profile";    /** Private reference to the singleton Installer class. */    private static Installer myInstaller;    /** This class has a different security domain than the MIDlet suite. */    private static SecurityDomain classSecurityDomain;    /** The unique storage name of the next MIDlet suite to run. */    private String nextMidletSuiteToRun;    /** The of the next MIDlet to run. */    private String nextMidletToRun;     /** Cache of installed MIDlet suites. */    private Vector midletSuiteList;    /** HTTP connection to close when we stop the installation. */    private HttpConnection httpConnection;    /** HTTP stream to close when we stop the installation. */    private InputStream httpInputStream;    /** Receives warnings and status. */    private InstallListener listener;    /** Holds the install state. */    private InstallStateImpl state;    /**     * Initializes the security domain for this class, so it can     * perform actions that a normal MIDlet Suite cannot.     *     * @param theDomain SecurityDomain for this class.     */    public static void initSecurityDomain(SecurityDomain theDomain) {        if (classSecurityDomain != null) {            return;        }        classSecurityDomain = theDomain;        MIDletSuiteImpl.initSecurityDomain(classSecurityDomain);    }    /**     * Return a reference to the singleton Installer object.     *     * @return the installer reference.     *     * @exception SecurityException if the caller does not have permission     *   to install software.     */    public static Installer getInstaller() throws SecurityException {        MIDletSuite midletSuite = Scheduler.getScheduler().getMIDletSuite();        // if a MIDlet suite is not scheduled, assume the JAM is calling.        if (midletSuite != null) {            midletSuite.checkIfPermitted(Actions.LIFECYCLE_MANAGEMENT);        }        return getInstallerCommon();    }    /**     * Return a reference to the singleton Installer object.     *     * @param securityDomain security domain of the calling class     *     * @return the installer reference.     *     * @exception SecurityException if the caller does not have permission     *   to install software.     */    public static Installer getInstaller(SecurityDomain securityDomain)           throws SecurityException {        securityDomain.checkIfPermitted(Actions.LIFECYCLE_MANAGEMENT);        return getInstallerCommon();    }    /**     * Return a reference to the singleton Installer object.     *     * @return the installer reference.     */    private static Installer getInstallerCommon() {        String nameOfInstaller;        if (myInstaller != null) {            return myInstaller;        }        /*         * In internal.config an alternate installer, such as a         * SecureInstaller can be specified.         */        nameOfInstaller =            Configuration.getProperty("com.sun.midp.midletsuite.installer");        if (nameOfInstaller == null) {            myInstaller = new Installer();            return myInstaller;        }                try {            myInstaller =                 (Installer)Class.forName(nameOfInstaller).newInstance();            return myInstaller;        } catch (Exception e) {            throw new RuntimeException(e.getMessage());        }    }    /**     * This method returns a storage identifier of an application.     *     * @param vendorName name of the vendor that created the application, as     *          given in a JAD file.     * @param appName name of the application, as given in a JAD file.     *     * @return the platform-specific storage name of the application     *          given by vendorName and appName.     */    public static String makeStorageName(String vendorName, String appName) {        return File.unicodeToAsciiFilename(vendorName) + '_' +            File.unicodeToAsciiFilename(appName) + '_';    }    /**     * Constructor to prevent a second instantiation of the Installer.     */    protected Installer() {        if (myInstaller != null) {            throw new                SecurityException("Illegal instantiation of the Installer");        }    }    /**     * Install a software package from the given URL. The URL MUST     * 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 force if <code>true</code> the MIDlet suite components to be     *              installed will overwrite any existing components without     *              any version comparison.     * @param installListener object to receive status updates and install     *     warnings, can be null     *     * @return the unique name 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 SecurityException if the caller does not have permission     *   to install software.     */    public String install(String location, boolean force,            InstallListener installListener)            throws IOException, InvalidJadException, SecurityException {        state = new InstallStateImpl();        state.jadUrl = location;        state.force = force;        state.nextStep = 1;        listener = installListener;        return performInstall();    }    /**     * Same as {@link #install(String, boolean, InstallListener)} but starting     * with a downloaded JAD and other associated information.     *

⌨️ 快捷键说明

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