FileDocCategorySizeDatePackage
DevMIDletSuiteImpl.javaAPI DocJ2ME MIDP 2.013239Thu Nov 07 12:02:24 GMT 2002com.sun.midp.dev

DevMIDletSuiteImpl

public class DevMIDletSuiteImpl extends com.sun.midp.midletsuite.MIDletSuiteImpl
Implements a the required MIDletSuite functionality needed by the Scheduler. The class is only need for development environments.

Fields Summary
private com.sun.midp.midletsuite.JadProperties
bufferedJadProps
Buffered properties from the application descriptor
private String
initialMIDletClassName
Initial midlet class name.
private String
storageRoot
Storage path for this MIDlet suite
private byte[]
permissions
Permissions for this suite.
private int
numberOfMidlets
number of midlets in this suite. less than 0 mean they need to counted
private String
pushInterruptQuestion
Push interrupt question for this suite.
private String
alarmInterruptQuestion
Alarm interrupt question for this suite.
Constructors Summary
private DevMIDletSuiteImpl(com.sun.midp.security.SecurityToken callerSecurityToken, byte[] permissions, int pushSetting, boolean trusted, String storageName)
Creates MIDletSuiteImpl from a raw JAD.

param
callerSecurityToken security token of the caller
param
permissions security permissions of the suite
param
pushSetting can this MIDlet suite interrupt other suites
param
trusted true if the suite is to considered trusted (not to be confused with a domain named "trusted", this only shown to the user and not used for permissions)
param
storageName name to separate this suite's storage from others

        super(callerSecurityToken, permissions, pushSetting, trusted,
              storageName);
    
Methods Summary
public voidaddProperty(java.lang.String key, java.lang.String value)
Add a property to the suite.

param
key the name of the property
param
value the value of the property
exception
SecurityException if the calling suite does not have internal API permission

        MIDletSuite current = Scheduler.getScheduler().getMIDletSuite();

        if (current != null) {
            current.checkIfPermissionAllowed(Permissions.MIDP);
        }

        bufferedJadProps.addProperty(key, value);
    
public voidcheckForPermission(int permission, java.lang.String resource)
Check for permission and throw an exception if not allowed. May block to ask the user a question.

param
permission ID of the permission to check for, the ID must be from {@link com.sun.midp.security.Permissions}
param
resource string to insert into the question, can be null
exception
SecurityException if the permission is not allowed by this token
exception
InterruptedException if another thread interrupts the calling thread while this method is waiting to preempt the display.

        String app;

        app = getProperty(Installer.SUITE_NAME_PROP);
        if (app == null) {
            app = initialMIDletClassName;
        }

        super.checkForPermission(permission, app, resource);
    
public static com.sun.midp.midlet.MIDletSuitecreate(com.sun.midp.security.SecurityToken callerSecurityToken, java.lang.String jadFilename, java.lang.String midletClassName, java.lang.String storageName, java.lang.String domain)
Creates MIDletSuite from a raw JAD.

param
callerSecurityToken security token of the caller
param
jadFilename filename of the descriptor for the suite
param
midletClassName class name of the MIDlet to run when this suite is scheduled
param
storageName name to separate this suite's storage from others
param
domain name of the security domain this suite is to run under, null for untrusted
return
new MIDletSuite object
exception
IOException is thrown if any error prevents the installation of the MIDlet suite
exception
InvalidJadException if the downloaded application descriptor is invalid


                                                                                                                                           
        
                                 
                                 
               
        return create(callerSecurityToken, jadFilename, midletClassName,
            storageName, null, null, domain, !(domain == null ||
            domain.equals(Permissions.UNTRUSTED_DOMAIN_NAME)),
            null, null);
    
public static com.sun.midp.midlet.MIDletSuitecreate(com.sun.midp.security.SecurityToken callerSecurityToken, java.lang.String jadFilename, java.lang.String midletClassName, java.lang.String storageName, java.lang.String[] keys, java.lang.String[] values, java.lang.String domain, boolean trusted, java.lang.String pushQuestion, java.lang.String alarmQuestion)
Creates MIDletSuite from a raw JAD.

param
callerSecurityToken security token of the caller
param
jadFilename filename of the descriptor for the suite
param
midletClassName class name of the MIDlet to run when this suite is scheduled
param
storageName name to separate this suite's storage from others
param
keys list of keys to MIDlet suite properties
param
values list of values for the keys to MIDlet suite properties
param
domain name of the security domain this suite is to run under, null for untrusted
param
trusted true if the suite is to considered trusted (not to be confused with a domain named "trusted", this used to determine if a trusted symbol should be displayed to the user and not used for permissions)
param
pushQuestion question to ask when a push interruption happens, can be null to use default
param
alarmQuestion question to ask when an alarm interruption happens, can be null to use default
return
new MIDletSuite object
exception
IOException is thrown if any error prevents the installation of the MIDlet suite
exception
InvalidJadException if the downloaded application descriptor is invalid

        DevMIDletSuiteImpl suite;
        RandomAccessStream storage;
        InputStream jadStream;
        byte[][] temp;
        int pushSetting;

        if (domain == null) {
            domain = Permissions.UNTRUSTED_DOMAIN_NAME;
        }

        temp = Permissions.forDomain(callerSecurityToken, domain);

        if (temp[Permissions.CUR_LEVELS][Permissions.PUSH] ==
                Permissions.NEVER) {
            pushSetting = Permissions.NEVER;
        } else if (temp[Permissions.CUR_LEVELS][Permissions.PUSH] ==
                   Permissions.ALLOW) {
            pushSetting = Permissions.BLANKET;
        } else {
            pushSetting = temp[Permissions.CUR_LEVELS][Permissions.PUSH];
        }

        suite = new DevMIDletSuiteImpl(callerSecurityToken, temp, pushSetting,
                                       trusted, storageName);

        if (jadFilename != null) {
            storage = new RandomAccessStream(callerSecurityToken);
            storage.connect(jadFilename, Connector.READ);
            try {
                jadStream = storage.openInputStream();
                suite.bufferedJadProps.load(jadStream);
            } finally {
                storage.disconnect();
            }

            suite.numberOfMidlets = suite.countMIDlets();
        } else {
            // without a jad we must assume at least one MIDlet
            suite.numberOfMidlets = 1;
        }

        if (keys != null) {
            for (int i = 0; i < keys.length; i++) {
                suite.bufferedJadProps.setProperty(keys[i], values[i]);
            }
        }

        suite.storageRoot = File.getStorageRoot() + storageName;

        suite.initialMIDletClassName = midletClassName;

        if (pushQuestion != null) {
            suite.pushInterruptQuestion = pushQuestion;
        } else {
            suite.pushInterruptQuestion = PUSH_INTERRUPT_QUESTION;
        }

        if (alarmQuestion != null) {
            suite.alarmInterruptQuestion = alarmQuestion;
        } else {
            suite.alarmInterruptQuestion = ALARM_INTERRUPT_QUESTION;
        }

        return suite;
    
protected java.lang.StringgetAlarmInterruptQuestion()
Get the Alarm interrupt question the should be used when interrupting this suite.

The question will have %2 where this suite name should be and a %1 where the current suite name should be.

return
alarm interrupt question

        return alarmInterruptQuestion;
    
public java.lang.StringgetCA()
Gets the name of CA that authorized this suite.

return
name of a CA or null if the suite was not signed

        return null;
    
public java.lang.StringgetInitialMIDletClassname()
Get the classname of the initial MIDlet to run.

return
classname of a MIDlet

        if (initialMIDletClassName != null) {
            return initialMIDletClassName;
        }

        // Have the user select a MIDlet. The selector should not exit.
        return "com.sun.midp.dev.PersistentSelector";
    
public java.lang.StringgetJadUrl()
The JAD URL of the suite. This is only for the installer.

return
URL of the JAD can be null

        return null;
    
public java.lang.StringgetJarUrl()
The JAR URL of the suite. This is only for the installer.

return
URL of the JAR, never null, even in development environments

        return "none";
    
public intgetNumberOfMIDlets()
Provides the number of of MIDlets in this suite.

return
number of MIDlet in the suite

        return numberOfMidlets;
    
public java.lang.StringgetProperty(java.lang.String key)
Get a property of the suite. A property is an attribute from the application descriptor.

param
key the name of the property
return
A string with the value of the property. null is returned if no value is available for the key.

        return bufferedJadProps.getProperty(key);
    
protected java.lang.StringgetPushInterruptQuestion()
Get the Push interrupt question the should be used when interrupting this suite.

The question will have %2 where this suite name should be and a %1 where the current suite name should be.

return
push interrupt question

        return pushInterruptQuestion;
    
public byte[]getResource(java.lang.String name)
Get a named resource out of the JAR of this MIDlet suite.

param
name name of the resource
return
raw bytes of the resource or null if not available

        return null;
    
public java.lang.StringgetStorageRoot()
Gets the path root of any file this suite. Has any needed file separators appended.

return
storage path root

        return storageRoot;
    
public intgetStorageUsed()
Get the amount of storage on the device that this suite is using. This includes the JAD, JAR, management data, and RMS.

return
number of bytes of storage the suite is using.

        return 0;
    
protected java.lang.StringgetSuiteNameForInterrupt()
Get the suite name for interruption purposes.

return
name for interrupt question

        String name = getProperty(Installer.SUITE_NAME_PROP);

        if (name != null) {
            return name;
        }

        return initialMIDletClassName;
    
public voidsaveSettings()
Save any the settings (security or others) that the user may have changed. Normally called by the scheduler after the last running MIDlet in the suite is destoryed. However it could be call during a suspend of the VM so that persisent settings of the suite can be perserved.

        // we do not save the settings for classes run from the classpath