Examples of AppContext

  • sisc.AppContext
  • sisc.interpreter.AppContext
  • sun.awt.AppContext
    The AppContext is a table referenced by ThreadGroup which stores application service instances. (If you are not writing an application service, or don't know what one is, please do not use this class.) The AppContext allows applet access to what would otherwise be potentially dangerous services, such as the ability to peek at EventQueues or change the look-and-feel of a Swing application.

    Most application services use a singleton object to provide their services, either as a default (such as getSystemEventQueue or getDefaultToolkit) or as static methods with class data (System). The AppContext works with the former method by extending the concept of "default" to be ThreadGroup-specific. Application services lookup their singleton in the AppContext.

    For example, here we have a Foo service, with its pre-AppContext code:

     public class Foo { private static Foo defaultFoo = new Foo(); public static Foo getDefaultFoo() { return defaultFoo; } ... Foo service methods }

    The problem with the above is that the Foo service is global in scope, so that applets and other untrusted code can execute methods on the single, shared Foo instance. The Foo service therefore either needs to block its use by untrusted code using a SecurityManager test, or restrict its capabilities so that it doesn't matter if untrusted code executes it.

    Here's the Foo class written to use the AppContext:

     public class Foo { public static Foo getDefaultFoo() { Foo foo = (Foo)AppContext.getAppContext().get(Foo.class); if (foo == null) { foo = new Foo(); getAppContext().put(Foo.class, foo); } return foo; } ... Foo service methods }

    Since a separate AppContext can exist for each ThreadGroup, trusted and untrusted code have access to different Foo instances. This allows untrusted code access to "system-wide" services -- the service remains within the AppContext "sandbox". For example, say a malicious applet wants to peek all of the key events on the EventQueue to listen for passwords; if separate EventQueues are used for each ThreadGroup using AppContexts, the only key events that applet will be able to listen to are its own. A more reasonable applet request would be to change the Swing default look-and-feel; with that default stored in an AppContext, the applet's look-and-feel will change without disrupting other applets or potentially the browser itself.

    Because the AppContext is a facility for safely extending application service support to applets, none of its methods may be blocked by a a SecurityManager check in a valid Java implementation. Applets may therefore safely invoke any of its methods without worry of being blocked. Note: If a SecurityManager is installed which derives from sun.awt.AWTSecurityManager, it may override the AWTSecurityManager.getAppContext() method to return the proper AppContext based on the execution context, in the case where the default ThreadGroup-based AppContext indexing would return the main "system" AppContext. For example, in an applet situation, if a system thread calls into an applet, rather than returning the main "system" AppContext (the one corresponding to the system thread), an installed AWTSecurityManager may return the applet's AppContext based on the execution context. @author Thomas Ball @author Fred Ecks


  • Examples of sun.awt.AppContext

                dispatchThread.stopDispatchingLater();
            }

      nextQueue = newEventQueue;
     
            AppContext appContext = AppContext.getAppContext();
            if (appContext.get(AppContext.EVENT_QUEUE_KEY) == this) {
          appContext.put(AppContext.EVENT_QUEUE_KEY, newEventQueue);
            }
        }
    View Full Code Here

    Examples of sun.awt.AppContext

          System.err.println("interrupted pop:");
          ie.printStackTrace(System.err);
            }
        }
          }
                AppContext appContext = AppContext.getAppContext();
                if (appContext.get(AppContext.EVENT_QUEUE_KEY) == this) {
                    appContext.put(AppContext.EVENT_QUEUE_KEY, previousQueue);
                }

          previousQueue = null;
              }
            }
    View Full Code Here

    Examples of sun.awt.AppContext

            public void dispose() {
                Window parent = owner.get();
                if (parent != null) {
                    parent.removeOwnedWindow(weakThis);
                }
                AppContext ac = context.get();
                if (null != ac) {
                    Window.removeFromWindowList(ac, weakThis);
                }
            }
    View Full Code Here

    Examples of sun.awt.AppContext

                        // if this dialog is toolkit-modal, the filter should be added
                        // to all EDTs (for all AppContexts)
                        if (modalityType == ModalityType.TOOLKIT_MODAL) {
                            Iterator it = AppContext.getAppContexts().iterator();
                            while (it.hasNext()) {
                                AppContext appContext = (AppContext)it.next();
                                if (appContext == showAppContext) {
                                    continue;
                                }
                                EventQueue eventQueue = (EventQueue)appContext.get(AppContext.EVENT_QUEUE_KEY);
                                // it may occur that EDT for appContext hasn't been started yet, so
                                // we post an empty invocation event to trigger EDT initialization
                                Runnable createEDT = new Runnable() {
                                    public void run() {};
                                };
                                eventQueue.postEvent(new InvocationEvent(this, createEDT));
                                EventDispatchThread edt = eventQueue.getDispatchThread();
                                edt.addEventFilter(modalFilter);
                            }
                        }

                        modalityPushed();
                        try {
                            if (EventQueue.isDispatchThread()) {
                                /*
                                 * dispose SequencedEvent we are dispatching on current
                                 * AppContext, to prevent us from hang.
                                 *
                                 */
                                // BugId 4531693 (son@sparc.spb.su)
                                SequencedEvent currentSequencedEvent = KeyboardFocusManager.
                                    getCurrentKeyboardFocusManager().getCurrentSequencedEvent();
                                if (currentSequencedEvent != null) {
                                    currentSequencedEvent.dispose();
                                }

                                /*
                                 * Event processing is done inside doPrivileged block so that
                                 * it wouldn't matter even if user code is on the stack
                                 * Fix for BugId 6300270
                                 */

                                 AccessController.doPrivileged(new PrivilegedAction() {
                                         public Object run() {
                                            pumpEventsForFilter.run();
                                            return null;
                                         }
                                 });
                            } else {
                                synchronized (getTreeLock()) {
                                    Toolkit.getEventQueue().postEvent(new PeerEvent(this,
                                                                                    pumpEventsForFilter,
                                                                                    PeerEvent.PRIORITY_EVENT));
                                    while (keepBlocking && windowClosingException == null) {
                                        try {
                                            getTreeLock().wait();
                                        } catch (InterruptedException e) {
                                            break;
                                        }
                                    }
                                }
                            }
                        } finally {
                            modalityPopped();
                        }

                        // if this dialog is toolkit-modal, its filter must be removed
                        // from all EDTs (for all AppContexts)
                        if (modalityType == ModalityType.TOOLKIT_MODAL) {
                            Iterator it = AppContext.getAppContexts().iterator();
                            while (it.hasNext()) {
                                AppContext appContext = (AppContext)it.next();
                                if (appContext == showAppContext) {
                                    continue;
                                }
                                EventQueue eventQueue = (EventQueue)appContext.get(AppContext.EVENT_QUEUE_KEY);
                                EventDispatchThread edt = eventQueue.getDispatchThread();
                                edt.removeEventFilter(modalFilter);
                            }
                        }

    View Full Code Here

    Examples of sun.awt.AppContext

                        if (null != pcs) {
                            pcs.firePropertyChange(evt);
                        }
                    }
                };
                final AppContext currentAppContext = AppContext.getAppContext();
                for (AppContext appContext : AppContext.getAppContexts()) {
                    if (null == appContext || appContext.isDisposed()) {
                        continue;
                    }
                    if (currentAppContext == appContext) {
    View Full Code Here

    Examples of sun.awt.AppContext

        //30 repaints per second should give smooth animation affect
        private final javax.swing.Timer timer =
                new javax.swing.Timer(1000 / 30, this);

        private static synchronized AnimationController getAnimationController() {
            AppContext appContext = AppContext.getAppContext();
            Object obj = appContext.get(ANIMATION_CONTROLLER_KEY);
            if (obj == null) {
                obj = new AnimationController();
                appContext.put(ANIMATION_CONTROLLER_KEY, obj);
            }
            return (AnimationController) obj;
        }
    View Full Code Here

    Examples of sun.awt.AppContext

                    }
                }
            };

            final JDesktopPane desktop = toolkit.getAwtContext().getDesktop();
            AppContext ac = SunToolkit.targetToAppContext(desktop);
            if (ac != null) {
                EventQueue eq = (EventQueue) ac.get(AppContext.EVENT_QUEUE_KEY);
                if (eq != null) {
                    eq.postEvent(new InvocationEvent(Toolkit.getDefaultToolkit(), run));
                    return;
                }
            }
    View Full Code Here

    Examples of sun.awt.AppContext

                public Object run() {


                    //peer frames should be created in the same app context where the desktop is
                    //todo refactor this into a generic inter-appcontext invoke and wait
                    AppContext ac = SunToolkit.targetToAppContext(target);
                    if (ac != null) {
                        EventQueue eq = (EventQueue) ac.get(sun.awt.AppContext.EVENT_QUEUE_KEY);
                        if (eq != null) {
                            try {
                                Method met = EventQueue.class.getDeclaredMethod("initDispatchThread");
                                met.setAccessible(true);
                                met.invoke(eq);
    View Full Code Here

    Examples of sun.awt.AppContext

        public JNodeToolkit() {
            refCount = 0;
            systemClipboard = new Clipboard("JNodeSystemClipboard");

            //initialize the main AppContext
            AppContext appContext = AppContext.getAppContext();

            synchronized (this) {
                if (appContext.get(AppContext.EVENT_QUEUE_KEY) == null || _eventQueue == null) {
                    String eqName = System.getProperty("AWT.EventQueueClass", "org.jnode.awt.JNodeEventQueue");
                    try {
                        _eventQueue = (JNodeEventQueue) Class.forName(eqName).newInstance();
                    } catch (Exception e) {
                        e.printStackTrace();
                        System.err.println("Failed loading " + eqName + ": " + e);
                        _eventQueue = new JNodeEventQueue();
                    }
                    appContext.put(AppContext.EVENT_QUEUE_KEY, _eventQueue);
                }
            }
        }
    View Full Code Here

    Examples of sun.awt.AppContext

        /**
         * @return The event queue
         */
        protected final EventQueue getSystemEventQueueImpl() {
            AppContext ac = AppContext.getAppContext();
            if (ac != null) {
                EventQueue eq = (EventQueue) ac.get(AppContext.EVENT_QUEUE_KEY);
                if (eq != null) {
                    return eq;
                }
            }

            if ((_eventQueue == null) || (!_eventQueue.isLive() && isGuiActive())) {
                synchronized (this) {
                    if ((_eventQueue == null) || (!_eventQueue.isLive() && isGuiActive())) {
                        _eventQueue = new JNodeEventQueue();
                    }

                    if (ac != null && ac.get(AppContext.EVENT_QUEUE_KEY) == null) {
                        ac.put(AppContext.EVENT_QUEUE_KEY, _eventQueue);
                    }
                }
            }

            return _eventQueue;
    View Full Code Here
    TOP
    Copyright © 2018 www.massapi.com. All rights reserved.
    All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.