Examples of BSFManager


Examples of org.apache.bsf.BSFManager

    private static final long serialVersionUID = 234L;

    public void sampleOccurred(SampleEvent event) {
        try {
            BSFManager mgr = getManager();
            if (mgr == null) {
                log.error("Problem creating BSF manager");
                return;
            }
            mgr.declareBean("sampleEvent", event, SampleEvent.class);
            SampleResult result = event.getResult();
            mgr.declareBean("sampleResult", result, SampleResult.class);
            processFileOrScript(mgr);
            mgr.terminate();
        } catch (BSFException e) {
            log.warn("Problem in BSF script "+e);
        }
    }
View Full Code Here

Examples of org.apache.bsf.BSFManager

     * @return - list of results
     * @throws Exception
     */
    public List<?> runGroovy(String script, Object... args) throws Exception {
        List<?> answer;
        BSFManager manager = new BSFManager();

        for (int x = 0; x < args.length; x++) {
            manager.declareBean("arg" + x, args[x], String.class);
        }
        answer = (List) manager.eval("groovy", "script.groovy", 0, 0, script);

        return answer;
    }
View Full Code Here

Examples of org.apache.bsf.BSFManager

     *
     **/
   
    public void discardFromPool(Object object)
    {
        BSFManager manager = (BSFManager)object;
       
        manager.terminate();
    }
View Full Code Here

Examples of org.apache.bsf.BSFManager

    {
        boolean debug = LOG.isDebugEnabled();

        long startTime = debug ? System.currentTimeMillis() : 0;

        BSFManager bsf = obtainBSFManager(cycle);

        ILocation location = getLocation();

        try
        {
            IPage page = cycle.getPage();

            bsf.declareBean("component", _component, _component.getClass());
            bsf.declareBean("page", page, page.getClass());
            bsf.declareBean("cycle", cycle, cycle.getClass());

            bsf.exec(
                _language,
                location.getResourceLocation().toString(),
                location.getLineNumber(),
                location.getLineNumber(),
                _script);
View Full Code Here

Examples of org.apache.bsf.BSFManager

    private BSFManager obtainBSFManager(IRequestCycle cycle)
    {
        IEngine engine = cycle.getEngine();
        Pool pool = engine.getPool();

        BSFManager result = (BSFManager) pool.retrieve(BSF_POOL_KEY);

        if (result == null)
        {
            LOG.debug("Creating new BSFManager instance.");

            result = new BSFManager();

            result.setClassLoader(engine.getResourceResolver().getClassLoader());
        }

        return result;
    }
View Full Code Here

Examples of org.apache.bsf.BSFManager

     */
    public void initialize(UimaContext aContext)
        throws ResourceInitializationException {
        super.initialize(aContext);
    // Initialize a BSF manager and do some 'cooking' to adapt the class loader
    manager = new BSFManager();
    ClassLoader classLoader = this.getClass().getClassLoader();
    Thread.currentThread().setContextClassLoader(classLoader);
    manager.setClassLoader(classLoader);
    // Is a UIMAClassLoader
    if (classLoader instanceof URLClassLoader) {
View Full Code Here

Examples of org.apache.bsf.BSFManager

        }

        String location = this.getLocation(modelService);

        // create the manager object and set the classloader
        BSFManager mgr = new BSFManager();
        mgr.setClassLoader(cl);

        mgr.registerBean("dctx", dctx);
        mgr.registerBean("context", context);

        // pre-load the engine to make sure we were called right
        org.apache.bsf.BSFEngine bsfEngine = null;
        try {
            bsfEngine = mgr.loadScriptingEngine(modelService.engineName);
        } catch (BSFException e) {
            throw new GenericServiceException("Problems loading org.apache.bsf.BSFEngine: " + modelService.engineName, e);
        }

        // source the script into a string
        String script = scriptCache.get(localName + "_" + location);

        if (script == null) {
            synchronized (this) {
                script = scriptCache.get(localName + "_" + location);
                if (script == null) {
                    URL scriptUrl = UtilURL.fromResource(location, cl);

                    if (scriptUrl != null) {
                        try {
                            HttpClient http = new HttpClient(scriptUrl);
                            script = http.get();
                        } catch (HttpClientException e) {
                            throw new GenericServiceException("Cannot read script from resource", e);
                        }
                    } else {
                        throw new GenericServiceException("Cannot read script, resource [" + location + "] not found");
                    }
                    if (script == null || script.length() < 2) {
                        throw new GenericServiceException("Null or empty script");
                    }
                    scriptCache.put(localName + "_" + location, script);
                }
            }
        }

        // now invoke the script
        try {
            bsfEngine.exec(location, 0, 0, script);
        } catch (BSFException e) {
            throw new GenericServiceException("Script invocation error", e);
        }

        return mgr.lookupBean("response");
    }
View Full Code Here

Examples of org.apache.bsf.BSFManager

    }

    public XLoper execute(IFunctionContext context, XLoper[] args) throws RequestException {
        try {
            Object[] a = converter.convert(args, createArgHints(args));
            BSFManager manager = new BSFManager();
            manager.declareBean("context", a, IFunctionContext.class);
            manager.declareBean("args", a, Object[].class);
            Object res = manager.eval(lang, name, 1, 1, source);
            return converter.createFrom(res);
        } catch (Throwable e) {
            throw new RequestException(e);
        }
    }
View Full Code Here

Examples of org.apache.bsf.BSFManager

            ActionForm form,
            HttpServletRequest request,
            HttpServletResponse response)
             throws Exception {

        BSFManager bsfManager = new BSFManager();

        String scriptName = null;
        try {
            scriptName = parseScriptName(mapping.getParameter(), bsfManager);
        } catch (Exception ex) {
            LOG.error("Unable to parse " + mapping.getParameter(), ex);
            throw new Exception("Unable to parse " + mapping.getParameter());
        }
        if (scriptName == null) {
            LOG.error("No script specified in the parameter attribute");
            throw new Exception("No script specified");
        }

        if (LOG.isDebugEnabled()) {
            LOG.debug("Executing script: " + scriptName);
        }

        HttpSession session = request.getSession();
        ServletContext application = getServlet().getServletContext();

        Script script = loadScript(scriptName, application);

        bsfManager.declareBean("request", request,
                HttpServletRequest.class);

        bsfManager.declareBean("response", response,
                HttpServletResponse.class);

        if (session == null) {
            LOG.debug("HTTP session is null");
        } else {
            bsfManager.declareBean("session", session, HttpSession.class);
        }

        bsfManager.declareBean("application", application,
                ServletContext.class);

        bsfManager.declareBean("log", LOG, Log.class);
        StrutsInfo struts = new StrutsInfo(this, mapping, form,
                getResources(request));
        bsfManager.declareBean("struts", struts, StrutsInfo.class);

        for (int x = 0; x < filters.length; x++) {
            filters[x].apply(bsfManager);
        }

        bsfManager.exec(script.lang, script.file.getCanonicalPath(), 0, 0,
                script.string);

        ActionForward af = struts.getForward();
        return af;
    }
View Full Code Here

Examples of org.apache.bsf.BSFManager

    protected BSFManager bsfManager;

    public ScriptMediator(String scriptKey, String functionName) {
        this.scriptKey = scriptKey;
        this.functionName = functionName;
        bsfManager = new BSFManager();
    }
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.