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.mmedia;
28:
29: import com.sun.midp.events.*;
30: import com.sun.midp.security.*;
31:
32: /**
33: * MMEventHandler is used by BasicPlayer to register an event handler.
34: */
35: public class MMEventHandler {
36:
37: /**
38: * Inner class to request security token from SecurityInitializer.
39: * SecurityInitializer should be able to check this inner class name.
40: */
41: static private class SecurityTrusted implements
42: ImplicitlyTrustedClass {
43: };
44:
45: /** This class has a different security domain than the MIDlet suite */
46: private static SecurityToken classSecurityToken = SecurityInitializer
47: .requestToken(new SecurityTrusted());
48:
49: /**
50: * The EventListener to receive the MM events.
51: */
52: private static EventListener listener;
53:
54: /**
55: * Initializes the security token for this class, so it can
56: * perform actions that a normal MIDlet Suite cannot.
57: *
58: * @param token security token for this class.
59: */
60: public static void initSecurityToken(SecurityToken token) {
61: if (classSecurityToken == null) {
62: classSecurityToken = token;
63: }
64: }
65:
66: /**
67: * Set the Event listener on the event queue.
68: * <br>
69: * This method is made package-private so only classes from
70: * com.sun.mmedia (BasicPlayer) can access it for security
71: * reasons.
72: *
73: * @param l EventListener for the MM events.
74: */
75: static void setListener(EventListener l) {
76:
77: // This can only be set once.
78: if (listener != null)
79: return;
80: listener = l;
81:
82: EventQueue evtq = EventQueue.getEventQueue(classSecurityToken);
83: evtq.registerEventListener(EventTypes.MMAPI_EVENT, listener);
84: }
85: }
|