@Test public void testApplyScriptWithoutInit() throws Exception { String script = "apply = function(priceTick) {};"; AdviserPredicate adviserPredicate = createAdviserPredicate(script); adviserPredicate.init(); }
@Override public void init() throws Exception { javaScripExpression = checkNotNull(getParameterValue(PARAMETER_JAVASCRIPT_EXPRESSION)); ScriptEngine engine = createJavaScriptEngine(); engine.getContext().getBindings(ScriptContext.ENGINE_SCOPE) .put(BINDING_NAME_CONTEXT, predicateExecutionContext); try { engine.eval(javaScripExpression); } catch (Exception e) { throw new Exception( String.format("Error [%s] while parsing javascript expression [%s].", e.getMessage(), javaScripExpression), e); } this.scriptEngine = (Invocable) engine; try { scriptEngine.invokeFunction(FUNCTION_INIT); } catch (NoSuchMethodException e) { } catch (ScriptException e) { throw new Exception( String.format("Error [%s] while calling initializing script with init().", e.getMessage()), e); } }
JavaScripPredicate extends AbstractAdviserPredicate { @Override public void init() throws Exception { javaScripExpression = checkNotNull(getParameterValue(PARAMETER_JAVASCRIPT_EXPRESSION)); ScriptEngine engine = createJavaScriptEngine(); engine.getContext().getBindings(ScriptContext.ENGINE_SCOPE) .put(BINDING_NAME_CONTEXT, predicateExecutionContext); try { engine.eval(javaScripExpression); } catch (Exception e) { throw new Exception( String.format("Error [%s] while parsing javascript expression [%s].", e.getMessage(), javaScripExpression), e); } this.scriptEngine = (Invocable) engine; try { scriptEngine.invokeFunction(FUNCTION_INIT); } catch (NoSuchMethodException e) { } catch (ScriptException e) { throw new Exception( String.format("Error [%s] while calling initializing script with init().", e.getMessage()), e); } } }
JavaScripPredicate extends AbstractAdviserPredicate { @Override public void init() throws Exception { javaScripExpression = checkNotNull(getParameterValue(PARAMETER_JAVASCRIPT_EXPRESSION)); ScriptEngine engine = createJavaScriptEngine(); engine.getContext().getBindings(ScriptContext.ENGINE_SCOPE) .put(BINDING_NAME_CONTEXT, predicateExecutionContext); try { engine.eval(javaScripExpression); } catch (Exception e) { throw new Exception( String.format("Error [%s] while parsing javascript expression [%s].", e.getMessage(), javaScripExpression), e); } this.scriptEngine = (Invocable) engine; try { scriptEngine.invokeFunction(FUNCTION_INIT); } catch (NoSuchMethodException e) { } catch (ScriptException e) { throw new Exception( String.format("Error [%s] while calling initializing script with init().", e.getMessage()), e); } } JavaScripPredicate(PredicateExecutionContext predicateExecutionContext); }
JavaScripPredicate extends AbstractAdviserPredicate { @Override public void init() throws Exception { javaScripExpression = checkNotNull(getParameterValue(PARAMETER_JAVASCRIPT_EXPRESSION)); ScriptEngine engine = createJavaScriptEngine(); engine.getContext().getBindings(ScriptContext.ENGINE_SCOPE) .put(BINDING_NAME_CONTEXT, predicateExecutionContext); try { engine.eval(javaScripExpression); } catch (Exception e) { throw new Exception( String.format("Error [%s] while parsing javascript expression [%s].", e.getMessage(), javaScripExpression), e); } this.scriptEngine = (Invocable) engine; try { scriptEngine.invokeFunction(FUNCTION_INIT); } catch (NoSuchMethodException e) { } catch (ScriptException e) { throw new Exception( String.format("Error [%s] while calling initializing script with init().", e.getMessage()), e); } } JavaScripPredicate(PredicateExecutionContext predicateExecutionContext); @Override boolean apply(final PriceTick priceTick); @Override void init(); }
JavaScripPredicate extends AbstractAdviserPredicate { @Override public void init() throws Exception { javaScripExpression = checkNotNull(getParameterValue(PARAMETER_JAVASCRIPT_EXPRESSION)); ScriptEngine engine = createJavaScriptEngine(); engine.getContext().getBindings(ScriptContext.ENGINE_SCOPE) .put(BINDING_NAME_CONTEXT, predicateExecutionContext); try { engine.eval(javaScripExpression); } catch (Exception e) { throw new Exception( String.format("Error [%s] while parsing javascript expression [%s].", e.getMessage(), javaScripExpression), e); } this.scriptEngine = (Invocable) engine; try { scriptEngine.invokeFunction(FUNCTION_INIT); } catch (NoSuchMethodException e) { } catch (ScriptException e) { throw new Exception( String.format("Error [%s] while calling initializing script with init().", e.getMessage()), e); } } JavaScripPredicate(PredicateExecutionContext predicateExecutionContext); @Override boolean apply(final PriceTick priceTick); @Override void init(); static final String PARAMETER_JAVASCRIPT_EXPRESSION; }