001: /*
002: * @(#)PXletContextImpl.java 1.7 06/10/10
003: *
004: * Copyright 1990-2006 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:
028: package sun.mtask.xlet;
029:
030: // Provides graphic representations for xlets.
031: import java.awt.Container;
032:
033: // Standard classes used by xlets.
034: import javax.microedition.xlet.XletContext;
035: import javax.microedition.xlet.XletStateChangeException;
036:
037: public class PXletContextImpl implements XletContext {
038:
039: // The xlet class name.
040: String mainClass;
041:
042: // Optional runtime arguments passed to this xlet from the command line.
043: String[] args;
044:
045: // An instance of XletManager. It manages the xlet that
046: // this XletContext belongs to.
047: PXletManager manager;
048:
049: // An AWT container. The xlet can draw on it.
050: Container container = null;
051:
052: public PXletContextImpl(String xletName, String[] args,
053: PXletManager manager) {
054: this .mainClass = xletName;
055: this .args = args;
056: this .manager = manager;
057: }
058:
059: // Returns the xlet properties, which were passed to the xlet with the
060: // -args option on the command line.
061: public Object getXletProperty(String key) {
062: if (key == null) {
063: throw new NullPointerException("Key is null");
064: } else if (key.equals("")) {
065: throw new IllegalArgumentException("Key is an empty String");
066: } else if (key.equals(ARGS)) {
067: return args;
068: }
069: return null;
070: }
071:
072: // Returns the AWT container that the xlet is using.
073: public Container getContainer() {
074: if (container == null) {
075: container = manager.getContainer();
076: }
077: return container;
078: }
079:
080: // Request from the xlet to make itself active. startXlet is called on a
081: // different thread than the one used to call resumeRequest.
082: public void resumeRequest() {
083: // Spawn a different thread.
084: new Thread(manager.threadGroup, new Runnable() {
085: public void run() {
086: manager.handleRequest(XletState.ACTIVE);
087: }
088: }, "ResumeRequest Thread").start();
089: }
090:
091: // Notification from the xlet that it is in the paused state.
092: public void notifyPaused() {
093: manager.setState(XletState.PAUSED);
094: }
095:
096: // Notification from the xlet that it is in the destroyed state.
097: public void notifyDestroyed() {
098: manager.setState(XletState.DESTROYED);
099: }
100:
101: /**
102: * Returns the base class loader of the Xlet. This class loader
103: * will be dedicated exclusively to the xlet. The xlet's classes are
104: * all loaded by this classloader or by a classloader that has this
105: * classloader as its ancestor.
106: */
107: public java.lang.ClassLoader getClassLoader() {
108: // In mtask, each xlet is confined to its own VM instance,
109: // using the system class loader in that instance
110: //
111: return ClassLoader.getSystemClassLoader();
112: }
113: }
|