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: /**
034: * Removes a suite.
035: */
036: public class SuiteRemover extends MIDlet implements Runnable {
037: /** ID of the suite. */
038: int suiteId;
039:
040: /**
041: * Create and initialize the MIDlet.
042: */
043: public SuiteRemover() {
044: // The arg-<n> properties are generic command arguments
045: String suiteArg = getAppProperty("arg-0");
046:
047: if (suiteArg == null) {
048: System.err.println("Suite ID argument missing.");
049: System.err.println("Suite remover arguments: <suite ID>");
050: notifyDestroyed();
051: return;
052: }
053:
054: try {
055: suiteId = Integer.parseInt(suiteArg);
056: } catch (Throwable t) {
057: System.err.println("Suite ID: " + t.getMessage());
058: notifyDestroyed();
059: }
060:
061: new Thread(this ).start();
062: }
063:
064: /**
065: * Start.
066: */
067: public void startApp() {
068: }
069:
070: /**
071: * Pause; there are no resources that need to be released.
072: */
073: public void pauseApp() {
074: }
075:
076: /**
077: * Destroy cleans up.
078: *
079: * @param unconditional is ignored; this object always
080: * destroys itself when requested.
081: */
082: public void destroyApp(boolean unconditional) {
083: }
084:
085: /** Remove a MIDlet suite. */
086: public void run() {
087: try {
088: MIDletSuiteStorage midletSuiteStorage = MIDletSuiteStorage
089: .getMIDletSuiteStorage();
090:
091: midletSuiteStorage.remove(suiteId);
092: System.out.println("Suite removed");
093: } catch (MIDletSuiteLockedException msle) {
094: System.err.println("Error: MIDlet suite is locked");
095: } catch (Throwable t) {
096: System.err.println("Error removing suite " + suiteId);
097: t.printStackTrace();
098: }
099:
100: notifyDestroyed();
101: }
102: }
|