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.jump;
26:
27: import java.net.URL;
28: import com.sun.jump.common.JUMPAppModel;
29: import com.sun.jump.common.JUMPApplication;
30:
31: /**
32: * Representation of an MIDlet application.
33: */
34: public class MIDletApplication extends JUMPApplication {
35:
36: public static final String SUITE_KEY = "MIDletApplication_suiteid";
37: public static final String CLASSNAME_KEY = "MIDletApplication_classname";
38:
39: public static int getMIDletSuiteID(JUMPApplication app) {
40: return Integer.parseInt(app.getProperty(SUITE_KEY));
41: }
42:
43: public static String getMIDletClassName(JUMPApplication app) {
44: return app.getProperty(CLASSNAME_KEY);
45: }
46:
47: /**
48: * Create an instance of an application.
49: *
50: * @param title The application's title, can be null
51: * @param iconPath The location of the application's icon in, can be null
52: * @param suiteID the MIDlet suite id which this midlet belongs to.
53: * @param classname the MIDlet class name.
54: */
55: public MIDletApplication(String title, URL iconPath, int suiteID,
56: String classname, int midletID) {
57:
58: super (title, iconPath, JUMPAppModel.MIDLET,
59: computeApplicationID(suiteID, midletID));
60:
61: addProperty(SUITE_KEY, Integer.toString(suiteID));
62: addProperty(CLASSNAME_KEY, classname);
63: }
64:
65: public int getMIDletSuiteID() {
66: return Integer.parseInt(getProperty(SUITE_KEY));
67: }
68:
69: public String getMIDletClassName() {
70: return getProperty(CLASSNAME_KEY);
71: }
72:
73: public String toString() {
74: return (super .toString() + " MIDletSuiteID("
75: + getMIDletSuiteID() + ")");
76: }
77:
78: private static int computeApplicationID(int suiteId,
79: int midletNumber) {
80: return (suiteId << 8 | (midletNumber & 0x00ff));
81: }
82:
83: public static int convertToSuiteID(int applicationID) {
84: return (applicationID >> 8);
85: }
86: }
|