Package ca.simplegames.micro.controllers

Examples of ca.simplegames.micro.controllers.ControllerManager


        log.info("Repositories:");
        // - Repositories
        repositoryManager = new RepositoryManager(this);

        // - Controllers
        controllerManager = new ControllerManager(this, (Map<String, Object>) appConfig.get("controllers"));

        // - Filters
        // log.info("Filters:");
        File filtersConfig = new File(configPath, "filters.yml");
        if (filtersConfig.exists()) {
View Full Code Here


        MicroContext context = new MicroContext<String>();
        Context<String> input = new MapContext<String>()
                .with(Rack.REQUEST_METHOD, "GET")
                .with(Rack.PATH_INFO, "/micro-logo.png");

        ControllerManager cm = micro.getSite().getControllerManager();
        cm.execute("allien.Controller", context);
    }
View Full Code Here

     * try to execute a controller that will generate an internal exception
     */
    @Test(expected = ControllerException.class)
    public void testExceptionalController() throws Exception {

        ControllerManager cm = micro.getSite().getControllerManager();
        cm.execute("DivideByZero.bsh", new MicroContext<String>());
    }
View Full Code Here

    private void executeViewControllers(List<Map<String, Object>> controllers, MicroContext context)
            throws ControllerException, ControllerNotFoundException {

        if (context != null && !CollectionUtils.isEmpty(controllers)) {
            ControllerManager controllerManager = context.getSiteContext().getControllerManager();
            for (Map<String, Object> map : controllers) {
                final Map controllerMap = (Map) map.get(Globals.CONTROLLER);
                if (!CollectionUtils.isEmpty(controllerMap)) {
                    String controllerName = (String) controllerMap.get(Globals.NAME);
                    String wrapperName = (String) controllerMap.get(Globals.WRAPPER);

                    // StringUtils.isNotBlank too heavy for this crowded space ... sorry Commons::Lang
                    if (controllerName != null && !controllerName.isEmpty()) {
                        if (wrapperName != null && !wrapperName.isEmpty()) {
                            try {
                                ControllerWrapper controller =
                                        (ControllerWrapper) ClassUtilities.loadClass(wrapperName).newInstance();
                                Class[] paramTypes = {String.class, MicroContext.class, Map.class};
                                Object[] params = {controllerName, context, (Map) controllerMap.get(Globals.OPTIONS)};
                                Method method = controller.getClass()
                                        .getDeclaredMethod(ControllerManager.EXECUTE_METHOD, paramTypes);
                                method.invoke(controller, params);
                            } catch (Exception e) {
                                repository.getLog().error(String.format("%s, error: %s", controllerName, e.getMessage()));
                                e.printStackTrace();
                                throw new ControllerException(e.getMessage());
                            }
                        } else {
                            controllerManager.execute(controllerName, context, (Map) controllerMap.get(Globals.OPTIONS));
                        }
                    }
                }
            }
        }
View Full Code Here

TOP

Related Classes of ca.simplegames.micro.controllers.ControllerManager

Copyright © 2018 www.massapicom. 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.