org.apache.bsf.BSFDeclaredBean Java Examples

The following examples show how to use org.apache.bsf.BSFDeclaredBean. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BeanShellBSFEngine.java    From beanshell with Apache License 2.0 6 votes vote down vote up
public void initialize ( BSFManager mgr, String lang, Vector declaredBeans)
throws BSFException
{
    super.initialize( mgr, lang, declaredBeans );

    interpreter = new Interpreter();

    // declare the bsf manager for callbacks, etc.
    try {
        interpreter.set( "bsf", mgr );
    } catch ( EvalError e ) {
        throw new BSFException(BSFException.REASON_OTHER_ERROR, "bsh internal error: "+e, e);
    }

    for(int i=0; i<declaredBeans.size(); i++)
    {
        BSFDeclaredBean bean = (BSFDeclaredBean)declaredBeans.get(i);
        declareBean( bean );
    }
}
 
Example #2
Source File: JythonEngine.java    From commons-bsf with Apache License 2.0 6 votes vote down vote up
/**
  * Initialize the engine.
  */
 public void initialize (BSFManager mgr, String lang,
					  Vector declaredBeans) throws BSFException {
super.initialize (mgr, lang, declaredBeans);

// create an interpreter
interp = new BSFPythonInterpreter ();

   // ensure that output and error streams are re-directed correctly
   interp.setOut(System.out);
   interp.setErr(System.err);
   
// register the mgr with object name "bsf"
interp.set ("bsf", new BSFFunctions (mgr, this));

   // Declare all declared beans to the interpreter
int size = declaredBeans.size ();
for (int i = 0; i < size; i++) {
  declareBean ((BSFDeclaredBean) declaredBeans.elementAt (i));
}
 }
 
Example #3
Source File: CachingGroovyEngine.java    From groovy with Apache License 2.0 6 votes vote down vote up
/**
 * Initialize the engine.
 */
public void initialize(final BSFManager mgr, String lang, Vector declaredBeans) throws BSFException {
    super.initialize(mgr, lang, declaredBeans);
    ClassLoader parent = mgr.getClassLoader();
    if (parent == null)
        parent = GroovyShell.class.getClassLoader();
    setLoader(mgr, parent);
    execScripts = new HashMap<>();
    evalScripts = new HashMap<>();
    context = shell.getContext();
    // create a shell
    // register the mgr with object name "bsf"
    context.setVariable("bsf", new BSFFunctions(mgr, this));
    int size = declaredBeans.size();
    for (int i = 0; i < size; i++) {
        declareBean((BSFDeclaredBean) declaredBeans.elementAt(i));
    }
}
 
Example #4
Source File: JavaScriptEngine.java    From commons-bsf with Apache License 2.0 6 votes vote down vote up
/**
 * Initialize the engine. 
 * Put the manager into the context-manager
 * map hashtable too.
 */
public void initialize(BSFManager mgr, String lang, Vector declaredBeans)
    throws BSFException {
    
    super.initialize(mgr, lang, declaredBeans);

    // Initialize context and global scope object
    try {
        Context cx = Context.enter();
        global = new ImporterTopLevel(cx);
        Scriptable bsf = Context.toObject(new BSFFunctions(mgr, this), global);
        global.put("bsf", global, bsf);

        for(Iterator it = declaredBeans.iterator(); it.hasNext();) {
            declareBean((BSFDeclaredBean) it.next());
        }
    } 
    catch (Throwable t) {

    } 
    finally {
        Context.exit();
    }
}
 
Example #5
Source File: JaclEngine.java    From commons-bsf with Apache License 2.0 6 votes vote down vote up
/**
 * Initialize the engine.
 */
public void initialize (BSFManager mgr, String lang,
            Vector declaredBeans) throws BSFException {
  super.initialize (mgr, lang, declaredBeans);

  // create interpreter
  interp = new Interp();

  // register the extension that user's can use to get at objects
  // registered by the app
  interp.createCommand ("bsf", new BSFCommand (mgr, this));

  // Make java functions be available to Jacl
      try {
      interp.eval("jaclloadjava");
  } catch (TclException e) {
      throw new BSFException (BSFException.REASON_OTHER_ERROR,
                  "error while loading java package: " +
                  interp.getResult (), e);
  }

  int size = declaredBeans.size ();
  for (int i = 0; i < size; i++) {
    declareBean ((BSFDeclaredBean) declaredBeans.elementAt (i));
  }
}
 
Example #6
Source File: SimpleMethodBsfEngine.java    From scipio-erp with Apache License 2.0 5 votes vote down vote up
@Override
public void initialize(BSFManager mgr, String lang, @SuppressWarnings("rawtypes") Vector declaredBeans) throws BSFException {
    super.initialize(mgr, lang, declaredBeans);
    // declare the bsf manager for callbacks, etc.
    context.put("bsf", mgr);
    for (int i = 0; i < declaredBeans.size(); i++) {
        BSFDeclaredBean bean = (BSFDeclaredBean) declaredBeans.get(i);
        declareBean(bean);
    }
}
 
Example #7
Source File: BeanShellBSFEngine.java    From beanshell with Apache License 2.0 5 votes vote down vote up
public void declareBean (BSFDeclaredBean bean)
    throws BSFException
{
    try {
        interpreter.set( bean.name, bean.bean);
    } catch ( EvalError e ) {
        throw new BSFException(BSFException.REASON_OTHER_ERROR, "error declaring bean: "+bean.name
        +" : "+e, e);
    }
}
 
Example #8
Source File: BeanShellBSFEngine.java    From beanshell with Apache License 2.0 5 votes vote down vote up
public void undeclareBean (BSFDeclaredBean bean)
    throws BSFException
{
    try {
        interpreter.unset( bean.name );
    } catch ( EvalError e ) {
        throw new BSFException(BSFException.REASON_OTHER_ERROR, "bsh internal error: "+e, e);
    }
}
 
Example #9
Source File: GroovyEngine.java    From groovy with Apache License 2.0 5 votes vote down vote up
/**
 * Initialize the engine.
 */
public void initialize(BSFManager mgr, String lang, Vector declaredBeans) throws BSFException {
    super.initialize(mgr, lang, declaredBeans);

    // create a shell
    shell = new GroovyShell(mgr.getClassLoader());

    // register the mgr with object name "bsf"
    shell.setVariable("bsf", new BSFFunctions(mgr, this));

    int size = declaredBeans.size();
    for (int i = 0; i < size; i++) {
        declareBean((BSFDeclaredBean) declaredBeans.elementAt(i));
    }
}
 
Example #10
Source File: XSLTEngine.java    From commons-bsf with Apache License 2.0 5 votes vote down vote up
/**
 * Undeclare a bean by setting he parameter represeting it to null
 */
public void undeclareBean (BSFDeclaredBean bean) throws BSFException {
    // Cannot clear only one parameter in Xalan 2, so we set it to null
    if ((transformer.getParameter (bean.name)) != null) {
        transformer.setParameter (bean.name, null);
    }
}
 
Example #11
Source File: JavaScriptEngine.java    From commons-bsf with Apache License 2.0 5 votes vote down vote up
public void declareBean(BSFDeclaredBean bean) throws BSFException {
    if ((bean.bean instanceof Number) ||
        (bean.bean instanceof String) ||
        (bean.bean instanceof Boolean)) {
        global.put(bean.name, global, bean.bean);
    } 
    else {
        // Must wrap non-scriptable objects before presenting to Rhino
        Scriptable wrapped = Context.toObject(bean.bean, global);
        global.put(bean.name, global, wrapped);
    }
}
 
Example #12
Source File: JythonEngine.java    From commons-bsf with Apache License 2.0 4 votes vote down vote up
/**
  * Declare a bean
  */
 public void declareBean (BSFDeclaredBean bean) throws BSFException {
interp.set (bean.name, bean.bean);
 }
 
Example #13
Source File: BSFEngineImpl.java    From commons-bsf with Apache License 2.0 4 votes vote down vote up
public void undeclareBean(BSFDeclaredBean bean) throws BSFException {
    throw new BSFException(BSFException.REASON_UNSUPPORTED_FEATURE,
                           "language " + lang + 
                           " does not support undeclareBean(...).");
}
 
Example #14
Source File: JythonEngine.java    From commons-bsf with Apache License 2.0 4 votes vote down vote up
/**
  * Undeclare a previously declared bean.
  */
 public void undeclareBean (BSFDeclaredBean bean) throws BSFException {
interp.set (bean.name, null);
 }
 
Example #15
Source File: JavaScriptEngine.java    From commons-bsf with Apache License 2.0 4 votes vote down vote up
public void undeclareBean(BSFDeclaredBean bean) throws BSFException {
    global.delete(bean.name);
}
 
Example #16
Source File: BSFEngineImpl.java    From commons-bsf with Apache License 2.0 4 votes vote down vote up
public void declareBean(BSFDeclaredBean bean) throws BSFException {
    throw new BSFException(BSFException.REASON_UNSUPPORTED_FEATURE,
                           "language " + lang + 
                           " does not support declareBean(...).");
}
 
Example #17
Source File: SimpleMethodBsfEngine.java    From scipio-erp with Apache License 2.0 4 votes vote down vote up
@Override
public void declareBean(BSFDeclaredBean bean) throws BSFException {
    context.put(bean.name, bean.bean);
}
 
Example #18
Source File: JaclEngine.java    From commons-bsf with Apache License 2.0 4 votes vote down vote up
/**
 * Undeclare a previously declared bean.
 */
public void undeclareBean (BSFDeclaredBean bean) throws BSFException {
  eval ("<undeclare bean>", 0, 0, "set " + bean.name + " \"\"");
}
 
Example #19
Source File: JaclEngine.java    From commons-bsf with Apache License 2.0 4 votes vote down vote up
/**
 * Declare a bean
 */
public void declareBean (BSFDeclaredBean bean) throws BSFException {
  String expr = "set " + bean.name + " [bsf lookupBean \"" + bean.name +
 "\"]";
  eval ("<declare bean>", 0, 0, expr);
}
 
Example #20
Source File: XSLTEngine.java    From commons-bsf with Apache License 2.0 4 votes vote down vote up
/**
 * Declare a bean by setting it as a parameter
 */
public void declareBean (BSFDeclaredBean bean) throws BSFException {
    transformer.setParameter (bean.name, new XObject (bean.bean));
}
 
Example #21
Source File: GroovyEngine.java    From groovy with Apache License 2.0 4 votes vote down vote up
/**
 * Undeclare a previously declared bean.
 */
public void undeclareBean(BSFDeclaredBean bean) throws BSFException {
    shell.setVariable(bean.name, null);
}
 
Example #22
Source File: GroovyEngine.java    From groovy with Apache License 2.0 4 votes vote down vote up
/**
 * Declare a bean
 */
public void declareBean(BSFDeclaredBean bean) throws BSFException {
    shell.setVariable(bean.name, bean.bean);
}
 
Example #23
Source File: SimpleMethodBsfEngine.java    From scipio-erp with Apache License 2.0 4 votes vote down vote up
@Override
public void undeclareBean(BSFDeclaredBean bean) throws BSFException {
    context.remove(bean.name);
}
 
Example #24
Source File: JEXLEngine.java    From commons-bsf with Apache License 2.0 3 votes vote down vote up
/**
 * Initialize the JEXL engine by creating a JexlContext and populating it
 * with the declared beans.
 *
 * @param mgr The {@link BSFManager}.
 * @param lang The language.
 * @param declaredBeans The vector of the initially declared beans.
 *
 * @throws BSFException For any exception that occurs while trying to
 *                      initialize the engine.
 */
public void initialize(BSFManager mgr, String lang, Vector declaredBeans)
        throws BSFException {
    super.initialize(mgr, lang, declaredBeans);
    jc = JexlHelper.createContext();
    for (int i = 0; i < declaredBeans.size(); i++) {
        BSFDeclaredBean bean = (BSFDeclaredBean) declaredBeans.elementAt(i);
        jc.getVars().put(bean.name, bean.bean);
    }
}
 
Example #25
Source File: JEXLEngine.java    From commons-bsf with Apache License 2.0 2 votes vote down vote up
/**
 * Adds this bean to the backing JexlContext.
 *
 * @param bean The {@link BSFDeclaredBean} to be added to the backing
 *             context.
 *
 * @throws BSFException For any exception that occurs while trying to
 *                      declare the bean.
 */
public void declareBean(BSFDeclaredBean bean) throws BSFException {
    jc.getVars().put(bean.name, bean.bean);
}
 
Example #26
Source File: JEXLEngine.java    From commons-bsf with Apache License 2.0 2 votes vote down vote up
/**
 * Removes this bean from the backing JexlContext.
 *
 * @param bean The {@link BSFDeclaredBean} to be removed from the backing
 *             context.
 *
 * @throws BSFException For any exception that occurs while trying to
 *                      undeclare the bean.
 */
public void undeclareBean(BSFDeclaredBean bean) throws BSFException {
    jc.getVars().remove(bean.name);
}
 
Example #27
Source File: NetRexxEngine.java    From commons-bsf with Apache License 2.0 votes vote down vote up
public void undeclareBean (BSFDeclaredBean bean) throws BSFException {} 
Example #28
Source File: NetRexxEngine.java    From commons-bsf with Apache License 2.0 votes vote down vote up
public void declareBean (BSFDeclaredBean bean) throws BSFException {}