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.automation;
028:
029: import com.sun.midp.main.*;
030: import com.sun.midp.events.*;
031:
032: /**
033: * Initializes Automation API
034: */
035: public final class AutomationInitializer {
036: /** Event queue */
037: private static EventQueue eventQueue = null;
038:
039: /** MIDletControllerEventProducer instance */
040: private static MIDletControllerEventProducer midletControllerEventProducer = null;
041:
042: /** whether Automation API has been initialized or not */
043: private static boolean isInitialized = false;
044:
045: /**
046: * Private constructor to prevent creating class instances
047: */
048: private AutomationInitializer() {
049: }
050:
051: /**
052: * Initializes Automation API.
053: *
054: * @param theEventQueue Automation API's isolate event queue
055: * @param theMidletControllerEventProducer MIDletControllerEventProducer
056: */
057: public static void init(
058: EventQueue theEventQueue,
059: MIDletControllerEventProducer theMidletControllerEventProducer) {
060:
061: if (!isInitialized) {
062: eventQueue = theEventQueue;
063: midletControllerEventProducer = theMidletControllerEventProducer;
064: isInitialized = true;
065: }
066: }
067:
068: /**
069: * Gets event queue.
070: *
071: * @return Automation API's isolate event queue
072: * @throws IllegalStateException if Automation API isn't initialized
073: * or not permitted to use
074: */
075: static EventQueue getEventQueue() throws IllegalStateException {
076:
077: guaranteeAutomationInitialized();
078: return eventQueue;
079: }
080:
081: /**
082: * Gets MIDletControllerEventProducer.
083: *
084: * @return MIDletControllerEventProducer instance
085: * @throws IllegalStateException if Automation API isn't initialized
086: * or not permitted to use
087: */
088: static MIDletControllerEventProducer getMIDletControllerEventProducer()
089: throws IllegalStateException {
090:
091: guaranteeAutomationInitialized();
092: return midletControllerEventProducer;
093: }
094:
095: /**
096: * Guarantees that Automation API is initialized and
097: * permitted to use.
098: *
099: * @throws IllegalStateException if Automation API isn't initialized
100: * or not permitted to use
101: */
102: static void guaranteeAutomationInitialized()
103: throws IllegalStateException {
104:
105: if (!isInitialized) {
106: throw new IllegalStateException(
107: "Automation API not initialized");
108: }
109: }
110: }
|