FileDocCategorySizeDatePackage
ExecuteMIDletEventListener.javaAPI DocphoneME MR2 API (J2ME)6776Wed May 02 18:00:06 BST 2007com.sun.midp.main

ExecuteMIDletEventListener

public class ExecuteMIDletEventListener extends Object implements Runnable, com.sun.midp.events.EventListener
Handles execute MIDlet events.

Fields Summary
private static com.sun.midp.security.SecurityToken
classSecurityToken
An internal security token.
private static com.sun.midp.lcdui.DisplayEventHandler
displayEventHandler
The controller of Displays.
private int
externalAppId
External app ID of an installed suite to execute.
private int
id
ID of an installed suite to execute.
private String
midlet
MIDlet class name of MIDlet to invoke.
private String
displayName
displayName name to display to the user.
private String
arg0
arg0 if not null, is application property arg-0.
private String
arg1
arg1 if not null, is application property arg-1.
private String
arg2
arg2 if not null, is application property arg-2.
Constructors Summary
private ExecuteMIDletEventListener()
Initialize an ExecuteMIDletEventListener to with execute arguments.

    
private ExecuteMIDletEventListener(int externalAppId, int id, String midlet, String displayName, String arg0, String arg1, String arg2)
Initialize an ExecuteMIDletEventListener with arguments to execute.

param
externalAppId ID of MIDlet to invoke, given by an external application manager
param
id ID of an installed suite
param
midlet class name of MIDlet to invoke
param
displayName name to display to the user
param
arg0 if not null, this parameter will be available to the MIDlet as application property arg-0
param
arg1 if not null, this parameter will be available to the MIDlet as application property arg-1
param
arg2 if not null, this parameter will be available to the MIDlet as application property arg-2

        this.externalAppId = externalAppId;
	this.id = id;
	this.midlet = midlet;
	this.displayName = displayName;
	this.arg0 = arg0;
	this.arg1 = arg1;
	this.arg2 = arg2;
    
Methods Summary
public booleanpreprocess(com.sun.midp.events.Event event, com.sun.midp.events.Event waitingEvent)
Preprocess an event that is being posted to the event queue. This implementation of the method always return true.

param
event event being posted
param
waitingEvent previous event of this type waiting in the queue to be processed
return
true to allow the post to continue

        return true;
    
public voidprocess(com.sun.midp.events.Event genericEvent)
Process an Execute event to start a new MIDlet. If the MIDlet is already in the ProxyList it will not start it again. If the MIDlet/Isolate has decided to exit but has not yet sent the remove event the execute will be unreliable.

param
genericEvent event to process

	// Verify that the requested MIDlet is not already running
	// (is not in the MIDletProxyList)
	if (MIDletProxyList.getMIDletProxyList().isMidletInList(id, midlet)) {
            if (Logging.REPORT_LEVEL <= Logging.WARNING) {
                Logging.report(Logging.WARNING, LogChannels.LC_CORE,
                               "MIDlet already running; execute ignored");
            }
	    return;
	}

        try {
            // The execute MIDlet method may block
	    NativeEvent event = (NativeEvent)genericEvent;
	    ExecuteMIDletEventListener runnable =
		new ExecuteMIDletEventListener(event.intParam1,
					       event.intParam2,
					       event.stringParam1,
					       event.stringParam2,
					       event.stringParam3,
					       event.stringParam4,
					       event.stringParam5);
            (new Thread(runnable)).start();
	} catch (Throwable t) {
            Logging.trace(t, "Error creating a new Execute thread");
        }
    
public voidrun()
Processes an execute MIDlet event outside of the event thread.

        try {
            MIDletSuiteUtils.executeWithArgs(classSecurityToken,
                externalAppId, id, midlet, displayName, arg0, arg1, arg2);
        } catch (Throwable t) {
            if (Logging.TRACE_ENABLED) {
                Logging.trace(t,
                    "Exception calling MIDletSuiteLoader.execute");
            }

            MIDletSuiteUtils.displayException(displayEventHandler,
                 Resource.getString(
                 ResourceConstants.AMS_MIDLETSUITELDR_CANT_EXE_NEXT_MIDLET) +
                             "\n\n" + t.getMessage());
        }
    
static voidstartListening(com.sun.midp.security.SecurityToken token, com.sun.midp.lcdui.DisplayEventHandler theDisplayEventHandler, com.sun.midp.events.EventQueue eventQueue)
Start listening for execute MIDlet events.

param
token security token for initilaization
param
theDisplayEventHandler display event handler
param
eventQueue event queue to work with

        classSecurityToken = token;
        displayEventHandler = theDisplayEventHandler;
        eventQueue.registerEventListener(EventTypes.EXECUTE_MIDLET_EVENT,
                                  new ExecuteMIDletEventListener());