public ScriptContextBuilder timeout(Integer value) { context.setAttribute(TIMEOUT_ATTRIBUTE, value, ScriptContext.ENGINE_SCOPE); return this; }
public ScriptContextBuilder stdout(PrintStream stdout) { context.setAttribute(OUTPUT_PRINTSTREAM_ATTRIBUTE, stdout, ScriptContext.ENGINE_SCOPE); return this; }
public ScriptContextBuilder stderr(PrintStream stderr) { context.setAttribute(ERROR_PRINTSTREAM_ATTRIBUTE, stderr, ScriptContext.ENGINE_SCOPE); return this; }
public ScriptContextBuilder currentResource(Resource<?> currentResource) { context.setAttribute(CURRENT_RESOURCE_ATTRIBUTE, currentResource, ScriptContext.ENGINE_SCOPE); return this; }
/** * Creates the script execution context from the resolution context. * * @param filterContext current resolution context * @param attributeId ID of the attribute currently being evaluted * @param attributeValue attribute currently being validated * * @return constructed script context */ protected ScriptContext getScriptContext(ShibbolethFilteringContext filterContext, String attributeId, Object attributeValue) { SimpleScriptContext scriptContext = new SimpleScriptContext(); scriptContext.setAttribute("filterContext", filterContext, ScriptContext.ENGINE_SCOPE); scriptContext.setAttribute("attributeId", attributeId, ScriptContext.ENGINE_SCOPE); scriptContext.setAttribute("attributeValue", attributeValue, ScriptContext.ENGINE_SCOPE); return scriptContext; }
/** {@inheritDoc} */ @Override public Set<String> apply(@Nullable final XMLObject context) { final SimpleScriptContext scriptContext = new SimpleScriptContext(); scriptContext.setAttribute("custom", getCustomObject(), ScriptContext.ENGINE_SCOPE); scriptContext.setAttribute("profileContext", context, ScriptContext.ENGINE_SCOPE); try { final Object output = script.eval(scriptContext); return (Set<String>) output; } catch (final ScriptException e) { log.error("{} Error while executing Function script", logPrefix, e); return null; } }
public void testScriptFilename() { ScriptEngineManager manager = new ScriptEngineManager(); ScriptEngine pythonEngine = manager.getEngineByName("python"); SimpleScriptContext scriptContext = new SimpleScriptContext(); scriptContext.setAttribute(ScriptEngine.FILENAME, "sample.py", ScriptContext.ENGINE_SCOPE); try { pythonEngine.eval("foo", scriptContext); } catch (ScriptException e) { assertEquals("sample.py", e.getFileName()); return; } assertTrue("Expected a ScriptException", false); }
JsRunThread(final String myAddress, final ScriptEngine scriptEngine, final LibraryServiceInterface libraryService, final Path scriptFilePath, final Map<String, ?> initialVariables) { super(myAddress, getScriptFilePath(scriptFilePath), initialVariables); this.scriptEngine = scriptEngine; scriptContext = new SimpleScriptContext(); scriptContext.setBindings(new GlobalBindings(), ScriptContext.GLOBAL_SCOPE); if (initialVariables != null) initialVariables.forEach( (key, value) -> scriptContext.setAttribute(key, value, ScriptContext.ENGINE_SCOPE)); if (libraryService != null) scriptContext.setAttribute("library", libraryService, ScriptContext.ENGINE_SCOPE); scriptContext.setAttribute("closeable", closeables, ScriptContext.ENGINE_SCOPE); this.scriptFilePath = scriptFilePath; scriptContext.setWriter(outputWriter); scriptContext.setErrorWriter(errorWriter); scriptEngine.setContext(scriptContext); }
/** {@inheritDoc} */ @Override protected void doExecute(@Nonnull @NonnullElements final Collection<Item<T>> itemCollection) throws StageProcessingException { final SimpleScriptContext context = new SimpleScriptContext(); context.setAttribute(ITEMS, itemCollection, SimpleScriptContext.ENGINE_SCOPE); try { script.eval(context); } catch (ScriptException e) { String errMsg = getId() + " pipeline stage unable to execute script"; log.error(errMsg, e); throw new StageProcessingException(errMsg, e); } }
@Override public void evaluate(Evaluation evaluation) { Policy policy = evaluation.getPolicy(); AuthorizationProvider authorization = evaluation.getAuthorizationProvider(); EvaluatableScriptAdapter adapter = evaluatableScript.apply(authorization, policy); try { SimpleScriptContext context = new SimpleScriptContext(); context.setAttribute("$evaluation", evaluation, ScriptContext.ENGINE_SCOPE); adapter.eval(context); } catch (Exception e) { throw new RuntimeException("Error evaluating JS Policy [" + policy.getName() + "].", e); } }
/** * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated NOT */ @Override public Boolean selected ( final CustomizationRequest request ) { try { if ( this.executor == null ) { this.executor = new ScriptExecutor ( getScriptEngine (), this.code, ScriptCustomizationPipelineImpl.class.getClassLoader () ); } final SimpleScriptContext ctx = new SimpleScriptContext (); ctx.setAttribute ( "request", request, ScriptContext.ENGINE_SCOPE ); return (Boolean)this.executor.execute ( ctx ); } catch ( final Exception e ) { throw new RuntimeException ( e ); } }
private List<?> processRow() throws ExpressionEvaluationException, TeiidComponentException, TeiidProcessingException { List<Object> tuple = new ArrayList<Object>(projectedColumns.size()); this.scriptContext.setAttribute(TEIID_ROW, this.item, ScriptContext.ENGINE_SCOPE); this.scriptContext.setAttribute(TEIID_ROW_NUMBER, this.rowCount, ScriptContext.ENGINE_SCOPE); for (ObjectColumn proColumn : projectedColumns) { Object value = evalScript(proColumn.getCompiledScript(), proColumn.getPath()); if (value == null) { if (proColumn.getDefaultExpression() != null) { tuple.add(getEvaluator(Collections.emptyMap()).evaluate(proColumn.getDefaultExpression(), null)); } else { tuple.add(null); } continue; } value = FunctionDescriptor.importValue(value, proColumn.getSymbol().getType(), getContext()); tuple.add(value); } item = null; return tuple; }
private List<?> processRow() throws ExpressionEvaluationException, TeiidComponentException, TeiidProcessingException { List<Object> tuple = new ArrayList<Object>(projectedColumns.size()); this.scriptContext.setAttribute(TEIID_ROW, this.item, ScriptContext.ENGINE_SCOPE); this.scriptContext.setAttribute(TEIID_ROW_NUMBER, this.rowCount, ScriptContext.ENGINE_SCOPE); for (ObjectColumn proColumn : projectedColumns) { Object value = evalScript(proColumn.getCompiledScript(), proColumn.getPath()); if (value == null) { if (proColumn.getDefaultExpression() != null) { tuple.add(getEvaluator(Collections.emptyMap()).evaluate(proColumn.getDefaultExpression(), null)); } else { tuple.add(null); } continue; } value = FunctionDescriptor.importValue(value, proColumn.getSymbol().getType()); tuple.add(value); } item = null; return tuple; }
private List<?> processRow() throws ExpressionEvaluationException, TeiidComponentException, TeiidProcessingException { List<Object> tuple = new ArrayList<Object>(projectedColumns.size()); this.scriptContext.setAttribute(TEIID_ROW, this.item, ScriptContext.ENGINE_SCOPE); this.scriptContext.setAttribute(TEIID_ROW_NUMBER, this.rowCount, ScriptContext.ENGINE_SCOPE); for (ObjectColumn proColumn : projectedColumns) { Object value = evalScript(proColumn.getCompiledScript(), proColumn.getPath()); if (value == null) { if (proColumn.getDefaultExpression() != null) { tuple.add(getEvaluator(Collections.emptyMap()).evaluate(proColumn.getDefaultExpression(), null)); } else { tuple.add(null); } continue; } value = FunctionDescriptor.importValue(value, proColumn.getSymbol().getType(), getContext()); tuple.add(value); } item = null; return tuple; }
/** * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated NOT */ @Override public void customize ( final CustomizationRequest request ) { // FIXME: we should somehow take this out of here try { if ( this.executor == null ) { final String resource = eResource ().getURI ().toString (); this.executor = new ScriptExecutor ( getScriptEngine (), this.code, ScriptCustomizationPipelineImpl.class.getClassLoader (), resource ); } final SimpleScriptContext ctx = new SimpleScriptContext (); ctx.setAttribute ( "request", request, ScriptContext.ENGINE_SCOPE ); this.executor.execute ( ctx ); } catch ( final Exception e ) { throw new RuntimeException ( e ); } }
throws AttributeResolutionException { SimpleScriptContext scriptContext = new SimpleScriptContext(); scriptContext.setAttribute(getId(), null, ScriptContext.ENGINE_SCOPE); scriptContext.setAttribute("requestContext", resolutionContext.getAttributeRequestContext(), ScriptContext.ENGINE_SCOPE); copy.setValueComparator(attr.getValueComparator()); copy.setValues(attr.getValues()); scriptContext.setAttribute(attr.getId(), copy, ScriptContext.ENGINE_SCOPE); copy.setValueComparator(attribute.getValueComparator()); copy.setValues(attribute.getValues()); scriptContext.setAttribute(attribute.getId(), copy, ScriptContext.ENGINE_SCOPE);
@Override public void open() throws TeiidComponentException, TeiidProcessingException { super.open(); if (table.getScriptEngine() == null) { table.setScriptEngine(getContext().getMetadata().getScriptEngine(table.getScriptingLanguage())); } this.scriptContext.setAttribute(TEIID_CONTEXT, this.getContext(), ScriptContext.ENGINE_SCOPE); }
@Override public void open() throws TeiidComponentException, TeiidProcessingException { super.open(); if (table.getScriptEngine() == null) { table.setScriptEngine(getContext().getMetadata().getScriptEngine(table.getScriptingLanguage())); } this.scriptContext.setAttribute(TEIID_CONTEXT, this.getContext(), ScriptContext.ENGINE_SCOPE); }
@Override public void open() throws TeiidComponentException, TeiidProcessingException { super.open(); if (table.getScriptEngine() == null) { table.setScriptEngine(getContext().getMetadata().getScriptEngine(table.getScriptingLanguage())); } this.scriptContext.setAttribute(TEIID_CONTEXT, this.getContext(), ScriptContext.ENGINE_SCOPE); }
@Test public void testArraySyntax() throws Exception { TeiidScriptEngine tse = new TeiidScriptEngine(); CompiledScript cs = tse.compile("root.1.2"); SimpleScriptContext ssc = new SimpleScriptContext(); ssc.setAttribute("root", new Object[] {new Object[] {"x", "y"}}, SimpleScriptContext.ENGINE_SCOPE); assertEquals("y", cs.eval(ssc)); }