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

AbstractMIDletSuiteLoader

public abstract class AbstractMIDletSuiteLoader extends Object implements MIDletSuiteExceptionListener
The class presents abstract MIDlet suite loader with routines to prepare runtime environment for a suite execution. The class provides generic scenario to load, start and terminate a MIDlet suite in the common way for both SVM and MVM modes. All the differences of SVM & MVM modes are designed as virtual or abstract methods.

Fields Summary
protected int
isolateId
The ID of the MIDlte suite task Isolate
protected int
amsIsolateId
The ID of the AMS task Isolate
protected int
suiteId
Suite ID of the MIDlet suite
protected int
externalAppId
External application ID that can be provided by native AMS
protected String
midletClassName
Name of the class to start MIDlet suite execution
protected String
midletDisplayName
Display name of a MIDlet suite
protected String[]
args
The arguments to start MIDlet suite with
protected static SecurityToken
internalSecurityToken
This class has a different security domain than the MIDlet suite
protected com.sun.midp.events.EventQueue
eventQueue
Event queue instance created for this MIDlet suite execution
protected MIDletSuite
midletSuite
MIDlet suite instance created and properly initialized for a MIDlet suite invocation.
protected ForegroundController
foregroundController
Foreground Controller adapter.
protected DisplayEventProducer
displayEventProducer
Event producer for various screen change events.
protected DisplayEventListener
displayEventListener
Provides interface for display preemption, creation and other functionality that can not be publicly added to a javax package.
protected RepaintEventProducer
repaintEventProducer
Event producer for all repaint events.
protected DisplayContainer
displayContainer
Stores array of active displays for a MIDlet suite isolate.
protected DisplayEventHandler
displayEventHandler
Provides interface for display preemption, creation and other functionality that can not be publicly added to a javax package.
protected ItemEventConsumer
itemEventConsumer
Handles item events not associated directly with particular Display.
protected MIDletStateHandler
midletStateHandler
Starts and controls MIDlets through the lifecycle states.
protected LCDUIEventListener
lcduiEventListener
The event listener for LCDUI events.
Constructors Summary
Methods Summary
protected booleanallocateReservedResources()
Allocates resources for a suite execution according to global resource policy.

return
true in the case resources were successfully allocated, false otherwise

        return true;
    
protected voidcheckForShutdown()
Checks whether an executed MIDlet suite has requested for a system shutdown. User MIDlets most probably have no right for it, however Java AMS MIDlet could do it.

        // IMPL_NOTE: No checks for shutdown by default
    
protected voidcloseSuite()
Closes suite and unlock native suite locks

        if (midletSuite != null) {
            /* When possible, don't wait for the finalizer
             * to unlock the suite. */
            midletSuite.close();
        }
    
protected abstract MIDletSuitecreateMIDletSuite()
Creates MIDlet suite instance by suite ID, the

return
MIDlet suite to load
throws
Exception in the case MIDlet suite can not be created because of a security reasons or some problems related to suite storage

protected voidcreateSuiteEnvironment()
Creates all needed objects of a MIDlet suite environment, but only initialization that is done, will be to pass other created objects, and the current and AMS isolate IDs. It is mostly event-related objects, however subclasses can extend the environment with more specific parts

        displayEventHandler =
            DisplayEventHandlerFactory.getDisplayEventHandler(
               internalSecurityToken);

        displayEventProducer =
            new DisplayEventProducer(
                eventQueue);

        repaintEventProducer =
            new RepaintEventProducer(
                eventQueue);

        displayContainer = new DisplayContainer(
            internalSecurityToken, isolateId);

        /*
         * 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,
            foregroundController,
            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);
    
protected voiddone()
Final actions to finish a MIDlet suite loader

        eventQueue.shutdown();
    
protected abstract voidexitLoader()
Explicitly requests suite loader exit after MIDlet suite execution is finished and created environment is done.

public abstract voidhandleException(java.lang.Throwable t)
Handles exception occurred during MIDlet suite execution.

param
t exception instance

protected voidinit()
Core initialization of a MIDlet suite loader

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

        eventQueue = EventQueue.getEventQueue(
            internalSecurityToken);
    
protected voidinitSuiteEnvironment()
Does all initialization for already created objects of a MIDlet suite environment. Subclasses can also extend the initialization with various global system initializations needed for all suites. The MIDlet suite has been created at this point, so it can be used to initialize any per suite data.

        displayEventHandler.initSuiteData(
            midletSuite.isTrusted());
    
protected abstract voidreportError(int errorCode, java.lang.String details)
Reports an error detected during MIDlet suite invocation.

param
errorCode the error code to report

protected voidreportError(int errorCode)
Reports an error detected during MIDlet suite invocation.

param
errorCode the error code to report


                        
          
    
                        
        
        reportError(errorCode, null);
    
protected voidrestrictAPIAccess()
Restricts suite access to internal API

        // IMPL_NOTE: No restrictions by default
    
protected voidrunMIDletSuite()
Inits MIDlet suite runtime environment and start a MIDlet suite with it

        // WARNING: Don't add any calls before this!
        //
        // The core init of a MIDlet suite task should be able
        // to perform the very first initializations of the environment
        init();

        try {
            /*
             * Prepare MIDlet suite environment, classes that only need
             * the isolate ID can be create here.
             */
            createSuiteEnvironment();

            /* Check to see that all of the core object are created. */
            if (foregroundController == null ||
                displayEventProducer == null ||
                repaintEventProducer == null ||
                displayContainer == null ||
                displayEventHandler == null ||
                itemEventConsumer == null ||
                lcduiEventListener == null ||
                midletStateHandler == null) {

                throw new
                    RuntimeException("Suite environment not complete.");
            }

            // Regard resource policy for the suite task
            if (!allocateReservedResources()) {
                reportError(Constants.MIDLET_RESOURCE_LIMIT);
                return;
            }

            // Create suite instance ready for start
            midletSuite = createMIDletSuite();

            if (midletSuite == null) {
                reportError(Constants.MIDLET_SUITE_NOT_FOUND);
                return;
            }

            if (!midletSuite.isEnabled()) {
                reportError(Constants.MIDLET_SUITE_DISABLED);
                return;
            }

            /*
             * Now that we have the suite and reserved its resources
             * we can initialize any classes that need MIDlet Suite
             * information.
             */
            initSuiteEnvironment();

            // Export suite arguments as properties, so well
            // set any other properties to control a suite
            setSuiteProperties();

            // Restrict suite access to internal API
            restrictAPIAccess();

            if (Logging.REPORT_LEVEL <= Logging.WARNING) {
                Logging.report(Logging.WARNING, LogChannels.LC_CORE,
                    "MIDlet suite task starting a suite");
            }

            // Blocking call to start MIDlet suite
            // in the prepared environment
            startSuite();

            // Check for shutdown possibly requested from the suite
            checkForShutdown();

            if (Logging.REPORT_LEVEL <= Logging.WARNING) {
                Logging.report(Logging.INFORMATION, LogChannels.LC_CORE,
                    "MIDlet suite loader exiting");
            }

        } catch (Throwable t) {
           handleException(t);

        } finally {
            closeSuite();
            done();
            exitLoader();
        }
    
protected voidsetSuiteProperties()
Sets MIDlet suite arguments as temporary suite properties. Subclasses can override the method to export any other needed suite properties.

        if (args != null) {
            for (int i = 0; i < args.length; i++) {
                if (args[i] != null) {
                    midletSuite.setTempProperty(
                        internalSecurityToken,
                        "arg-" + i, args[i]);
                }
            }
        }
    
protected voidstartSuite()
Start MIDlet suite in the prepared environment

throws
Exception can be thrown during execution

        midletStateHandler.startSuite(
            this, midletSuite, externalAppId, midletClassName);