@Override public ValueExpression resolveVariable(String variableName) { int scope = scriptContext.getAttributesScope(variableName); if (scope != -1) { Object value = scriptContext.getAttribute(variableName, scope); if (value instanceof ValueExpression) { // Just return the existing ValueExpression return (ValueExpression) value; } else { // Create a new ValueExpression based on the variable value return expressionFactory.createValueExpression(value, Object.class); } } return null; }
private Object callGlobal(String name, Object[] args, ScriptContext ctx) { Closure<?> closure = globalClosures.get(name); if (closure != null) { return closure.call(args); } else { // Look for closure valued variable in the // given ScriptContext. If available, call it. Object value = ctx.getAttribute(name); if (value instanceof Closure) { return ((Closure) value).call(args); } // else fall thru.. } throw new MissingMethodException(name, getClass(), args); }
@Override public Method resolveFunction(String prefix, String localName) { String functionName = getFullFunctionName(prefix, localName); int scope = scriptContext.getAttributesScope(functionName); if (scope != -1) { // Methods are added as variables in the ScriptScope Object attributeValue = scriptContext.getAttribute(functionName); return (attributeValue instanceof Method) ? (Method) attributeValue : null; } else { return null; } } }
private ELContext createElContext(final ScriptContext scriptCtx) { Object existingELCtx = scriptCtx.getAttribute("elcontext"); if (existingELCtx instanceof ELContext) { return (ELContext) existingELCtx;
@Override public Method resolveFunction(String prefix, String localName) { String functionName = getFullFunctionName(prefix, localName); int scope = scriptContext.getAttributesScope(functionName); if (scope != -1) { // Methods are added as variables in the ScriptScope Object attributeValue = scriptContext.getAttribute(functionName); return (attributeValue instanceof Method) ? (Method) attributeValue : null; } else { return null; } } }
private Object callGlobal(final String name, final Object args[], final ScriptContext ctx) { final Closure closure = globalClosures.get(name); if (closure != null) { return closure.call(args); } final Object value = ctx.getAttribute(name); if (value instanceof Closure) { return ((Closure) value).call(args); } else { throw new MissingMethodException(name, getClass(), args); } }
@Override public Method resolveFunction(String prefix, String localName) { String functionName = getFullFunctionName(prefix, localName); int scope = scriptContext.getAttributesScope(functionName); if (scope != -1) { // Methods are added as variables in the ScriptScope Object attributeValue = scriptContext.getAttribute(functionName); return (attributeValue instanceof Method) ? (Method) attributeValue : null; } else { return null; } } }
private Object callGlobal(String name, Object[] args, ScriptContext ctx) { Closure<?> closure = globalClosures.get(name); if (closure != null) { return closure.call(args); } else { // Look for closure valued variable in the // given ScriptContext. If available, call it. Object value = ctx.getAttribute(name); if (value instanceof Closure) { return ((Closure) value).call(args); } // else fall thru.. } throw new MissingMethodException(name, getClass(), args); }
@Override public ValueExpression resolveVariable(String variableName) { int scope = scriptContext.getAttributesScope(variableName); if (scope != -1) { Object value = scriptContext.getAttribute(variableName, scope); if (value instanceof ValueExpression) { // Just return the existing ValueExpression return (ValueExpression) value; } else { // Create a new ValueExpression based on the variable value return expressionFactory.createValueExpression(value, Object.class); } } return null; }
public Object eval(String script, ScriptContext ctx) throws ScriptException { try { String val = (String) ctx.getAttribute("#jsr223.groovy.engine.keep.globals", ScriptContext.ENGINE_SCOPE); ReferenceBundle bundle = ReferenceBundle.getHardBundle(); if (val != null && val.length() > 0) { if (val.equalsIgnoreCase("soft")) { bundle = ReferenceBundle.getSoftBundle(); } else if (val.equalsIgnoreCase("weak")) { bundle = ReferenceBundle.getWeakBundle(); } else if (val.equalsIgnoreCase("phantom")) { bundle = ReferenceBundle.getPhantomBundle(); } } globalClosures.setBundle(bundle); } catch (ClassCastException cce) { /*ignore.*/ } try { Class<?> clazz = getScriptClass(script); if (clazz == null) throw new ScriptException("Script class is null"); return eval(clazz, ctx); } catch (Exception e) { if (debug) e.printStackTrace(); throw new ScriptException(e); } }
@Override public ValueExpression resolveVariable(String variableName) { int scope = scriptContext.getAttributesScope(variableName); if (scope != -1) { Object value = scriptContext.getAttribute(variableName, scope); if (value instanceof ValueExpression) { // Just return the existing ValueExpression return (ValueExpression) value; } else { // Create a new ValueExpression based on the variable value return expressionFactory.createValueExpression(value, Object.class); } } return null; }
final Map<String, Object> localVars = (Map<String, Object>) context.getAttribute(COLLECTED_BOUND_VARS_MAP_VARNAME); if (localVars != null) { localVars.entrySet().forEach(e -> {
@Override public Object getVariable(String name) { synchronized (context) { int scope = context.getAttributesScope(name); if (scope != -1) { return context.getAttribute(name, scope); } // Redirect script output to context writer, if out var is not already provided if ("out".equals(name)) { final Writer writer = context.getWriter(); if (writer != null) { return (writer instanceof PrintWriter) ? (PrintWriter) writer : new PrintWriter(writer, true); } } // Provide access to engine context, if context var is not already provided if ("context".equals(name)) { return context; } } throw new MissingPropertyException(name, getClass()); }
/** * {@inheritDoc} */ @Override public Object eval(final String script, final ScriptContext context) throws ScriptException { if (globalFunctionCacheEnabled) { try { final String val = (String) context.getAttribute(KEY_REFERENCE_TYPE, ScriptContext.ENGINE_SCOPE); ReferenceBundle bundle = ReferenceBundle.getHardBundle(); if (val != null && val.length() > 0) { if (val.equalsIgnoreCase(REFERENCE_TYPE_SOFT)) { bundle = ReferenceBundle.getSoftBundle(); } else if (val.equalsIgnoreCase(REFERENCE_TYPE_WEAK)) { bundle = ReferenceBundle.getWeakBundle(); } else if (val.equalsIgnoreCase(REFERENCE_TYPE_PHANTOM)) { bundle = ReferenceBundle.getPhantomBundle(); } } globalClosures.setBundle(bundle); } catch (ClassCastException cce) { /*ignore.*/ } } try { registerBindingTypes(context); final Class clazz = getScriptClass(script); if (null == clazz) throw new ScriptException("Script class is null"); return eval(clazz, context); } catch (Exception e) { throw new ScriptException(e); } }
@Override public Object getVariable(String name) { synchronized (ctx) { int scope = ctx.getAttributesScope(name); if (scope != -1) { return ctx.getAttribute(name, scope); } // Redirect script output to context writer, if out var is not already provided if ("out".equals(name)) { Writer writer = ctx.getWriter(); if (writer != null) { return (writer instanceof PrintWriter) ? (PrintWriter) writer : new PrintWriter(writer, true); } } // Provide access to engine context, if context var is not already provided if ("context".equals(name)) { return ctx; } } throw new MissingPropertyException(name, getClass()); }
private ELContext createElContext(final ScriptContext scriptCtx) { Object existingELCtx = scriptCtx.getAttribute("elcontext"); if (existingELCtx instanceof ELContext) { return (ELContext) existingELCtx;
@Override public Object getVariable(final String name) { synchronized (ctx) { final int scope = ctx.getAttributesScope(name); if (scope != -1) { return ctx.getAttribute(name, scope); } } throw new MissingPropertyException(name, getClass()); }
private ELContext createElContext(final ScriptContext scriptCtx) { Object existingELCtx = scriptCtx.getAttribute("elcontext"); if (existingELCtx instanceof ELContext) { return (ELContext) existingELCtx;
protected String getFilename(ScriptContext context) { String filename = (String) context.getAttribute(ScriptEngine.FILENAME); if (filename != null) { return filename; } else { return "unknown"; } }
static boolean isTerminationOn(ScriptContext context) { Object obj = context.getAttribute(AttributeName.TERMINATION.toString()); if (obj != null && obj instanceof Boolean && ((Boolean) obj) == true) { return true; } return false; }