Package org.apache.bsf

Examples of org.apache.bsf.BSFManager


   *
   * @return the interpreter or null, if there was an error.
   */
  protected BSFManager createInterpreter() throws BSFException
  {
    final BSFManager interpreter = new BSFManager();
    initializeInterpreter(interpreter);
    return interpreter;
  }
View Full Code Here


  /**
   * {@inheritDoc}
   */
  @Override
  public Object evaluate(IScript scriptable, Map<String, Object> context) {
    BSFManager enginesManager = new BSFManager();
    if (context != null) {
      enginesManager.registerBean(IScript.CONTEXT, context);
      enginesManager.registerBean(IScript.SCRIPTED_OBJECT, scriptable
          .getScriptedObject());
    }
    try {
      return enginesManager.eval(scriptable.getLanguage(), null, 0, 0,
          scriptable.getScript());
    } catch (BSFException ex) {
      throw new ScriptException(ex);
    }
  }
View Full Code Here

  /**
   * {@inheritDoc}
   */
  @Override
  public void execute(IScript scriptable, Map<String, Object> context) {
    BSFManager enginesManager = new BSFManager();
    if (context != null) {
      enginesManager.registerBean(IScript.CONTEXT, scriptable);
      enginesManager.registerBean(IScript.SCRIPTED_OBJECT, scriptable
          .getScriptedObject());
    }
    try {
      enginesManager.exec(scriptable.getLanguage(), null, 0, 0, scriptable
          .getScript());
    } catch (BSFException ex) {
      throw new ScriptException(ex);
    }
  }
View Full Code Here

        BSFManager.registerScriptingEngine("ruby", "org.jruby.javasupport.bsf.JRubyEngine", new String[] { "rb" });

        /*
         * Now we create a new BSFManager.
         */
        new BSFExample(new BSFManager());
    }
View Full Code Here

    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

     * @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

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

    {
        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

    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

     */
    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

TOP

Related Classes of org.apache.bsf.BSFManager

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.