public Shell create()

in gshell-wisdom/gshell-wisdom-bootstrap/src/main/java/org/apache/geronimo/gshell/wisdom/application/ApplicationManagerImpl.java [178:240]


    public Shell create() throws Exception {
        // Make sure that we have a valid context
        getApplication();

        final Shell shell = applicationContainer.getBean(Shell.class);

        final ShellContext context = shell.getContext();

        log.debug("Created shell instance: {}", shell);

        InvocationHandler handler = new InvocationHandler() {
            //
            // FIXME: Need to resolve how to handle the security manager for the application,
            //        the SM is not thread-specific, but VM specific... so not sure this is
            //        the right approache at all :-(
            //

            //
            // FIXME: This SM actually causes some icky problems when trying to shutdown thread pools, which makes for ugly crap when using ssh
            //

            //
            // FIXME: Disable our custom security stuff for now, not sure how to make this work well... yet.
            //
            // private final ApplicationSecurityManager sm = new ApplicationSecurityManager();

            public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable {
                assert proxy != null;
                assert method != null;
                // args may be null

                if (method.getDeclaringClass() == Object.class) {
                    return method.invoke(this, args);
                }

                final ShellContext prevContext = ShellContextHolder.get(true);
                ShellContextHolder.set(context);

                // final SecurityManager prevSM = System.getSecurityManager();
                // System.setSecurityManager(sm);

                try {
                    return method.invoke(shell, args);
                }
                catch (InvocationTargetException e) {
                    throw e.getTargetException();
                }
                finally {
                    // System.setSecurityManager(prevSM);
                    ShellContextHolder.set(prevContext);
                }
            }
        };

        ClassLoader cl = Thread.currentThread().getContextClassLoader();
        Shell proxy = (Shell) Proxy.newProxyInstance(cl, new Class[] { Shell.class }, handler);

        log.debug("Create shell proxy: {}", proxy);

        eventPublisher.publish(new ShellCreatedEvent(proxy));
        
        return proxy;
    }