@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; }
@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; } } }
@Override public void setVariable(String name, Object value) { synchronized (context) { int scope = context.getAttributesScope(name); if (scope == -1) { scope = ScriptContext.ENGINE_SCOPE; } context.setAttribute(name, value, scope); } } };
@Override public void setVariable(String name, Object value) { synchronized (ctx) { int scope = ctx.getAttributesScope(name); if (scope == -1) { scope = ScriptContext.ENGINE_SCOPE; } ctx.setAttribute(name, value, scope); } } };
@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; } } }
@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; } } }
@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; }
@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; }
@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()); }
@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 static String[] getArguments(ScriptContext ctx) { int scope = ctx.getAttributesScope(ARGUMENTS); if (scope != -1) { Object obj = ctx.getAttribute(ARGUMENTS, scope); if (obj instanceof String[]) { return (String[])obj; } } // return zero length array return EMPTY_STRING_ARRAY; }
private static ClassLoader getParentLoader(ScriptContext ctx) { int scope = ctx.getAttributesScope(PARENTLOADER); if (scope != -1) { Object loader = ctx.getAttribute(PARENTLOADER); if (loader instanceof ClassLoader) { return (ClassLoader) loader; } // else fall through.. } return null; }
/** {@inheritDoc} */ public void set(final String name, final Object value) { int scope = scriptContext.getAttributesScope(name); if (scope == -1) { // not found, default to engine scope = ScriptContext.ENGINE_SCOPE; } scriptContext.getBindings(scope).put(name , value); }
private static String getSourcePath(ScriptContext ctx) { int scope = ctx.getAttributesScope(SOURCEPATH); if (scope != -1) { return ctx.getAttribute(SOURCEPATH).toString(); } else { // look for "com.sun.script.java.sourcepath" return System.getProperty(SYSPROP_PREFIX + SOURCEPATH); } }
private static String getMainClassName(ScriptContext ctx) { int scope = ctx.getAttributesScope(MAINCLASS); if (scope != -1) { return ctx.getAttribute(MAINCLASS).toString(); } else { // look for "com.sun.script.java.mainClass" return System.getProperty(SYSPROP_PREFIX + MAINCLASS); } }
private static ClassLoader getParentLoader(ScriptContext ctx) { int scope = ctx.getAttributesScope(PARENTLOADER); if (scope != -1) { Object loader = ctx.getAttribute(PARENTLOADER); if (loader instanceof ClassLoader) { return (ClassLoader) loader; } // else fall through.. } return null; }
private static String getFileName(ScriptContext ctx) { int scope = ctx.getAttributesScope(ScriptEngine.FILENAME); if (scope != -1) { return ctx.getAttribute(ScriptEngine.FILENAME, scope).toString(); } else { return "$unnamed.java"; } }
private static String getMainClassName(ScriptContext ctx) { int scope = ctx.getAttributesScope(MAINCLASS); if (scope != -1) { return ctx.getAttribute(MAINCLASS).toString(); } else { // look for "com.sun.script.java.mainClass" return System.getProperty(SYSPROP_PREFIX + MAINCLASS); } }
private static String getFileName(ScriptContext ctx) { int scope = ctx.getAttributesScope(ScriptEngine.FILENAME); if (scope != -1) { return ctx.getAttribute(ScriptEngine.FILENAME, scope).toString(); } else { return "$unnamed.java"; } }
@Override public void __setitem__(String key, PyObject value) { int scope = context.getAttributesScope(key); if (scope == -1) scope = ScriptContext.ENGINE_SCOPE; context.setAttribute(key, value instanceof PyType ? value : value.__tojava__(Object.class), scope); }