/** Bind a This reference to a parent's namespace with the specified declaring interpreter. Also re-init the callstack. It's necessary to bind a This reference before it can be used after deserialization. This is used by the bsh load() command. <p> This is a static utility method because it's used by a bsh command bind() and the interpreter doesn't currently allow access to direct methods of This objects (small hack) */ public static void bind( This ths, NameSpace namespace, Interpreter declaringInterpreter ) { ths.namespace.setParent( namespace ); ths.declaringInterpreter = declaringInterpreter; }
/** Bind a This reference to a parent's namespace with the specified declaring interpreter. Also re-init the callstack. It's necessary to bind a This reference before it can be used after deserialization. This is used by the bsh load() command. <p> This is a static utility method because it's used by a bsh command bind() and the interpreter doesn't currently allow access to direct methods of This objects (small hack) */ public static void bind( This ths, NameSpace namespace, Interpreter declaringInterpreter ) { ths.namespace.setParent( namespace ); ths.declaringInterpreter = declaringInterpreter; }
/** Used for serialization. */ public void prune() { this.getClassManager(); this.setParent(null); }
/** * Change the parent of the class instance namespace. * This is currently used for inner class support. * Note: This method will likely be removed in the future. */ // This could be static public void setInstanceNameSpaceParent(Object instance, String className, NameSpace parent) { This ithis = ClassGeneratorUtil.getClassInstanceThis(instance, className); ithis.getNameSpace().setParent(parent); }
/** Used for serialization */ public void prune() { // Cut off from parent, we must have our own class manager. // Can't do this in the run() command (needs to resolve stuff) // Should we do it by default when we create a namespace will no // parent of class manager? if ( this.classManager == null ) // XXX if we keep the createClassManager in getClassManager then we can axe // this? setClassManager( BshClassManager.createClassManager( null/*interp*/ ) ); setParent( null ); }
public NameSpace( NameSpace parent, BshClassManager classManager, String name ) { // We might want to do this here rather than explicitly in Interpreter // for global (see also prune()) //if ( classManager == null && (parent == null ) ) // create our own class manager? setName(name); setParent(parent); setClassManager( classManager ); // Register for notification of classloader change if ( classManager != null ) classManager.addListener(this); }
/** Instantiates a new name space. * @param parent the parent * @param classManager the class manager * @param name the name */ public NameSpace(final NameSpace parent, final BshClassManager classManager, final String name) { // We might want to do this here rather than explicitly in Interpreter // for global (see also prune()) // if (classManager == null && (parent == null)) // create our own class manager? this.setName(name); this.setParent(parent); this.setClassManager(classManager); // Register for notification of classloader change this.getClassManager().addListener(this); }
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); }
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; }
instanceNameSpace.setParent(CONTEXT_NAMESPACE.get());
instanceNameSpace.setParent(CONTEXT_NAMESPACE.get()); } else { instanceNameSpace = new NameSpace(classStaticThis.getNameSpace(), className); // todo: old code