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 org.apache.openejb.AppContext

            });

            deploymentId = "deploymentId";
            deploymentInfo = new BeanContext(deploymentId,
                null,
                new ModuleContext(deploymentId, null, null, new AppContext(deploymentId, SystemInstance.get(), getClass().getClassLoader(), null, null, false), null),
                SFSB.class,
                null,
                null,
                null,
                null,
    View Full Code Here

    Examples of org.apache.tez.dag.app.AppContext

      public AppContext createMockAppContext() {

        ApplicationId appId = ApplicationId.newInstance(2000, 1);
        ApplicationAttemptId appAttemptId = ApplicationAttemptId.newInstance(appId, 1);

        AppContext appContext = mock(AppContext.class);
        doReturn(appAttemptId).when(appContext).getApplicationAttemptId();

        return appContext;
      }
    View Full Code Here

    Examples of org.apache.tools.ant.gui.core.AppContext

             * post <code>ConsoleNotVisibleEvent</code> or
             * <code>ConsoleVisibleEvent</code> events.
             */
            addComponentListener(new ComponentAdapter() {
                public void componentResized(ComponentEvent e) {
                    AppContext c = BuildConsole.this.getContext();
                    if (BuildConsole.this.getHeight() == 0) {
                        c.getEventBus().postEvent(new ConsoleNotVisibleEvent(c));
                    } else {
                        c.getEventBus().postEvent(new ConsoleVisibleEvent(c));
                    }
                }
                public void componentHidden(ComponentEvent e) {}
                public void componentMoved(ComponentEvent e) {}
                public void componentShown(ComponentEvent e) {}
    View Full Code Here

    Examples of org.mule.el.context.AppContext

        public StaticVariableResolverFactory(ParserConfiguration parserConfiguration, MuleContext muleContext)
        {
            super(parserConfiguration, muleContext);
            addFinalVariable("server", new ServerContext());
            addFinalVariable("mule", new MuleInstanceContext(muleContext));
            addFinalVariable("app", new AppContext(muleContext));
            addFinalVariable(MVELExpressionLanguageContext.MULE_CONTEXT_INTERNAL_VARIABLE, muleContext);
            declareFunction("regex", new RegexExpressionLanguageFuntion());
            declareFunction("wildcard", new WildcardExpressionLanguageFuntion());
            declareFunction("dateTime", new DateTimeExpressionLanguageFuntion());
        }
    View Full Code Here

    Examples of sisc.AppContext

        synchronized (httpContext) {
          siscContext = (AppContext)httpContext.getAttribute(REPLGenericServlet.appCtxAttrName);

          if (siscContext == null) {
            siscContext = new AppContext();
            httpContext.setAttribute(REPLGenericServlet.appCtxAttrName, siscContext);

            interPool = new ArrayList();
            Interpreter interp = getInterpreter();
    View Full Code Here

    Examples of sisc.AppContext

        synchronized(interPool) {
          if (!interPool.empty())
            return (Interpreter)interPool.pop();

          // Create a new interpreter and return it
          AppContext ctx = (AppContext)servletContext.getAttribute(appCtxAttrName);
          DynamicEnv environment = new DynamicEnv(System.in, System.out);
          Interpreter interp = new Interpreter(ctx, environment);
          return interp;
        }
      }
    View Full Code Here

    Examples of sisc.AppContext

        interPool = new Stack();

        Interpreter interp;

        synchronized (servletContext) {
          AppContext ctx = (AppContext)servletContext.getAttribute(appCtxAttrName);

          if (ctx == null) {
            ctx = new AppContext();
            servletContext.setAttribute(appCtxAttrName, ctx);

            interp = getInterpreter();
            // Read the heap file
            String realPath = servletContext.getRealPath("/");
            String heapFileName = realPath + config.getInitParameter("heap");
            System.out.println("loading heap " + heapFileName);
            File heapFile = new File(heapFileName);

            try {
              FileInputStream fis = new FileInputStream(heapFileName);
              BufferedInputStream bis
                = new BufferedInputStream(fis, (int)heapFile.length());
              GZIPInputStream gzis = new GZIPInputStream(bis);
              DataInputStream dis
                = new DataInputStream(new BufferedInputStream(gzis));
              ctx.loadEnv(interp, dis);
         
            } catch (IOException ex) {
              System.err.println("Error loading heap:" + ex);
              ex.printStackTrace();
              throw new ServletException(ex);
            }

            ctx.setEvaluator("eval");
          }
          else {
            interp = getInterpreter();
          }     
        }
    View Full Code Here

    Examples of sisc.interpreter.AppContext

       * @param phoenix  PhoenixController for this SchemeController
       */
      public SchemeController(PhoenixController phoenix)
      {
        // load SISC
        AppContext ctx = new AppContext();
        this.phoenix = phoenix;
        this.window = new SchemeWindow(this);

        // load heap
        try
        {
          ctx.addHeap(AppContext.openHeap(new URL("file://"
            + PhoenixController.getFile("sisc.shp"))));
        } // try
        catch (Exception e)
        {
          e.printStackTrace();
    View Full Code Here

    Examples of sun.awt.AppContext

            }

            KeyboardFocusManager oldManager = null;

            synchronized (KeyboardFocusManager.class) {
                AppContext appcontext = AppContext.getAppContext();

                if (newManager != null) {
                    oldManager = getCurrentKeyboardFocusManager(appcontext);

                    appcontext.put(KeyboardFocusManager.class, newManager);
                } else {
                    oldManager = getCurrentKeyboardFocusManager(appcontext);
                    appcontext.remove(KeyboardFocusManager.class);
                }
            }

            if (oldManager != null) {
                oldManager.firePropertyChange("managingFocus",
    View Full Code Here

    Examples of sun.awt.AppContext

         * Returns true if successfuly dispatched event, false if failed
         * to dispatch.
         */
        static boolean sendMessage(Component target, AWTEvent e) {
            e.isPosted = true;
            AppContext myAppContext = AppContext.getAppContext();
            final AppContext targetAppContext = target.appContext;
            final SentEvent se =
                new DefaultKeyboardFocusManagerSentEvent(e, myAppContext);

            if (myAppContext == targetAppContext) {
                se.dispatch();
            } else {
                if (targetAppContext.isDisposed()) {
                    return false;
                }
                SunToolkit.postEvent(targetAppContext, se);
                if (EventQueue.isDispatchThread()) {
                    EventDispatchThread edt = (EventDispatchThread)
                        Thread.currentThread();
                    edt.pumpEvents(SentEvent.ID, new Conditional() {
                            public boolean evaluate() {
                                return !se.dispatched && !targetAppContext.isDisposed();
                            }
                        });
                } else {
                    synchronized (se) {
                        while (!se.dispatched && !targetAppContext.isDisposed()) {
                            try {
                                se.wait(1000);
                            } catch (InterruptedException ie) {
                                break;
                            }
    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.