FileDocCategorySizeDatePackage
SuiteVerifier.javaAPI DocphoneME MR2 API (J2ME)8820Wed May 02 18:00:02 BST 2007com.sun.midp.installer

SuiteVerifier

public class SuiteVerifier extends javax.microedition.midlet.MIDlet implements CommandListener
The Graphical MIDlet suite classes verifier application.

Fields Summary
private Display
display
Display for this MIDlet
private Command
backCommand
Command object for "Back" command in the suite verification form
private Form
progressForm
Displays the progress of the verification
private int
progressGaugeIndex
Gauge for progress form index.
private String
jarPath
Path to the JAR package to be verified
private int
suiteId
Suite ID of the suite whose classes are verified
private com.sun.midp.midletsuite.MIDletSuiteStorage
suiteStorage
Suite storage
Constructors Summary
public SuiteVerifier()
Create and initialize a new discovery application MIDlet. The saved URL is retrieved and the list of MIDlets are retrieved.

        display = Display.getDisplay(this);

        String strSuiteId = getAppProperty("arg-0");
        try {
            suiteId = Integer.parseInt(strSuiteId);
        } catch (RuntimeException ex) {
            suiteId = MIDletSuite.UNUSED_SUITE_ID;
        }

        suiteStorage = MIDletSuiteStorage.getMIDletSuiteStorage();
        jarPath = suiteStorage.getMidletSuiteJarPath(suiteId);

        if (jarPath == null) {
            exit(false);
            return;
        }
        createProgressForm();
        new Thread(new BackgroundVerifier(this, jarPath)).start();
    
Methods Summary
public voidcommandAction(Command command, Displayable displayable)

param
command
param
displayable

        if(command == backCommand) {
            destroyApp(false);
            notifyDestroyed();
        } else if (command == Alert.DISMISS_COMMAND) {
            // goto back to the manager midlet
            exit(false);
        }
    
private FormcreateProgressForm()
Create main form for suite classes verification

return
Created form instance


        progressForm = new Form(null);
        progressForm.setTitle(Resource.getString(
            ResourceConstants.AMS_CLASS_VERIFIER_TITLE));
        Gauge progressGauge = new Gauge(
            Resource.getString(
            ResourceConstants.AMS_CLASS_VERIFIER_GAUGE_LABEL),
            false, Gauge.INDEFINITE,
            Gauge.CONTINUOUS_RUNNING);

        progressGaugeIndex = progressForm.append(progressGauge);
        backCommand = new Command(Resource.getString(
            ResourceConstants.BACK), Command.BACK, 1);
        progressForm.addCommand(backCommand);
        progressForm.setCommandListener(this);
        display.setCurrent(progressForm);
        return progressForm;
    
public voiddestroyApp(boolean unconditional)
Destroy cleans up.

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

    
private voiddisplaySuccessMessage(java.lang.String successMessage)
Alert the user that an action was successful.

param
successMessage message to display to user

        Image icon;
        Alert successAlert;
        icon = GraphicalInstaller.getImageFromInternalStorage("_dukeok8");

        successAlert = new Alert(null, successMessage, icon, null);
        successAlert.setTimeout(GraphicalInstaller.ALERT_TIMEOUT);
        // Provide a listener to disable the advance-to-next-displayable
        // feature of Alert.
        successAlert.setCommandListener(
            new CommandListener() {
                public void commandAction(Command c, Displayable d) { }
            }
        );
        display.setCurrent(successAlert);
    
private voiddisplayWarning(java.lang.String title, java.lang.String message)
Display a warning to the user, with a done command.

param
title warning form's title
param
message warning message

        Alert a = new Alert(title, message, null, AlertType.WARNING);
        a.setTimeout(Alert.FOREVER);
        a.setCommandListener(this);
        display.setCurrent(a);
    
voidexit(boolean status)
Exit the SuiteVerifier with the status supplied. It will perform any remaining cleanup and call notifyDestroyed.

param
status true if the install was a success, false otherwise.

        /* TBD: Handle the status */
        notifyDestroyed();
    
public voidpauseApp()
Pause; there are no resources that need to be released.

    
public voidstartApp()
Start.

    
private voidstoreSuiteHash()
Store hash value of the suite JAR after all classes in the package are successfully verified

        try {
            // Evaluate suite hash value and store it
            byte []verifyHash = MIDletSuiteVerifier.getJarHash(jarPath);
            suiteStorage.storeSuiteVerifyHash(suiteId, verifyHash);
        } catch (IOException ioe) {
            displayWarning(
                Resource.getString(
                ResourceConstants.AMS_CLASS_VERIFIER_WARNING),
                Resource.getString(
                ResourceConstants.AMS_CLASS_VERIFIER_CANT_STORE_HASH));
        }