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); } }
public PreparsedScript(final String source, final ClassLoader classLoader) throws EvalError { final ClassManagerImpl classManager = new ClassManagerImpl(); classManager.setClassLoader(classLoader); final NameSpace nameSpace = new NameSpace("global", classManager); _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", Reflect.ZERO_TYPES, false); } catch (final UtilEvalError e) { throw new IllegalStateException(e); } }
false, new NameSpace(master, "global"), null, null); } else { interpreter = new Interpreter();
namespace = new NameSpace(namespace, bcm, "global");
private void initRootSystemObject() { BshClassManager bcm = getClassManager(); // bsh setu("bsh", new NameSpace(null, bcm, "Bsh Object" ).getThis( this ) ); // bsh.system setu( "bsh.system", SYSTEM_OBJECT); setu( "bsh.shared", SYSTEM_OBJECT); // alias // bsh.help This helpText = new NameSpace(null, bcm, "Bsh Command Help Text" ).getThis( this ); setu( "bsh.help", helpText ); // bsh.cwd setu( "bsh.cwd", System.getProperty("user.dir") ); // bsh.interactive setu( "bsh.interactive", interactive ? Primitive.TRUE : Primitive.FALSE ); // bsh.evalOnly setu( "bsh.evalOnly", Primitive.FALSE ); }
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); }
private void initRootSystemObject() { BshClassManager bcm = getClassManager(); // bsh setu("bsh", new NameSpace( bcm, "Bsh Object" ).getThis( this ) ); setu( "bsh.system", SYSTEM_OBJECT); setu( "bsh.shared", SYSTEM_OBJECT); // alias // bsh.help This helpText = new NameSpace(bcm, "Bsh Command Help Text" ).getThis( this ); setu( "bsh.help", helpText ); // bsh.cwd try { setu( "bsh.cwd", System.getProperty("user.dir") ); } catch ( SecurityException e ) { // applets can't see sys props setu( "bsh.cwd", "." ); } // bsh.interactive setu( "bsh.interactive", new Primitive(interactive) ); // bsh.evalOnly setu( "bsh.evalOnly", new Primitive(evalOnly) ); }
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; }
globalNameSpace = new NameSpace( bcm, "global"); initRootSystemObject(); } else {
public Object constructWithInterfaceBody( BSHAllocationExpression node, Class type, Object[] args, BSHBlock body ) throws EvalError { NameSpace namespace = callstack.top(); NameSpace local = new NameSpace(namespace, "AnonymousBlock"); callstack.push(local); evalBlock(body, true); callstack.pop(); // statical import fields from the interface so that code inside // can refer to the fields directly (e.g. HEIGHT) local.importStatic( type ); return local.getThis(interpreter).getInterface( type ); }
private Object constructWithInterfaceBody( Class type, Object[] args, BSHBlock body, CallStack callstack, Interpreter interpreter ) throws EvalError { NameSpace namespace = callstack.top(); NameSpace local = new NameSpace(namespace, "AnonymousBlock"); callstack.push(local); body.eval( callstack, interpreter, true/*overrideNamespace*/ ); callstack.pop(); // statical import fields from the interface so that code inside // can refer to the fields directly (e.g. HEIGHT) local.importStatic( type ); return local.getThis(interpreter).getInterface( type ); }
/** This is the invocation handler for the dynamic proxy. <p> Notes: Inner class for the invocation handler seems to shield this unavailable interface from JDK1.2 VM... I don't understand this. JThis works just fine even if those classes aren't there (doesn't it?) This class shouldn't be loaded if an XThis isn't instantiated in NameSpace.java, should it? */ class Handler implements InvocationHandler, java.io.Serializable { public Object invoke( Object proxy, Method method, Object[] args ) throws Throwable { try { return invokeImpl( proxy, method, args ); } catch ( TargetError te ) { // Unwrap target exception. If the interface declares that // it throws the ex it will be delivered. If not it will be // wrapped in an UndeclaredThrowable // This isn't simple because unwrapping this loses all context info. // So rewrap is better than unwrap. - fschmidt Throwable t = te.getTarget(); Class<? extends Throwable> c = t.getClass(); String msg = t.getMessage(); try {
NameSpace ns = new NameSpace(namespace,namespace.getName()+" clone"); try { for( String varName : namespace.getVariableNames() ) {
NameSpace consArgsNameSpace = new NameSpace(classStaticThis.getNameSpace(), "consArgs"); String[] consArgNames = constructor.getParameterNames(); Class<?>[] consArgTypes = constructor.getParameterTypes();
NameSpace classStaticNameSpace = new NameSpace(enclosingNameSpace, className); classStaticNameSpace.isClass = true;
instanceNameSpace.setParent(CONTEXT_NAMESPACE.get()); } else { instanceNameSpace = new NameSpace(classStaticThis.getNameSpace(), className); // todo: old code
NameSpace consArgsNameSpace = new NameSpace(classStaticThis.getNameSpace(), "consArgs"); String[] consArgNames = constructor.getParameterNames(); Class[] consArgTypes = constructor.getParameterTypes();
else localNameSpace = new NameSpace( declaringNameSpace, name ); localNameSpace.isMethod = true;
NameSpace classStaticNameSpace = new NameSpace(enclosingNameSpace, className); classStaticNameSpace.isClass = true;
else localNameSpace = new NameSpace( declaringNameSpace, name ); localNameSpace.isMethod = true;