本文整理汇总了Java中org.apache.bsf.BSFManager类的典型用法代码示例。如果您正苦于以下问题:Java BSFManager类的具体用法?Java BSFManager怎么用?Java BSFManager使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BSFManager类属于org.apache.bsf包,在下文中一共展示了BSFManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initialize
import org.apache.bsf.BSFManager; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public void initialize(BSFManager mgr, String lang, Vector declaredBeans) throws BSFException {
super.initialize(mgr, lang, declaredBeans);
interpreter = BshUtil.getMasterInterpreter(null);
// declare the bsf manager for callbacks, etc.
try {
interpreter.set("bsf", mgr);
} catch (EvalError e) {
throw new BSFException("bsh internal error: "+e.toString());
}
for (int i=0; i<declaredBeans.size(); i++) {
BSFDeclaredBean bean = (BSFDeclaredBean)declaredBeans.get(i);
declareBean(bean);
}
}
示例2: addPetData
import org.apache.bsf.BSFManager; //导入依赖的package包/类
public void addPetData(BSFManager context, int petID, int levelStart, int levelEnd, Map<String, String> stats)
throws BSFException
{
L2PetData[] petData = new L2PetData[levelEnd - levelStart + 1];
int value = 0;
for (int level = levelStart; level <= levelEnd; level++)
{
petData[level - 1] = new L2PetData();
petData[level - 1].setPetID(petID);
petData[level - 1].setPetLevel(level);
context.declareBean("level", new Double(level), Double.TYPE);
for (String stat : stats.keySet())
{
value = ((Number)Expression.eval(context, "beanshell", stats.get(stat))).intValue();
petData[level - 1].setStat(stat, value);
}
context.undeclareBean("level");
}
}
示例3: 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();
}
}
示例4: parseScript
import org.apache.bsf.BSFManager; //导入依赖的package包/类
@Override
public void parseScript(Node questNode, BSFManager context)
{
if (DEBUG) System.out.println("Parsing Quest.");
String questID = attribute(questNode, "ID");
for (Node node = questNode.getFirstChild(); node != null; node = node.getNextSibling()) {
if (isNodeName(node, "DROPLIST"))
{
parseQuestDropList(node.cloneNode(true), questID);
}
else if (isNodeName(node, "DIALOG WINDOWS"))
{
//parseDialogWindows(node.cloneNode(true));
}
else if (isNodeName(node, "INITIATOR"))
{
//parseInitiator(node.cloneNode(true));
}
else if (isNodeName(node, "STATE"))
{
//parseState(node.cloneNode(true));
}
}
}
示例5: init
import org.apache.bsf.BSFManager; //导入依赖的package包/类
/**
* Initialize the engine for scripts of quests, luxury shops and blacksmith
*/
public static void init()
{
try
{
// Initialize the engine for loading Jython scripts
_bsf = new BSFManager();
// Execution of all the scripts placed in data/jscript
// inside the DataPack directory
String dataPackDirForwardSlashes = Config.DATAPACK_ROOT.getPath().replaceAll("\\\\","/");
String loadingScript =
"import sys;"
+ "sys.path.insert(0,'" + dataPackDirForwardSlashes + "');"
+ "import data";
_bsf.exec("jython", "quest", 0, 0, loadingScript);
}
catch (BSFException e)
{
e.printStackTrace();
}
}
示例6: 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;
}
示例7: getResult
import org.apache.bsf.BSFManager; //导入依赖的package包/类
@Override
public AssertionResult getResult(SampleResult response) {
AssertionResult result = new AssertionResult(getName());
BSFManager mgr =null;
try {
mgr = getManager();
mgr.declareBean("SampleResult", response, SampleResult.class);
mgr.declareBean("AssertionResult", result, AssertionResult.class);
processFileOrScript(mgr);
result.setError(false);
} catch (BSFException e) {
log.warn("Problem in BSF script "+e);
result.setFailure(true);
result.setError(true);
result.setFailureMessage(e.toString());
} finally {
if(mgr != null) {
mgr.terminate();
}
}
return result;
}
示例8: initialize
import org.apache.bsf.BSFManager; //导入依赖的package包/类
/**
* 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<Object, Class>();
evalScripts = new HashMap<Object, Class>();
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));
}
}
示例9: configureBSF
import org.apache.bsf.BSFManager; //导入依赖的package包/类
private void configureBSF() {
if (log.isDebugEnabled())
log.debug("Adding Beanshell to BSF");
String[] beanshellExtensions = {"bsh"};
BSFManager.registerScriptingEngine("beanshell", "bsh.util.BeanShellBSFEngine", beanshellExtensions);
if (log.isDebugEnabled())
log.debug("Adding Groovy to BSF");
String[] groovyExtensions = {"groovy", "gy"};
BSFManager.registerScriptingEngine("groovy", "org.codehaus.groovy.bsf.GroovyEngine", groovyExtensions);
if (log.isDebugEnabled())
log.debug("Adding Ruby to BSF");
String[] rubyExtensions = {"ruby", "rb"};
BSFManager.registerScriptingEngine("ruby", "org.jruby.embed.bsf.JRubyEngine", rubyExtensions);
}
示例10: initialize
import org.apache.bsf.BSFManager; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public void initialize(BSFManager mgr, String lang, Vector declaredBeans) throws BSFException {
super.initialize(mgr, lang, declaredBeans);
interpreter = BshUtil.getMasterInterpreter(null);
// declare the bsf manager for callbacks, etc.
try {
interpreter.set("bsf", mgr);
} catch (EvalError e) {
throw new BSFException("bsh internal error: "+e.toString());
}
for(int i=0; i<declaredBeans.size(); i++) {
BSFDeclaredBean bean = (BSFDeclaredBean)declaredBeans.get(i);
declareBean(bean);
}
}
示例11: supportsLanguage
import org.apache.bsf.BSFManager; //导入依赖的package包/类
/**
* Check if bsf supports the language.
* @return true if bsf can create an engine for this language.
*/
@Override
public boolean supportsLanguage() {
Map<String, String> table =
ReflectUtil.getField(new BSFManager(), "registeredEngines");
String engineClassName = table.get(getLanguage());
if (engineClassName == null) {
getProject().log(
"This is no BSF engine class for language '"
+ getLanguage() + "'",
Project.MSG_VERBOSE);
return false;
}
try {
getScriptClassLoader().loadClass(engineClassName);
return true;
} catch (Throwable ex) {
getProject().log(
"unable to create BSF engine class for language '"
+ getLanguage() + "'",
ex,
Project.MSG_VERBOSE);
return false;
}
}
示例12: executeScript
import org.apache.bsf.BSFManager; //导入依赖的package包/类
/**
* Do the work.
*
* @param execName the name that will be passed to BSF for this script execution.
* @exception BuildException if something goes wrong executing the script.
*/
@Override
public void executeScript(String execName) throws BuildException {
checkLanguage();
ClassLoader origLoader = replaceContextLoader();
try {
BSFManager m = createManager();
declareBeans(m);
// execute the script
if (engine == null) {
m.exec(getLanguage(), execName, 0, 0, getScript());
} else {
engine.exec(execName, 0, 0, getScript());
}
} catch (BSFException be) {
throw getBuildException(be);
} finally {
restoreContextLoader(origLoader);
}
}
示例13: 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);
}
}
示例14: initEngine
import org.apache.bsf.BSFManager; //导入依赖的package包/类
protected void initEngine() {
try {
String scriptLanguage = BSFManager.getLangFromFilename(scriptName);
BSFManager bsfManager = new BSFManager();
bsfManager.setClassLoader(BSFManager.class.getClassLoader());
// bsfManager.declareBean("_AxisService", axisService,
// AxisService.class);
BSFEngine bsfEngine = bsfManager
.loadScriptingEngine(scriptLanguage);
Object scriptSrc = readScript();
bsfEngine.exec(scriptName, 0, 0, scriptSrc);
} catch (BSFException e) {
throw new RuntimeException(e);
}
}
示例15: sampleOccurred
import org.apache.bsf.BSFManager; //导入依赖的package包/类
@Override
public void sampleOccurred(SampleEvent event) {
BSFManager mgr =null;
try {
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);
} catch (BSFException e) {
log.warn("Problem in BSF script "+e);
} finally {
if (mgr != null) {
mgr.terminate();
}
}
}