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.lcdui;
28:
29: import javax.microedition.lcdui.Display;
30:
31: import com.sun.midp.security.SecurityToken;
32: import com.sun.midp.security.Permissions;
33:
34: /**
35: * This class works around the fact that public classes can not
36: * be added to a javax package by an implementation.
37: */
38: public class DisplayEventHandlerFactory {
39: /** The real implementation of the display event handler. */
40: private static DisplayEventHandler managerImpl;
41:
42: /**
43: * Set the implementation of the display manager, if one
44: * is not already set.
45: * <p>
46: * This implementation class will be in the as the Display class for
47: * security. But needs placed here to be visible to com.sun.midp classes.
48: *
49: * @param dm reference to the system display manager
50: */
51: public static void SetDisplayEventHandlerImpl(DisplayEventHandler dm) {
52: if (managerImpl != null) {
53: return;
54: }
55:
56: managerImpl = dm;
57: };
58:
59: /**
60: * Return a reference to the singleton display manager object.
61: *
62: * @param token security token with the MIDP permission "allowed"
63: *
64: * @return display manager reference.
65: */
66: public static DisplayEventHandler getDisplayEventHandler(
67: SecurityToken token) {
68:
69: token.checkIfPermissionAllowed(Permissions.MIDP);
70:
71: if (managerImpl != null) {
72: return managerImpl;
73: }
74:
75: /**
76: * The display manager implementation is a private class of Display
77: * and is create in the class init of Display, we need to call a
78: * static method of display to get the class init to run, because
79: * some classes need to get the display manager to create a display
80: */
81: try {
82: // this will yield a null pointer exception on purpose
83: Display.getDisplay(null);
84: } catch (NullPointerException npe) {
85: // this is normal for this case, do nothing
86: }
87:
88: return managerImpl;
89: };
90: }
|