@Override public <T> T getInterface(Object thiz, Class<T> clasz) { return ((Invocable) engine).getInterface(thiz, clasz); }
@Override public <T> T getInterface(Class<T> clasz) { return ((Invocable)engine).getInterface(clasz); }
@Override public <T> T getInterface(Class<T> clasz) { return ((Invocable) engine).getInterface(clasz); }
@Override public <T> T getInterface(Class<T> clasz) { return ((Invocable)engine).getInterface(clasz); }
@Override public <T> T getInterface(Object thiz, Class<T> clasz) { return ((Invocable) engine).getInterface(thiz, clasz); }
@Override public <T> T getInterface(Class<T> clasz) { return ((Invocable) engine).getInterface(clasz); }
@Override public <T> T getInterface(Object thiz, Class<T> clasz) { return ((Invocable)engine).getInterface(thiz, clasz); }
@Override public <T> T getInterface(Object thiz, Class<T> clasz) { return ((Invocable)engine).getInterface(thiz, clasz); }
private SelectorFunction compileSelectorFunction() { final ScriptEngine engine = new ScriptEngineManager().getEngineByName("javascript"); try { ((Compilable) engine).compile("var apply = " + function).eval(); return ((Invocable) engine).getInterface(SelectorFunction.class); } catch (ScriptException e) { throw new RuntimeException(e); } }
private SelectorFunction compileSelectorFunction() { final ScriptEngine engine = new ScriptEngineManager().getEngineByName("javascript"); try { ((Compilable) engine).compile("var apply = " + function).eval(); return ((Invocable) engine).getInterface(SelectorFunction.class); } catch (ScriptException e) { throw Throwables.propagate(e); } }
@Nullable protected Object adaptToInterfaces( @Nullable Object script, ScriptSource scriptSource, Class<?>... actualInterfaces) { Class<?> adaptedIfc; if (actualInterfaces.length == 1) { adaptedIfc = actualInterfaces[0]; } else { adaptedIfc = ClassUtils.createCompositeInterface(actualInterfaces, this.beanClassLoader); } if (adaptedIfc != null) { ScriptEngine scriptEngine = this.scriptEngine; if (!(scriptEngine instanceof Invocable)) { throw new ScriptCompilationException(scriptSource, "ScriptEngine must implement Invocable in order to adapt it to an interface: " + scriptEngine); } Invocable invocable = (Invocable) scriptEngine; if (script != null) { script = invocable.getInterface(script, adaptedIfc); } if (script == null) { script = invocable.getInterface(adaptedIfc); if (script == null) { throw new ScriptCompilationException(scriptSource, "Could not adapt script to interface [" + adaptedIfc.getName() + "]"); } } } return script; }
@Nullable protected Object adaptToInterfaces( @Nullable Object script, ScriptSource scriptSource, Class<?>... actualInterfaces) { Class<?> adaptedIfc; if (actualInterfaces.length == 1) { adaptedIfc = actualInterfaces[0]; } else { adaptedIfc = ClassUtils.createCompositeInterface(actualInterfaces, this.beanClassLoader); } if (adaptedIfc != null) { ScriptEngine scriptEngine = this.scriptEngine; if (!(scriptEngine instanceof Invocable)) { throw new ScriptCompilationException(scriptSource, "ScriptEngine must implement Invocable in order to adapt it to an interface: " + scriptEngine); } Invocable invocable = (Invocable) scriptEngine; if (script != null) { script = invocable.getInterface(script, adaptedIfc); } if (script == null) { script = invocable.getInterface(adaptedIfc); if (script == null) { throw new ScriptCompilationException(scriptSource, "Could not adapt script to interface [" + adaptedIfc.getName() + "]"); } } } return script; }
final RecordSetWriterFactory scriptedWriter = invocable.getInterface(obj, RecordSetWriterFactory.class); recordFactory.set(scriptedWriter);
final Processor scriptProcessor = invocable.getInterface(obj, Processor.class); processor.set(scriptProcessor);
final RecordReaderFactory scriptedReader = invocable.getInterface(obj, RecordReaderFactory.class); recordFactory.set(scriptedReader);
final LookupService<Object> scriptedLookupService = invocable.getInterface(obj, LookupService.class); lookupService.set(scriptedLookupService);
public <T> T compileScript( Class<T> iface, String script, String engineName) { ScriptEngineManager factory = new ScriptEngineManager(); ScriptEngine engine = factory.getEngineByName(engineName); try { engine.eval(script); Invocable inv = (Invocable) engine; return inv.getInterface(iface); } catch (ScriptException e) { throw Util.newError( e, "Error while compiling script to implement " + iface + " SPI"); } }
@Override public <T> T getInterface(Object thiz, Class<T> clasz) { return getInvocableEngine().getInterface(thiz, clasz); } private Invocable getInvocableEngine() {
@Override public <T> T getInterface(Class<T> clasz) { return getInvocableEngine().getInterface(clasz); } @Override
private SelectorFunction compileSelectorFunction() { final ScriptEngine engine = new ScriptEngineManager().getEngineByName("javascript"); try { ((Compilable) engine).compile("var apply = " + function).eval(); return ((Invocable) engine).getInterface(SelectorFunction.class); } catch (ScriptException e) { throw new RuntimeException(e); } }