01: /*
02: *
03: *
04: * Copyright 1990-2007 Sun Microsystems, Inc. All Rights Reserved.
05: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
06: *
07: * This program is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU General Public License version
09: * 2 only, as published by the Free Software Foundation.
10: *
11: * This program is distributed in the hope that it will be useful, but
12: * WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * General Public License version 2 for more details (a copy is
15: * included at /legal/license.txt).
16: *
17: * You should have received a copy of the GNU General Public License
18: * version 2 along with this work; if not, write to the Free Software
19: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20: * 02110-1301 USA
21: *
22: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
23: * Clara, CA 95054 or visit www.sun.com if you need additional
24: * information or have any questions.
25: */
26:
27: package com.sun.midp.events;
28:
29: import javax.microedition.midlet.MIDlet;
30:
31: import com.sun.midp.main.MIDletSuiteUtils;
32:
33: /**
34: * Register an event listener, send an event to self, and throw a
35: * RuntimeException while processing an event.
36: */
37: public class FatalMIDlet extends MIDlet implements EventListener {
38: /**
39: * Set up.
40: */
41: public void startApp() {
42: EventQueue eventQueue;
43: Event event;
44:
45: if (MIDletSuiteUtils.isAmsIsolate()) {
46: // This is single VM mode don't throw a fatal error. Just end.
47: notifyDestroyed();
48: return;
49: }
50:
51: eventQueue = EventQueue.getEventQueue();
52:
53: eventQueue.registerEventListener(EventTypes.TEST_EVENT, this );
54:
55: event = new Event(EventTypes.TEST_EVENT);
56:
57: eventQueue.post(event);
58: }
59:
60: /**
61: * Pause; there are no resources that need to be released.
62: */
63: public void pauseApp() {
64: }
65:
66: /**
67: * Does nothing.
68: *
69: * @param unconditional is ignored
70: */
71: public void destroyApp(boolean unconditional) {
72: }
73:
74: /**
75: * Preprocess an event that is being posted to the event queue.
76: * This method will get called in the thread that posted the event.
77: *
78: * @param event event being posted
79: *
80: * @param waitingEvent previous event of this type waiting in the
81: * queue to be processed
82: *
83: * @return true to allow the post to continue, false to not post the
84: * event to the queue
85: */
86: public boolean preprocess(Event event, Event waitingEvent) {
87: return true;
88: }
89:
90: /**
91: * Process an event.
92: * This method will get called in the event queue processing thread.
93: *
94: * @param event event to process
95: */
96: public void process(Event event) {
97: throw new RuntimeException("fatal test error");
98: }
99: }
|