001: /*
002: *
003: *
004: * Copyright 1990-2007 Sun Microsystems, Inc. All Rights Reserved.
005: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License version
009: * 2 only, as published by the Free Software Foundation.
010: *
011: * This program is distributed in the hope that it will be useful, but
012: * WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * General Public License version 2 for more details (a copy is
015: * included at /legal/license.txt).
016: *
017: * You should have received a copy of the GNU General Public License
018: * version 2 along with this work; if not, write to the Free Software
019: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA
021: *
022: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023: * Clara, CA 95054 or visit www.sun.com if you need additional
024: * information or have any questions.
025: */
026:
027: package com.sun.midp.scriptutil;
028:
029: import javax.microedition.midlet.MIDlet;
030:
031: import com.sun.midp.midletsuite.*;
032:
033: import com.sun.midp.midlet.MIDletSuite;
034:
035: /**
036: * List all installed suites.
037: */
038: public class SuiteLister extends MIDlet implements Runnable {
039: /**
040: * Create and initialize the MIDlet.
041: */
042: public SuiteLister() {
043: new Thread(this ).start();
044: }
045:
046: /**
047: * Start.
048: */
049: public void startApp() {
050: }
051:
052: /**
053: * Pause; there are no resources that need to be released.
054: */
055: public void pauseApp() {
056: }
057:
058: /**
059: * Destroy cleans up.
060: *
061: * @param unconditional is ignored; this object always
062: * destroys itself when requested.
063: */
064: public void destroyApp(boolean unconditional) {
065: }
066:
067: /** Remove a MIDlet suite. */
068: public void run() {
069: try {
070: MIDletSuiteStorage storage = MIDletSuiteStorage
071: .getMIDletSuiteStorage();
072:
073: int[] suiteIds = storage.getListOfSuites();
074:
075: if (suiteIds.length == 0) {
076: System.out.println("No suites installed.");
077: notifyDestroyed();
078: return;
079: }
080:
081: for (int i = 0; i < suiteIds.length; i++) {
082: MIDletSuite suite = storage.getMIDletSuite(suiteIds[i],
083: false);
084: String value;
085:
086: System.out.println("Suite: " + suiteIds[i]);
087:
088: value = suite.getProperty("MIDlet-Name");
089: System.out.println(" Name: " + value);
090:
091: value = suite.getProperty("MIDlet-Version");
092: System.out.println(" Version: " + value);
093:
094: value = suite.getProperty("MIDlet-Vendor");
095: System.out.println(" Vendor: " + value);
096:
097: value = suite.getProperty("MIDlet-Description");
098: if (value != null) {
099: System.out.println(" Description: " + value);
100: }
101:
102: for (int j = 1;; j++) {
103: value = suite.getProperty("MIDlet-" + j);
104: if (value == null) {
105: break;
106: }
107:
108: if (j == 1) {
109: System.out.println(" MIDlets:");
110: }
111:
112: MIDletInfo midlet = new MIDletInfo(value);
113: System.out.println(" " + midlet.name + ": "
114: + midlet.classname);
115: }
116: }
117: } catch (MIDletSuiteLockedException msle) {
118: System.err.println("Error: MIDlet suite is locked");
119: } catch (Throwable t) {
120: System.err.println("Error listing suites.");
121: t.printStackTrace();
122: }
123:
124: notifyDestroyed();
125: }
126: }
|