FileDocCategorySizeDatePackage
MIDletContainer.javaAPI DocphoneME MR2 API (J2ME)16910Wed May 02 18:00:04 BST 2007com.sun.midp.jump.isolate

MIDletContainer

public class MIDletContainer extends com.sun.jump.isolate.jvmprocess.JUMPAppContainer implements MIDletSuiteExceptionListener, MIDletStateListener, PlatformRequest, ForegroundController, Runnable
Application Container for the MIDlet app model.

The container uses the system property sun.midp.home.path as the directory of the MIDP native library and application database.

The container uses the system property sun.midp.library.name as the name of the MIDP native library.

Fields Summary
private SecurityToken
internalSecurityToken
This class has a different security domain than the MIDlet suite
private boolean
appStarted
True, if an app has been started.
private DisplayEventHandler
displayEventHandler
Provides interface for display preemption, creation and other functionality that can not be publicly added to a javax package.
private DisplayContainer
displayContainer
Stores array of active displays for a MIDlet suite isolate.
private MIDletSuiteStorage
suiteStorage
Reference to the suite storage.
private MIDletStateHandler
midletStateHandler
Starts and controls MIDlets through the lifecycle states.
private MIDletSuite
midletSuite
MIDlet suite instance created and properly initialized for a MIDlet suite invocation.
private String
midletClassName
Name of the class to start MIDlet suite execution
private int
currentDisplayId
Holds the ID of the current display, for preempting purposes.
Constructors Summary
public MIDletContainer()
Core initialization of a MIDP environment.

        EventQueue eventQueue;
        DisplayEventProducer displayEventProducer;
        RepaintEventProducer repaintEventProducer;
        DisplayEventListener displayEventListener;
        ItemEventConsumer itemEventConsumer;
        LCDUIEventListener lcduiEventListener;

        CDCInit.init();

        internalSecurityToken =
            SecurityInitializer.requestToken(new SecurityTrusted());

        // Init security tokens for core subsystems
        SecurityInitializer.initSystem();

        eventQueue = EventQueue.getEventQueue(
            internalSecurityToken);

        displayEventHandler =
            DisplayEventHandlerFactory.getDisplayEventHandler(
               internalSecurityToken);

        displayEventProducer =
            new DisplayEventProducer(
                eventQueue);

        repaintEventProducer =
            new RepaintEventProducer(
                eventQueue);

        displayContainer = new DisplayContainer(
            internalSecurityToken, 0);

        /*
         * Because the display handler is implemented in a javax
         * package it cannot created outside of the package, so
         * we have to get it after the static initializer of display the class
         * has been run and then hook up its objects.
         */
        displayEventHandler.initDisplayEventHandler(
            displayEventProducer,
            this,
            repaintEventProducer,
            displayContainer);

        displayEventListener = new DisplayEventListener(
            eventQueue,
            displayContainer);

        /* Bad style of type casting, but DisplayEventHandlerImpl
         * implements both DisplayEventHandler & ItemEventConsumer IFs */
        itemEventConsumer =
            (ItemEventConsumer)displayEventHandler;

        lcduiEventListener = new LCDUIEventListener(
            internalSecurityToken,
            eventQueue,
            itemEventConsumer);

        suiteStorage =
            MIDletSuiteStorage.getMIDletSuiteStorage(internalSecurityToken);

        midletStateHandler =
            MIDletStateHandler.getMidletStateHandler();

        midletStateHandler.initMIDletStateHandler(
            internalSecurityToken,
            this,
            new CdcMIDletLoader(suiteStorage),
            this);
    
Methods Summary
public voiddestroyApp(int appId, boolean force)
Call a MIDlet's destroyApp method. This method will not return until after the the MIDlet's startApp method has returned.

If force = false and the app did not get destroyed, then a RuntimeException must be thrown.

param
appId the application ID returned from startApp
param
force if false, give the app the option of not being destroyed

        // IMPL_NOTE: force=false is not supported.
        try {
            MIDletEventConsumer mec =
                midletStateHandler.getMIDletEventConsumer(
                    internalSecurityToken, midletClassName);

            if (mec == null) {
                return;
            }

            // IMPL_NOTE: This asynchronous call should be synchronous.
            mec.handleMIDletDestroyEvent();

        } catch (Exception e) {
            e.printStackTrace();
        }
    
public booleandispatch(java.lang.String URL)

        throw new ConnectionNotFoundException("not implemented");
    
public voidhandleException(java.lang.Throwable t)
Handles exception occurred during MIDlet suite execution.

param
t exception instance

        t.printStackTrace();
    
public voidmidletActivated(MIDletSuite suite, javax.microedition.midlet.MIDlet midlet)
Called after a MIDlet is successfully activated. This is after the startApp method is called. This implementation does nothing.

param
suite reference to the loaded suite
param
midlet reference to the MIDlet

    
public voidmidletCreated(MIDletSuite suite, java.lang.String className, int externalAppId)
Called after a MIDlet is successfully created. This implementation does nothing.

param
suite reference to the loaded suite
param
className Class name of the MIDlet
param
externalAppId ID of given by an external application manager

    
public voidmidletDestroyed(MIDletSuite suite, java.lang.String className)
Called after a MIDlet is successfully destroyed. This implementation does nothing.

param
suite reference to the loaded suite
param
className class name of the MIDlet

        // IMPL_NOTE: The JUMPApplication API does not support this.
    
public voidmidletPaused(MIDletSuite suite, java.lang.String className)
Called after a MIDlet is successfully paused. This implementation does nothing.

param
suite reference to the loaded suite
param
className class name of the MIDlet

    
public voidmidletPausedItself(MIDletSuite suite, java.lang.String className)
Called after a MIDlet pauses itself. In this case pauseApp has not been called.

param
suite reference to the loaded suite
param
className class name of the MIDlet

        // IMPL_NOTE: The JUMPApplication API does not support this.
    
public voidmidletPreStart(MIDletSuite suite, java.lang.String className)
Called before a MIDlet is created. This implementation does nothing.

param
suite reference to the loaded suite
param
className class name of the MIDlet to be created

    
public voidpauseApp(int appId)
Call a MIDlet's pauseApp method. This method will not return until after the the MIDlet's pauseApp method has returned.

param
the application ID returned from startApp

        try {
            MIDletEventConsumer mec =
                midletStateHandler.getMIDletEventConsumer(
                    internalSecurityToken, midletClassName);

            if (mec == null) {
                return;
            }

            // IMPL_NOTE: This asynchronous call should be synchronous.
            mec.handleMIDletPauseEvent();
        } catch (Exception e) {
            e.printStackTrace();
        }
    
public voidpreActivated(MIDletSuite suite, java.lang.String className)
Called before a MIDlet is activated. This implementation does nothing.

param
suite reference to the loaded suite
param
className class name of the MIDlet

    
public javax.microedition.lcdui.DisplayableregisterDisplay(int displayId, java.lang.String ownerClassName)
Called to register a newly create Display. Must method must be called before the other methods can be called. This implementation does nothing.

param
displayId ID of the Display
param
ownerClassName Class name of the that owns the display
return
a place holder displayable to used when "getCurrent()==null", if null is returned an empty form is used

        currentDisplayId = displayId;
        return null;
    
public voidrequestBackground(int displayId)
Called to request the background. This implementation does nothing.

param
displayId ID of the Display

        ForegroundEventConsumer fc =
            displayContainer.findForegroundEventConsumer(displayId);

        if (fc == null) {
            return;
        }

        fc.handleDisplayBackgroundNotifyEvent();
    
public voidrequestForeground(int displayId, boolean isAlert)
Called to request the foreground. This implementation does nothing.

param
displayId ID of the Display
param
isAlert true if the current displayable is an Alert

        ForegroundEventConsumer fc =
            displayContainer.findForegroundEventConsumer(displayId);

        if (fc == null) {
            return;
        }

        setForegroundInNativeState(displayId);

        fc.handleDisplayForegroundNotifyEvent();
    
public voidresumeApp(int appId)
Call a MIDlet's startApp method. This method will not return until after the the MIDlet's startApp method has returned.

param
the application ID returned from startApp

        try {
            MIDletEventConsumer mec =
                midletStateHandler.getMIDletEventConsumer(
                    internalSecurityToken, midletClassName);

            if (mec == null) {
                return;
            }

            // IMPL_NOTE: This asynchronous call should be synchronous.
            mec.handleMIDletActivateEvent();

        } catch (Exception e) {
            e.printStackTrace();
        }
    
public voidresumeRequest(MIDletSuite suite, java.lang.String className)
Called when a MIDlet calls MIDlet resume request.

param
suite reference to the loaded suite
param
className class name of the MIDlet

        MIDletEventConsumer mec =
            midletStateHandler.getMIDletEventConsumer(internalSecurityToken,
                                                      className);
        // IMPL_NOTE: The JUMPApplication API does not support this.
        if (mec == null) {
            return;
        }

        mec.handleMIDletActivateEvent();
    
public voidrun()
Run the MIDletStateHandler.

        try {
            midletStateHandler.startSuite(this, midletSuite, 0,
                                          midletClassName);
            midletSuite.close();
        } catch (Throwable t) {
            t.printStackTrace();
        } finally {
            System.exit(0);
        }
    
private native voidsetForegroundInNativeState(int displayId)
Set foreground display native state, so the native code will know which display can draw. This method will not be needed when JUMP uses GCI.

param
displayId Display ID

public synchronized intstartApp(com.sun.jump.common.JUMPApplication app, java.lang.String[] args)
Create a MIDlet and call its startApp method. This method will not return until after the the MIDlet's startApp method has returned.

param
app application properties
param
args arguments for the app
return
runtime application ID or -1 for failure

        try {
            int suiteId;

            if (appStarted) {
                throw new
                    IllegalStateException("Attempt to start a second app");
            }

            appStarted = true;

            suiteId = MIDletApplication.getMIDletSuiteID(app);

            midletSuite = suiteStorage.getMIDletSuite(suiteId, false);

            if (midletSuite == null) {
                throw new IllegalArgumentException("Suite not found");
            }

            Logging.initLogSettings(suiteId);

            if (!midletSuite.isEnabled()) {
                throw new IllegalStateException("Suite is disabled");
            }

            displayEventHandler.initSuiteData(midletSuite.isTrusted());

            // set a each arg as property numbered from 0, first arg: "arg-0"
            if (args != null) {
                for (int i = 0; i < args.length; i++) {
                    if (args[i] != null) {
                        midletSuite.setTempProperty(internalSecurityToken,
                                                    "arg-" + i, args[i]);
                    }
                }
            }

            midletClassName = MIDletApplication.getMIDletClassName(app);

            // IMPL_NOTE: This asynchronous call should be synchronous.
            new Thread(this).start();
        } catch (Exception e) {
            e.printStackTrace();
            return -1;
        }

        //DEBUG:System.err.println("**started");
        return 1; // only one app can run in this container at a time
    
public voidstartPreempting(int displayId)
Called to start preempting. The given display will preempt all other displays for this isolate.

param
displayId ID of the Display

        requestBackground(currentDisplayId);
        requestForeground(displayId, true);
    
public voidstopPreempting(int displayId)
Called to end preempting.

param
displayId ID of the Display

        requestBackground(displayId);
        requestForeground(currentDisplayId, false);