FileDocCategorySizeDatePackage
AutoMIDletImpl.javaAPI DocphoneME MR2 API (J2ME)9078Wed May 02 18:00:08 BST 2007com.sun.midp.automation

AutoMIDletImpl

public final class AutoMIDletImpl extends Object implements AutoMIDlet
AutoMIDlet interface implementation

Fields Summary
private AutoMIDletDescriptorImpl
midletDescriptor
MIDlet descriptor for this MIDlet
private AutoStateTracker
lifeCycleStateTracker
For tracking life cycle states
private AutoStateTracker
foregroundStateTracker
For tracking background/foreground states
private static AutoMIDletStateController
midletStateController
For switching MIDlet state
private static AutoForegroundStateController
foregroundStateController
For switching MIDlet state
Constructors Summary
AutoMIDletImpl(AutoMIDletDescriptorImpl midletDescriptor)
Constructor.

param
midletDescriptor MIDlet descriptor for this MIDlet

   

                 
      
        this.midletDescriptor = midletDescriptor;
        this.lifeCycleStateTracker = 
            new AutoStateTracker(AutoMIDletLifeCycleState.PAUSED);

        this.foregroundStateTracker = 
            new AutoStateTracker(AutoMIDletForegroundState.BACKGROUND);

        if (midletStateController == null) {
            midletStateController = 
                AutoMIDletStateController.getMIDletStateController();
        }

        if (foregroundStateController == null) {
            foregroundStateController = 
                AutoForegroundStateController.getForegroundStateController();
        }
    
Methods Summary
public AutoEventQueuegetEventQueue()
Get MIDlet's event queue.

return
AutoEventQueue representing event queue.

        return null;
    
public AutoMIDletForegroundStategetForegroundState()
Get current foreground state.

return
AutoForegroundState representing current foreground state

        synchronized (foregroundStateTracker) {
            Object state = foregroundStateTracker.getCurrentState();
            return (AutoMIDletForegroundState)state; 
        }
    
public AutoMIDletLifeCycleStategetLifeCycleState()
Get current lifecycle state.

return
AutoLifeCycleState representing current lifecycle state

        synchronized (lifeCycleStateTracker) {
            Object state = lifeCycleStateTracker.getCurrentState();
            return (AutoMIDletLifeCycleState)state; 
        }
    
public AutoMIDletDescriptorgetMIDletDescriptor()
Get MIDlet's descriptor.

return
AutoMIDletDescriptor representing descriptor.

        return midletDescriptor;
    
private voidguaranteeMIDletNotDestroyed(java.lang.String s)
Guarantees that MIDlet is not destroyed: if MIDlet is destroyed, exception is thrown.

param
s error string

            
        if (lifeCycleStateTracker.getCurrentState() == 
                AutoMIDletLifeCycleState.DESTROYED) {
            throw new IllegalStateException(s);
        }
    
private voidguaranteeStateTransitionIsValid(AutoMIDletLifeCycleState state, java.lang.String s)
Guarantees that state transition is valid (possible): if state is unreachable, exception is thrown.

param
state state to check for
param
s error string


        if (state != AutoMIDletLifeCycleState.DESTROYED) {
            guaranteeMIDletNotDestroyed(s);
        }
    
private voidguaranteeStateTransitionIsValid(AutoMIDletForegroundState state, java.lang.String s)
Guarantees that waiting for state is valid: if state is unreachable, exception is thrown.

param
state state to check for
param
s error string


        guaranteeMIDletNotDestroyed(s);
    
voidstateChanged(AutoMIDletLifeCycleState newState)
To be called when MIDlet's life cycle state has changed.

param
newState new life cycle state

        boolean interruptWaiters = false;
        if (newState == AutoMIDletLifeCycleState.DESTROYED) {
            interruptWaiters = true;
        }

        lifeCycleStateTracker.setCurrentState(newState, interruptWaiters);
        
        if (newState == AutoMIDletLifeCycleState.DESTROYED) {
            foregroundStateTracker.interruptWait();
            midletDescriptor.midletDestroyed();
        }
    
voidstateChanged(AutoMIDletForegroundState newState)
To be called when MIDlet's foreground state has changed.

param
newState new forgeround state

        foregroundStateTracker.setCurrentState(newState, false);
    
public voidswitchTo(AutoMIDletLifeCycleState state, boolean wait)
Initiate a switch (transition) from current to specified lifecycle state.

param
state state to switch to
param
wait if true, wait (block) until transition to the specified state has been completed
throws
IllegalStateException thrown when switching to specified state is invalid

            
        synchronized (lifeCycleStateTracker) {
            guaranteeStateTransitionIsValid(state, "switchTo");

            midletStateController.switchTo(this, state);
            if (wait) {
                waitFor(state);
            }
        }        
    
public voidswitchTo(AutoMIDletForegroundState state, boolean wait)
Initiate a switch (transition) from current to specified foreground state.

param
state state to switch to
param
wait if true, wait (block) until transition to the specified state has been completed
throws
IllegalStateException thrown when switching to specified state is invalid


        synchronized (foregroundStateTracker) {
            guaranteeStateTransitionIsValid(state, "switchTo");

            foregroundStateController.switchTo(this, state);
            if (wait) {
                waitFor(state);
            }
        }
    
public voidwaitFor(AutoMIDletForegroundState state)
Wait (block) until MIDlet reaches specified foreground state.

param
state state to wait for
throws
IlegalStateException thrown if state to wait for is invalid, or if during waiting MIDlet has reached the state where waiting for specified state is no longer valid

            
        synchronized (foregroundStateTracker) {
            guaranteeStateTransitionIsValid(state, "waitFor");
            
            foregroundStateTracker.waitFor(state);
            
            // wait might have been interrupted, so check again
            // if waiting for this state is still valid
            guaranteeStateTransitionIsValid(state, "waitFor");
        }
    
public voidwaitFor(AutoMIDletLifeCycleState state)
Wait (block) until MIDlet reaches specified lifecycle state.

param
state state to wait for
throws
IlegalStateException thrown if state to wait for is invalid, or if during waiting MIDlet has reached the state where waiting for specified state is no longer valid

        
        synchronized (lifeCycleStateTracker) {
            guaranteeStateTransitionIsValid(state, "waitFor");
            
            // wait
            lifeCycleStateTracker.waitFor(state);
            
            // wait might have been interrupted, so check again
            // if waiting for this state is still valid
            guaranteeStateTransitionIsValid(state, "waitFor");
        }