FileDocCategorySizeDatePackage
CommandLineInstaller.javaAPI DocphoneME MR2 API (J2ME)7847Wed May 02 18:00:02 BST 2007com.sun.midp.scriptutil

CommandLineInstaller

public class CommandLineInstaller extends javax.microedition.midlet.MIDlet implements Runnable, InstallListener
A command-line installer. Allows to install midlet either from an http(s):// or from a file:// URL.

The MIDlet uses certain application properties as arguments:

  1. arg-0: currently must be "I" == install (for consistency with GraphicalInstaller)
  2. arg-1: URL of the midlet suite to install
  3. arg-2: a storage ID where to save the suite's jar file

Fields Summary
Constructors Summary
public CommandLineInstaller()
Create and initialize the MIDlet.

        new Thread(this).start();
    
Methods Summary
public booleanconfirmAuthPath(InstallState state)
Called with the current state of the install so the user can be asked to confirm the authentication path. If false is returned, the an I/O exception thrown and {@link Installer#wasStopped()} will return true if called.

param
state current state of the install.
return
true if the user wants to continue, false to stop the install

        return true;
    
public booleanconfirmJarDownload(InstallState state)
Called with the current state of the install so the user can be asked to confirm the jar download. If false is returned, the an I/O exception thrown and {@link Installer#wasStopped()} will return true if called.

param
state current state of the install.
return
true if the user wants to continue, false to stop the install

        return true;
    
public voiddestroyApp(boolean unconditional)
Destroy cleans up.

param
unconditional is ignored; this object always destroys itself when requested.

    
public booleankeepRMS(InstallState state)
Called with the current state of the install so the user can be asked to confirm if the RMS data should be kept for new version of an updated suite. If false is returned, the an I/O exception thrown and {@link Installer#wasStopped()} will return true if called.

param
state current state of the install.
return
true if the user wants to keep the RMS data for the next suite

        return true;
    
public voidpauseApp()
Pause; there are no resources that need to be released.

    
public voidrun()
Installs a new MIDlet suite.

        Installer installer = null;
        String installerClassName = null;
        final String supportedUrlTypes[] = {
            "http",  "HttpInstaller",
            "https", "HttpInstaller",
            "file", "FileInstaller"
        };

        // parse the arguments
        String arg0 = getAppProperty("arg-0");
        if (arg0 == null || !"I".equals(arg0)) {
            showUsage();
            notifyDestroyed();
            return;
        }

        String url = getAppProperty("arg-1");
        if (url == null) {
            showUsage();
            notifyDestroyed();
            return;
        }

        int storageId = Constants.INTERNAL_STORAGE_ID;
        String strStorageId = getAppProperty("arg-2");
        if (strStorageId != null) {
            try {
                storageId = Integer.parseInt(strStorageId);
            } catch (NumberFormatException nfe) {
                // Intentionally ignored
            }
        }

        // If a scheme is omitted, handle the url
        // as a file on the local file system.
        final String scheme = Installer.getUrlScheme(url, "file");

        for (int i = 0; i < supportedUrlTypes.length << 1; i++, i++) {
            if (supportedUrlTypes[i].equals(scheme)) {
                installerClassName = "com.sun.midp.installer." +
                    supportedUrlTypes[i+1];
                break;
            }
        }

        if (installerClassName != null) {
            try {
                installer = (Installer)
                    Class.forName(installerClassName).newInstance();
            } catch (Throwable t) {
                // Intentionally ignored: 'installer' is already null
            }
        }

        if (installer == null) {
            final String errMsg = "'" + scheme + "' URL type is not supported.";
            System.out.println("ERROR: " + errMsg);
            notifyDestroyed();
            return;
        }

        // install the suite
        int lastInstalledMIDletId;
        int len = url.length();
        boolean jarOnly = (len >= 4 &&
            ".jar".equalsIgnoreCase(url.substring(len - 4, len)));

        try {
            if (jarOnly) {
                lastInstalledMIDletId = installer.installJar(url, null,
                    storageId, false, false, this);
            } else {
                lastInstalledMIDletId =
                    installer.installJad(url, storageId, false, false, this);
            }

            System.out.println("The suite was succesfully installed, ID: " +
                               lastInstalledMIDletId);
        } catch (Throwable t) {
            System.err.println("Error installing the suite: " + t.getMessage());
            t.printStackTrace();
        }

        notifyDestroyed();
    
private voidshowUsage()
Prints a message about the midlet usage.

        System.out.println("Usage: ./runMidlet internal " +
                           "CommandLineInstaller I <url> [storageId]");
    
public voidstartApp()
Start.

    
public voidupdateStatus(int status, InstallState state)
Called with the current status of the install. See {@link Installer} for the status codes.

param
status current status of the install.
param
state current state of the install.

    
public booleanwarnUser(InstallState state)
Called with the current state of the install so the user can be asked to override the warning. To get the warning from the state call {@link InstallState#getLastException()}. If false is returned, the last exception in the state will be thrown and {@link Installer#wasStopped()} will return true if called.

param
state current state of the install.
return
true if the user wants to continue, false to stop the install

        return true;