/** * Sets the binding (the variables available in the scope of the BeanBuilder) * @param b The Binding instance */ public void setBinding(Binding b) { this.binding = b.getVariables(); }
private Map doGetVariables() { return super.getVariables(); }
public Object getVariable(String name) { return context.getVariables().get(name); }
@SuppressWarnings("unchecked") private static void storeBindingVars(ScriptEngine self, Binding binding) { Set<Map.Entry<?, ?>> vars = binding.getVariables().entrySet(); for (Map.Entry<?, ?> me : vars) { self.put(me.getKey().toString(), me.getValue()); } }
@Override public Map getVariables() { lazyInit(); return super.getVariables(); }
@SuppressWarnings("unchecked") private Map collectParams(HttpServletRequest request) { Map params = new LinkedHashMap(); for (Enumeration names = request.getParameterNames(); names.hasMoreElements();) { String name = (String) names.nextElement(); if (!super.getVariables().containsKey(name)) { String[] values = request.getParameterValues(name); if (values.length == 1) { params.put(name, values[0]); } else { params.put(name, values); } } } return params; }
private Object invokePropertyOrMissing(Object object, String methodName, Object[] originalArguments, boolean fromInsideClass, boolean isCallToSuper) { // if no method was found, try to find a closure defined as a field of the class and run it Object value = null; final MetaProperty metaProperty = this.getMetaProperty(methodName, false); if (metaProperty != null) value = metaProperty.getProperty(object); else { if (object instanceof Map) value = ((Map)object).get(methodName); } if (value instanceof Closure) { // This test ensures that value != this If you ever change this ensure that value != this Closure closure = (Closure) value; MetaClass delegateMetaClass = closure.getMetaClass(); return delegateMetaClass.invokeMethod(closure.getClass(), closure, CLOSURE_DO_CALL_METHOD, originalArguments, false, fromInsideClass); } if (object instanceof Script) { Object bindingVar = ((Script) object).getBinding().getVariables().get(methodName); if (bindingVar != null) { MetaClass bindingVarMC = ((MetaClassRegistryImpl) registry).getMetaClass(bindingVar); return bindingVarMC.invokeMethod(bindingVar, CLOSURE_CALL_METHOD, originalArguments); } } return invokeMissingMethod(object, methodName, originalArguments, null, isCallToSuper); }
Map variables = context.getVariables(); MetaClass mc = getMetaClass(object); for (Object o : variables.entrySet()) {
Map bindings = script.getBinding().getVariables();
public void testCreateScriptWithNullClass() { Script script = InvokerHelper.createScript(null, new Binding(bindingVariables)); assertEquals(bindingVariables, script.getBinding().getVariables()); }
public void testCreateScriptWithScriptClass() { GroovyClassLoader classLoader = new GroovyClassLoader(); String controlProperty = "text"; String controlValue = "I am a script"; String code = controlProperty + " = '" + controlValue + "'"; GroovyCodeSource codeSource = new GroovyCodeSource(code, "testscript", "/groovy/shell"); Class scriptClass = classLoader.parseClass(codeSource, false); Script script = InvokerHelper.createScript(scriptClass, new Binding(bindingVariables)); assertEquals(bindingVariables, script.getBinding().getVariables()); script.run(); assertEquals(controlValue, script.getProperty(controlProperty)); } }
@SuppressWarnings("unchecked") private static void storeBindingVars(ScriptEngine self, Binding binding) { Set<Map.Entry<?, ?>> vars = binding.getVariables().entrySet(); for (Map.Entry<?, ?> me : vars) { self.put(me.getKey().toString(), me.getValue()); } }
/** * Sets the binding (the variables available in the scope of the BeanBuilder) * @param b The Binding instance */ public void setBinding(Binding b) { this.binding = b.getVariables(); }
/** * Sets the binding (the variables available in the scope of the BeanBuilder) * @param b The Binding instance */ public void setBinding(Binding b) { this.binding = b.getVariables(); }
@SuppressWarnings("unchecked") @Override public Map getVariables() { return ImmutableMap.builder() .putAll(first.getVariables()) .putAll(second.getVariables()) .build(); }
@Override public Object remove(Object key) { final String name = (String) key; if (context.containsBean(name)) { throw new IllegalArgumentException("Can't remove variable to named '" + name + "'."); } return super.getVariables().remove(key); }
@SuppressWarnings("unchecked") private static void storeBindingVars(ScriptEngine self, Binding binding) { Set<Map.Entry> vars = binding.getVariables().entrySet(); for (Map.Entry me : vars) { self.put(me.getKey().toString(), me.getValue()); } } }
private void updateBoundVariables() { boundVariables = getBinding().getVariables(); final Object boundScript = boundVariables.remove("script"); if(boundScript != null) script = boundScript; // this is important: we need this reference no matter if "node" is overridden later by the user node = (NodeRO) boundVariables.get("node"); controller = (ControllerRO) boundVariables.get("c"); }
@Override public Object getAttribute(String name) { Assert.notNull(name, "Attribute name cannot be null"); if (pageScope.getVariables().containsKey(name)) { return pageScope.getVariable(name); } return null; }
@SuppressWarnings("unchecked") public GroovyScript(CompiledScript compiledScript, Script script, @Nullable LeafSearchLookup lookup, ESLogger logger) { this.compiledScript = compiledScript; this.script = script; this.lookup = lookup; this.logger = logger; this.variables = script.getBinding().getVariables(); }