本文整理汇总了Java中org.apache.bsf.BSFException类的典型用法代码示例。如果您正苦于以下问题:Java BSFException类的具体用法?Java BSFException怎么用?Java BSFException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BSFException类属于org.apache.bsf包,在下文中一共展示了BSFException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initialize
import org.apache.bsf.BSFException; //导入依赖的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: invokeBusinessLogic
import org.apache.bsf.BSFException; //导入依赖的package包/类
/**
* Invokes the service by calling the script function
*/
public void invokeBusinessLogic(MessageContext inMC, MessageContext outMC) throws AxisFault {
try {
log.debug("invoking script service");
outMC.setEnvelope(getSOAPFactory(inMC).getDefaultEnvelope());
BSFEngine engine = getBSFEngine(inMC);
OMElementConvertor convertor = (OMElementConvertor) inMC.getServiceContext().getProperty(CONVERTOR_PROP);
Parameter scriptFunctionParam = inMC.getAxisService().getParameter(FUNCTION_ATTR);
String scriptFunction = scriptFunctionParam == null ? DEFAULT_FUNCTION : (String) scriptFunctionParam.getValue();
ScriptMessageContext inScriptMC = new ScriptMessageContext(inMC, convertor);
ScriptMessageContext outScriptMC = new ScriptMessageContext(outMC, convertor);
Object[] args = new Object[] { inScriptMC, outScriptMC };
engine.call(null, scriptFunction, args);
} catch (BSFException e) {
throw AxisFault.makeFault(e);
}
}
示例3: addPetData
import org.apache.bsf.BSFException; //导入依赖的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");
}
}
示例4: parsePackages
import org.apache.bsf.BSFException; //导入依赖的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();
}
}
示例5: init
import org.apache.bsf.BSFException; //导入依赖的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: getResult
import org.apache.bsf.BSFException; //导入依赖的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;
}
示例7: eval
import org.apache.bsf.BSFException; //导入依赖的package包/类
/**
* Evaluate an expression.
*/
public Object eval(String source, int lineNo, int columnNo, Object script) throws BSFException {
try {
Class scriptClass = evalScripts.get(script);
if (scriptClass == null) {
scriptClass = loader.parseClass(script.toString(), source);
evalScripts.put(script, scriptClass);
} else {
LOG.fine("eval() - Using cached script...");
}
//can't cache the script because the context may be different.
//but don't bother loading parsing the class again
Script s = InvokerHelper.createScript(scriptClass, context);
return s.run();
} catch (Exception e) {
throw new BSFException(BSFException.REASON_EXECUTION_ERROR, "exception from Groovy: " + e, e);
}
}
示例8: exec
import org.apache.bsf.BSFException; //导入依赖的package包/类
/**
* Execute a script.
*/
public void exec(String source, int lineNo, int columnNo, Object script) throws BSFException {
try {
// shell.run(script.toString(), source, EMPTY_ARGS);
Class scriptClass = execScripts.get(script);
if (scriptClass == null) {
scriptClass = loader.parseClass(script.toString(), source);
execScripts.put(script, scriptClass);
} else {
LOG.fine("exec() - Using cached version of class...");
}
InvokerHelper.invokeMethod(scriptClass, "main", EMPTY_ARGS);
} catch (Exception e) {
LOG.log(Level.WARNING, "BSF trace", e);
throw new BSFException(BSFException.REASON_EXECUTION_ERROR, "exception from Groovy: " + e, e);
}
}
示例9: initialize
import org.apache.bsf.BSFException; //导入依赖的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));
}
}
示例10: initialize
import org.apache.bsf.BSFException; //导入依赖的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: runScripts
import org.apache.bsf.BSFException; //导入依赖的package包/类
protected void runScripts() {
if (_bsfManager == null) return;
synchronized(_bsfManager) {
for (int i=0; i<_scripts.size(); i++) {
Script script = _scripts.get(i);
if (script.isEnabled()) {
// if (_scriptManager != null) _scriptManager.scriptStarted(this, script);
try {
_bsfManager.exec(script.getLanguage(), _name, 0, 0, script.getScript());
} catch (BSFException bsfe) {
_logger.warning("Script exception: " + bsfe);
// if (_scriptManager != null) _scriptManager.scriptError(this, script, bsfe);
}
// if (_scriptManager != null) _scriptManager.scriptEnded(this, script);
}
}
}
}
示例12: executeScript
import org.apache.bsf.BSFException; //导入依赖的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.BSFException; //导入依赖的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.BSFException; //导入依赖的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: eval
import org.apache.bsf.BSFException; //导入依赖的package包/类
/** {@inheritDoc} */
@Override
public Object eval(String fileName, int lineNo, int colNo, Object expr)
throws BSFException {
if (expr == null) {
return null;
}
try {
Script jExpr = null;
if (expr instanceof File) {
jExpr = ScriptFactory.createScript((File) expr);
} else if (expr instanceof URL) {
jExpr = ScriptFactory.createScript((URL) expr);
} else {
jExpr = ScriptFactory.createScript((String) expr);
}
return jExpr.execute(jc);
} catch (Exception e) {
throw new BSFException(BSFException.REASON_OTHER_ERROR, e.getMessage(), e);
}
}