001: /*
002: * @(#)XletContextImpl.java 1.27 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 com.sun.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 XletContextImpl 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: XletManager manager;
048:
049: // An AWT container. The xlet can draw on it.
050: Container container = null;
051:
052: public XletContextImpl(String xletName, String[] args,
053: XletManager 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: if (args == null) {
068: return new String[] {};
069: } else {
070: return args;
071: }
072: }
073: return null;
074: }
075:
076: // Returns the AWT container that the xlet is using.
077: public Container getContainer() {
078: if (container == null) {
079: container = manager.getContainer();
080: }
081: return container;
082: }
083:
084: // Request from the xlet to make itself active. startXlet is called on a
085: // different thread than the one used to call resumeRequest.
086: public void resumeRequest() {
087: // Spawn a different thread.
088: new Thread(manager.threadGroup, new Runnable() {
089: public void run() {
090: manager.handleRequest(XletState.ACTIVE);
091: }
092: }, "ResumeRequest Thread").start();
093: //manager.startXlet(manager);
094: }
095:
096: // Notification from the xlet that it is in the paused state.
097: public void notifyPaused() {
098: manager.setState(XletState.PAUSED);
099: }
100:
101: // Notification from the xlet that it is in the destroyed state.
102: public void notifyDestroyed() {
103: manager.setState(XletState.DESTROYED);
104: }
105:
106: /**
107: * Returns the base class loader of the Xlet. This class loader
108: * will be dedicated exclusively to the xlet. The xlet's classes are
109: * all loaded by this classloader or by a classloader that has this
110: * classloader as its ancestor.
111: */
112: public java.lang.ClassLoader getClassLoader() {
113: return XletManager.getXletClassLoader((XletContext) this);
114: }
115:
116: }
|