本文整理了Java中bsh.Interpreter.setNameSpace()
方法的一些代码示例,展示了Interpreter.setNameSpace()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Interpreter.setNameSpace()
方法的具体详情如下:
包路径:bsh.Interpreter
类名称:Interpreter
方法名:setNameSpace
[英]Set the global namespace for this interpreter.
Note: This is here for completeness. If you're using this a lot it may be an indication that you are doing more work than you have to. For example, caching the interpreter instance rather than the namespace should not add a significant overhead. No state other than the debug status is stored in the interpreter.
All features of the namespace can also be accessed using the interpreter via eval() and the script variable 'this.namespace' (or global.namespace as necessary).
[中]设置此解释器的全局命名空间。
注意:这是为了完整性。如果你经常使用这个,这可能表明你做的工作比你必须做的更多。例如,缓存解释器实例而不是命名空间不应该增加大量开销。解释器中不存储除调试状态以外的任何状态。
还可以使用解释器通过eval()和脚本变量“this”访问命名空间的所有功能。namespace'(或根据需要使用global.namespace)。
代码示例来源:origin: jitlogic/zorka
protected Interpreter getInterpreter() {
if (interpreter == null) {
this.interpreter = new bsh.Interpreter();
interpreter.setNameSpace(null); // should always be set by context
}
return interpreter;
}
代码示例来源:origin: beanshell/beanshell
protected Interpreter getInterpreter() {
if (interpreter == null) {
this.interpreter = new Interpreter();
interpreter.setNameSpace(null); // should always be set by context
}
return interpreter;
}
代码示例来源:origin: org.zkoss.zk/zk
public void destroy() {
getOwner().removeAttribute(VAR_NSW);
//bug 1814819 ,clear variable, dennis
try {
_bshns.clear();
_ip.setNameSpace(null);
} catch (Throwable t) { //silently ignore (in case of upgrading to new bsh)
}
_ip = null;
_bshns = null;
super.destroy();
}
代码示例来源:origin: beanshell/beanshell
this.setNameSpace(namespace);
this.setConsole(console);
代码示例来源:origin: org.zkoss.zk/zk
public void init(Page owner, String zslang) {
super.init(owner, zslang);
_ip = new bsh.Interpreter();
_ip.setClassLoader(Classes.getContextClassLoader(BSHInterpreter.class));
_bshns = new GlobalNS(_ip.getClassManager(), "global");
_ip.setNameSpace(_bshns);
}
代码示例来源:origin: jpos/jPOS
BSHLogListener.ScriptInfo info = getScriptInfo(sources[i]);
NameSpace ns = info!=null ?info.getNameSpace():null;
if(ns!=null) bsh.setNameSpace(ns);
bsh.set("event", ret);
bsh.set("cfg", cfg);
代码示例来源:origin: beanshell/beanshell
private Object evalSource(Object source, ScriptContext scriptContext) throws ScriptException {
try ( Interpreter bsh = getInterpreter() ) {
NameSpace contextNameSpace = getEngineNameSpace(scriptContext);
bsh.setNameSpace(contextNameSpace);
bsh.setOut(toPrintStream(scriptContext.getWriter()));
bsh.setErr(toPrintStream(scriptContext.getErrorWriter()));
if (source instanceof Reader) {
return bsh.eval((Reader) source);
} else {
return bsh.eval((String) source);
}
} catch (ParseException e) {
// explicit parsing error
throw new ScriptException(e.toString(), e.getErrorSourceFile(), e.getErrorLineNumber());
} catch (TargetError e) {
// The script threw an application level exception
ScriptException se = new ScriptException(e.toString(), e.getErrorSourceFile(), e.getErrorLineNumber());
se.initCause(e.getTarget());
throw se;
} catch (EvalError e) {
// The script couldn't be evaluated properly
throw new ScriptException(e.toString(), e.getErrorSourceFile(), e.getErrorLineNumber());
} catch (IOException e) {
throw new ScriptException(e.toString());
}
}
代码示例来源:origin: jitlogic/zorka
private Object evalSource(Object source, ScriptContext scriptContext) throws ScriptException {
bsh.NameSpace contextNameSpace = getEngineNameSpace(scriptContext);
Interpreter bsh = getInterpreter();
bsh.setNameSpace(contextNameSpace);
bsh.setOut(toPrintStream(scriptContext.getWriter()));
bsh.setErr(toPrintStream(scriptContext.getErrorWriter()));
try {
if (source instanceof Reader) {
return bsh.eval((Reader) source);
} else {
return bsh.eval((String) source);
}
//} catch (ParseException e) {
// explicit parsing error TODO how to handle parse exception ?
//throw new ScriptException(e.toString());
//e.getErrorSourceFile(), e.getErrorLineNumber());
} catch (TargetError e) {
// The script threw an application level exception
// set it as the cause ?
ScriptException se = new ScriptException(e.toString(), e.getErrorSourceFile(), e.getErrorLineNumber());
se.initCause(e.getTarget());
throw se;
} catch (EvalError e) {
// The script couldn't be evaluated properly
throw new ScriptException(e.toString(), e.getErrorSourceFile(), e.getErrorLineNumber());
} catch (InterpreterError e) {
// The interpreter had a fatal problem
throw new ScriptException(e.toString());
}
}
内容来源于网络,如有侵权,请联系作者删除!