01: /*
02: * Copyright 1990-2007 Sun Microsystems, Inc. All Rights Reserved.
03: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
04: *
05: * This program is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU General Public License version
07: * 2 only, as published by the Free Software Foundation.
08: *
09: * This program is distributed in the hope that it will be useful, but
10: * WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12: * General Public License version 2 for more details (a copy is
13: * included at /legal/license.txt).
14: *
15: * You should have received a copy of the GNU General Public License
16: * version 2 along with this work; if not, write to the Free Software
17: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18: * 02110-1301 USA
19: *
20: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
21: * Clara, CA 95054 or visit www.sun.com if you need additional
22: * information or have any questions.
23: */
24:
25: package com.sun.midp.main;
26:
27: import javax.microedition.midlet.*;
28:
29: import com.sun.midp.midlet.*;
30:
31: import com.sun.midp.midletsuite.*;
32:
33: import sun.misc.*;
34: import java.net.*;
35:
36: /**
37: * The class implements the MIDlet loader for the CLDC VM.
38: */
39: public class CdcMIDletLoader implements MIDletLoader {
40: /** Reference to the MIDlet suite storage object. */
41: private MIDletSuiteStorage midletSuiteStorage;
42:
43: /**
44: * Initializes this object.
45: *
46: * @param mss the MIDlet suite storage
47: *
48: */
49: public CdcMIDletLoader(MIDletSuiteStorage mss) {
50: midletSuiteStorage = mss;
51: }
52:
53: /**
54: * Loads a MIDlet from a suite's JAR.
55: *
56: * @param suite reference to the suite
57: * @param className class name of the MIDlet to be created
58: *
59: * @return new instance of a MIDlet
60: *
61: * @exception ClassNotFoundException if the MIDlet class is
62: * not found
63: * @exception InstantiationException if the MIDlet cannot be
64: * created or is not subclass of MIDlet
65: * @exception IllegalAccessException if the MIDlet is not
66: * permitted to perform a specific operation
67: */
68: public MIDlet newInstance(MIDletSuite suite, String className)
69: throws ClassNotFoundException, InstantiationException,
70: IllegalAccessException {
71: String[] jars;
72: Class midletClass;
73:
74: if (suite.getID() == -1) {
75: /*
76: * This is the internal suite, that has no JAR
77: *
78: * This is a workaround for loading external midlets
79: * from command line. The ID can be -1.
80: */
81: jars = MIDPLauncher.getMidletSuitePath();
82: } else {
83: jars = midletSuiteStorage.getMidletSuiteClassPath(suite
84: .getID());
85: }
86:
87: /* Use MIDletClassLoader to load the main midlet class. */
88: MIDletClassLoader midletClassLoader = MIDPConfig
89: .newMIDletClassLoader(jars);
90:
91: midletClass = midletClassLoader.loadClass(className);
92:
93: if (!MIDlet.class.isAssignableFrom(midletClass)) {
94: throw new InstantiationException("Class not a MIDlet");
95: }
96:
97: return (MIDlet) midletClass.newInstance();
98: }
99: }
|