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

CldcMIDletSuiteLoader

public abstract class CldcMIDletSuiteLoader extends AbstractMIDletSuiteLoader
The class presents abstract MIDlet suite loader with routines to prepare runtime environment for CLDC a suite execution.

Fields Summary
protected MIDletControllerEventProducer
midletControllerEventProducer
Event producer to send MIDlet state events to the AMS isolate.
protected MIDletEventListener
midletEventListener
Listener for MIDlet related events (state changes, etc).
protected ForegroundEventListener
foregroundEventListener
Provides interface for display foreground notification, functionality that can not be publicly added to a javax package.
Constructors Summary
Methods Summary
protected voidcloseSuite()

        super.closeSuite();

        // shutdown any preempting
        if (displayEventHandler != null) {
            displayEventHandler.donePreempting(null);
        }
    
protected MIDletSuitecreateMIDletSuite()
Creates MIDlet suite instance by suite ID

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

        MIDletSuiteStorage storage;
        MIDletSuite suite = null;

        if (suiteId == MIDletSuite.INTERNAL_SUITE_ID) {
            // assume a class name of a MIDlet in the classpath
            suite = InternalMIDletSuiteImpl.create(midletDisplayName, suiteId);
        } else {
            storage = MIDletSuiteStorage.
                getMIDletSuiteStorage(internalSecurityToken);

            suite = storage.getMIDletSuite(suiteId, false);
            Logging.initLogSettings(suiteId);
        }

        return suite;
    
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

        midletControllerEventProducer =
            new MIDletControllerEventProducer(
                eventQueue,
                amsIsolateId,
                isolateId);

        foregroundController = new CldcForegroundController(
            midletControllerEventProducer);

        // creates display container, needs foregroundController
        super.createSuiteEnvironment();

        foregroundEventListener = new ForegroundEventListener(
            eventQueue,
            displayContainer);

        midletStateHandler =
            MIDletStateHandler.getMidletStateHandler();

        MIDletStateListener midletStateListener =
            new CldcMIDletStateListener(internalSecurityToken,
                                        displayContainer,
                                        midletControllerEventProducer);

        midletStateHandler.initMIDletStateHandler(
            internalSecurityToken,
            midletStateListener,
            new CldcMIDletLoader(internalSecurityToken),
            new CldcPlatformRequest(internalSecurityToken));

        midletEventListener = new MIDletEventListener(
            internalSecurityToken,
            midletStateHandler,
            eventQueue);
    
protected static intgetErrorCode(java.lang.Throwable t)
Gets error code by exception type

param
t exception instance
return
error code

        if (t instanceof ClassNotFoundException) {
            return Constants.MIDLET_CLASS_NOT_FOUND;
        } else if (t instanceof InstantiationException) {
            return Constants.MIDLET_INSTANTIATION_EXCEPTION;
        } else if (t instanceof IllegalAccessException) {
            return Constants.MIDLET_ILLEGAL_ACCESS_EXCEPTION;
        } else if (t instanceof OutOfMemoryError) {
            return Constants.MIDLET_OUT_OF_MEM_ERROR;
        } else if (t instanceof MIDletSuiteLockedException) {
            return Constants.MIDLET_INSTALLER_RUNNING;
        } else {
            return Constants.MIDLET_CONSTRUCTOR_FAILED;
        }
    
protected static intgetErrorMessageId(int errorCode)
Gets AMS error message ID by generic error code

param
errorCode generic error code
return
AMS error ID

        switch (errorCode) {
            case Constants.MIDLET_SUITE_DISABLED:
                return ResourceConstants.
                    AMS_MIDLETSUITELDR_MIDLETSUITE_DISABLED;
            case Constants.MIDLET_SUITE_NOT_FOUND:
                return ResourceConstants.
                    AMS_MIDLETSUITELDR_MIDLETSUITE_NOTFOUND;
            case Constants.MIDLET_CLASS_NOT_FOUND:
                return ResourceConstants.
                    AMS_MIDLETSUITELDR_CANT_LAUNCH_MISSING_CLASS;
            case Constants.MIDLET_INSTANTIATION_EXCEPTION:
                return ResourceConstants.
                    AMS_MIDLETSUITELDR_CANT_LAUNCH_ILL_OPERATION;
            case Constants.MIDLET_ILLEGAL_ACCESS_EXCEPTION:
                return ResourceConstants.
                    AMS_MIDLETSUITELDR_CANT_LAUNCH_ILL_OPERATION;
            case Constants.MIDLET_OUT_OF_MEM_ERROR:
                return ResourceConstants.
                    AMS_MIDLETSUITELDR_QUIT_OUT_OF_MEMORY;
            default:
                return ResourceConstants.
                    AMS_MIDLETSUITELDR_UNEXPECTEDLY_QUIT;
        }
    
public voidhandleException(java.lang.Throwable t)
Handles exception occurred during MIDlet suite execution.

param
t exception instance

        t.printStackTrace();
        int errorCode = getErrorCode(t);

        reportError(errorCode, t.getMessage());
    
protected voidinit()
Core initialization of a MIDlet suite loader

        isolateId = MIDletSuiteUtils.getIsolateId();
        amsIsolateId = MIDletSuiteUtils.getAmsIsolateId();

        // Hint VM of startup beginning: system init phase
        MIDletSuiteUtils.vmBeginStartUp(isolateId);

        super.init();
    
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.

        super.initSuiteEnvironment();
    
protected voidstartSuite()
Starts MIDlet suite in the prepared environment Overrides super method to hint VM of system startup phase is ended

throws
Exception can be thrown during execution

        // Hint VM of startup finish: system init phase 
        MIDletSuiteUtils.vmEndStartUp(isolateId);
        super.startSuite();