本文整理汇总了Java中org.apache.bsf.BSFManager.eval方法的典型用法代码示例。如果您正苦于以下问题:Java BSFManager.eval方法的具体用法?Java BSFManager.eval怎么用?Java BSFManager.eval使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.bsf.BSFManager
的用法示例。
在下文中一共展示了BSFManager.eval方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parsePackages
import org.apache.bsf.BSFManager; //导入方法依赖的package包/类
public void parsePackages()
{
BSFManager context = new BSFManager();
try
{
context.eval("beanshell", "core", 0, 0, "double log1p(double d) { return Math.log1p(d); }");
context.eval("beanshell", "core", 0, 0,
"double pow(double d, double p) { return Math.pow(d,p); }");
for (ScriptDocument script : _scripts)
{
parseScript(script, context);
//System.out.println(script.getName());
}
}
catch (BSFException e)
{
e.printStackTrace();
}
}
示例2: main
import org.apache.bsf.BSFManager; //导入方法依赖的package包/类
public static void main(String[] args) {
BSFManager manager = new BSFManager();
// register scripting language
String[] fntypes = { ".py" };
BSFManager.registerScriptingEngine("jython",
"org.apache.bsf.engines.jython.JythonEngine", fntypes);
try {
// try an expression
Object r = manager.eval("jython", "testString", 0, 0, "22.0/7");
System.out.println("Result type is " + r.getClass().getName());
System.out.println("Result value is " + r);
} catch (Exception ex) {
System.err.println(ex.toString());
}
System.out.println("Scripting demo done.");
return;
}
示例3: evaluateScript
import org.apache.bsf.BSFManager; //导入方法依赖的package包/类
/**
* Evaluate the script.
*
* @param execName the name that will be passed to BSF for this script execution.
* @return the result of the evaluation
* @exception BuildException if something goes wrong executing the script.
*/
@Override
public Object evaluateScript(String execName) throws BuildException {
checkLanguage();
ClassLoader origLoader = replaceContextLoader();
try {
BSFManager m = createManager();
declareBeans(m);
// execute the script
if (engine == null) {
return m.eval(getLanguage(), execName, 0, 0, getScript());
}
return engine.eval(execName, 0, 0, getScript());
} catch (BSFException be) {
throw getBuildException(be);
} finally {
restoreContextLoader(origLoader);
}
}
示例4: eval
import org.apache.bsf.BSFManager; //导入方法依赖的package包/类
public static Object eval(BSFManager context, String lang, String code)
{
try
{
return context.eval(lang, "eval", 0, 0, code);
}
catch (Exception e)
{
e.printStackTrace();
return null;
}
}
示例5: testSimpleIntegration
import org.apache.bsf.BSFManager; //导入方法依赖的package包/类
@Test
public void testSimpleIntegration() throws BSFException {
// tag::bsf_simple[]
String myScript = "println('Hello World')\n return [1, 2, 3]";
BSFManager manager = new BSFManager();
List answer = (List) manager.eval("groovy", "myScript.groovy", 0, 0, myScript);
assertEquals(3, answer.size());
// end::bsf_simple[]
}
示例6: testVariablePassing
import org.apache.bsf.BSFManager; //导入方法依赖的package包/类
@Test
public void testVariablePassing() throws BSFException {
// tag::bsf_variable_passing[]
BSFManager manager = new BSFManager();
manager.declareBean("xyz", 4, Integer.class);
Object answer = manager.eval("groovy", "test.groovy", 0, 0, "xyz + 1");
assertEquals(5, answer);
// end::bsf_variable_passing[]
}
示例7: runGroovy
import org.apache.bsf.BSFManager; //导入方法依赖的package包/类
/**
* Runs a groovy script with a list of arguments
* Each argument is passed to groovy as argX(arg0, arg1, arg2 etc..)
*
* @param script script to execute
* @param args arguments to pass to the script
* @return list of results
* @throws Exception 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;
}