📄 installer.java
字号:
* Note that version number only has to * increase if data has been removed, not if new data has been * added to the end of the file. */ storageStream.writeByte(1); storageStream.writeBoolean(trusted); storageStream.writeByte(pushInterruptSetting); storageStream.writeByte(currentLevels.length); for (int i = 0; i < currentLevels.length; i++) { storageStream.writeByte(currentLevels[i]); } storageStream.writeByte(maximums.length); for (int i = 0; i < maximums.length; i++) { storageStream.writeByte(maximums[i]); } // Add new items at the end of the file } finally { try { storage.disconnect(); } catch (IOException e) { // ignore } } } /** * Returns 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.checkIfPermissionAllowed(Permissions.AMS); } return getInstallerCommon(); } /** * Returns a reference to the singleton Installer object. * * @param securityToken security token of the calling class * * @return the installer reference * * @exception SecurityException if the caller does not have permission * to install software */ public static Installer getInstaller(SecurityToken securityToken) throws SecurityException { securityToken.checkIfPermissionAllowed(Permissions.AMS); return getInstallerCommon(); } /** * Returns 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 SecureInstaller(); return myInstaller; } try { myInstaller = (Installer)Class.forName(nameOfInstaller).newInstance(); return myInstaller; } catch (Exception e) { throw new RuntimeException(e.getMessage()); } } /** * 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"); } } /** * 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 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 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 * @exception IllegalArgumentException is thrown, if the location of the * descriptor file is not specified */ public String installJad(String location, boolean force, boolean removeRMS, InstallListener installListener) throws IOException, InvalidJadException, SecurityException { state = new InstallStateImpl(); state.jadUrl = location; state.force = force; state.removeRMS = removeRMS; state.nextStep = 1; state.listener = installListener; return performInstall(); } /** * 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 from which the JAR 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 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 name 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 SecurityException if the caller does not have permission * to install software * @exception IllegalArgumentException is thrown, if the location of the * JAR specified */ public String installJar(String location, boolean force, boolean removeRMS, InstallListener installListener) throws IOException, InvalidJadException, SecurityException { if (location == null || location.length() == 0) { throw new IllegalArgumentException("Must specify URL of .jar file"); } state = new InstallStateImpl(); state.jarUrl = location; state.force = force; state.removeRMS = removeRMS; state.nextStep = 4; state.listener = installListener; return performInstall(); } /** * Performs an install. * * @return the unique name of the installed package * * @exception IOException is thrown, if an I/O error occurs during * descriptor or jar file download * @exception InvalidJadException is thrown, if the descriptor file is not * properly formatted or does not contain the required * information * @exception IllegalArgumentException is thrown, if the * descriptor file is not specified */ private synchronized String performInstall() throws IOException, InvalidJadException { /* Disable push interruptions during install. */ PushRegistryImpl.enablePushLaunch(classSecurityToken, false); try { state.startTime = System.currentTimeMillis(); while (state.nextStep < 7) { /* * clear the previous warning, so we can tell if another has * happened */ state.exception = null; if (state.stopInstallation) { postInstallMsgBackToProvider(USER_CANCELLED_MSG); throw new IOException("stopped"); } switch (state.nextStep) { case 1: installStep1(); break; case 2: installStep2(); break; case 3: installStep3(); break; case 4: installStep4(); break; case 5: installStep5(); break; case 6: installStep6(); break; } if (state.exception != null) { if (state.listener == null) { throw state.exception; } if (!state.listener.warnUser(state)) { state.stopInstallation = true; postInstallMsgBackToProvider(USER_CANCELLED_MSG); throw state.exception; } } } } finally { PushRegistryImpl.enablePushLaunch(classSecurityToken, true); } return state.storageName; } /** * Downloads the JAD, save it in the install state. * Parse the JAD, make sure it has * the required properties, and save them in the install state. * * @exception IOException is thrown, if an I/O error occurs during * descriptor or jar file download * @exception InvalidJadException is thrown, if the descriptor file is not * properly formatted or does not contain the required attributes * @exception IllegalArgumentException is thrown, if the * descriptor file is not specified */ private void installStep1() throws IOException, InvalidJadException { if (state.jadUrl == null || state.jadUrl.length() == 0) { throw new IllegalArgumentException("Must specify URL of .jad file"); } state.jad = downloadJAD(); if (state.exception != null) { return;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -