FileDocCategorySizeDatePackage
CdcMIDletLoader.javaAPI DocphoneME MR2 API (J2ME)3261Wed May 02 18:00:08 BST 2007com.sun.midp.main

CdcMIDletLoader

public class CdcMIDletLoader extends Object implements MIDletLoader
The class implements the MIDlet loader for the CLDC VM.

Fields Summary
private MIDletSuiteStorage
midletSuiteStorage
Reference to the MIDlet suite storage object.
Constructors Summary
public CdcMIDletLoader(MIDletSuiteStorage mss)
Initializes this object.

param
mss the MIDlet suite storage

        midletSuiteStorage = mss;
    
Methods Summary
public MIDletnewInstance(MIDletSuite suite, java.lang.String className)
Loads a MIDlet from a suite's JAR.

param
suite reference to the suite
param
className class name of the MIDlet to be created
return
new instance of a MIDlet
exception
ClassNotFoundException if the MIDlet class is not found
exception
InstantiationException if the MIDlet cannot be created or is not subclass of MIDlet
exception
IllegalAccessException if the MIDlet is not permitted to perform a specific operation

        String[] jars;
        Class midletClass;

        if (suite.getID() == -1) {
            /*
             * This is the internal suite, that has no JAR
             *
             * This is a workaround for loading external midlets
             * from command line. The ID can be -1.
             */
            jars = MIDPLauncher.getMidletSuitePath();
        } else {
            jars = midletSuiteStorage.
                       getMidletSuiteClassPath(suite.getID());
        }

        /* Use MIDletClassLoader to load the main midlet class. */
        MIDletClassLoader  midletClassLoader =
            MIDPConfig.newMIDletClassLoader(jars);          

        midletClass = midletClassLoader.loadClass(className);

        if (!MIDlet.class.isAssignableFrom(midletClass)) {
            throw new InstantiationException("Class not a MIDlet");
        }

        return (MIDlet)midletClass.newInstance();