@Test public void shouldRemoveGlobalBindings() throws Exception { final DefaultGremlinScriptEngineManager manager = new DefaultGremlinScriptEngineManager(); manager.put("x", 100); final GremlinScriptEngine engine1 = manager.getEngineByName(ENGINE_TO_TEST); assertThat(engine1.getBindings(ScriptContext.GLOBAL_SCOPE).size(), is(1)); assertEquals(101, (int) engine1.eval("x+1")); manager.getBindings().remove("x"); final GremlinScriptEngine engine2 = manager.getEngineByName(ENGINE_TO_TEST); assertThat(engine2.getBindings(ScriptContext.GLOBAL_SCOPE).size(), is(0)); }
@Test public void shouldAddLazyGlobalBindingsViaPlugin() throws Exception { final Bindings bindings = new SimpleBindings(); bindings.put("x", 100); final BindingsGremlinPlugin plugin = new BindingsGremlinPlugin(() -> bindings); final DefaultGremlinScriptEngineManager manager = new DefaultGremlinScriptEngineManager(); manager.addPlugin(plugin); final GremlinScriptEngine engine = manager.getEngineByName(ENGINE_TO_TEST); assertThat(engine.getBindings(ScriptContext.GLOBAL_SCOPE).size(), is(1)); assertEquals(101, (int) engine.eval("x+1")); }
public void loadStyleResource( String s ) { if( !initialized ) { initializeApi(); } try { Reader in = new InputStreamReader(getClass().getResourceAsStream(s)); CompiledScript script = compiler.compile(in); int before = bindings.size(); Object result = script.eval(bindings); if( before != bindings.size() ) { //log.warn( "Binding count increased executing:" + s + " keys:" + bindings.keySet() ); } } catch( ScriptException e ) { throw new RuntimeException("Error running resource:" + s, e); } }
public void loadStyle( String name, Reader in ) { if( !initialized ) { initializeApi(); } try { CompiledScript script = compiler.compile(in); int before = bindings.size(); Object result = script.eval(bindings); if( before != bindings.size() ) { //log.warn( "Binding count increased executing:" + s + " keys:" + bindings.keySet() ); } } catch( ScriptException e ) { throw new RuntimeException("Error running resource:" + name, e); } } }
private String[] getAllKeys() { ArrayList<String> list = new ArrayList<String>(); synchronized (context) { for (int scope : context.getScopes()) { Bindings bindings = context.getBindings(scope); if (bindings != null) { list.ensureCapacity(bindings.size()); for (String key : bindings.keySet()) { list.add(key); } } } } String[] res = new String[list.size()]; list.toArray(res); return res; }
@Override public Object[] getIds() { ArrayList<String> list = new ArrayList<String>(); synchronized (context) { for (int scope : context.getScopes()) { Bindings bindings = context.getBindings(scope); if (bindings != null) { list.ensureCapacity(bindings.size()); for (String key : bindings.keySet()) { list.add(key); } } } } return list.toArray(new String[list.size()]); }
private String[] getAllKeys() { ArrayList<String> list = new ArrayList<String>(); synchronized (context) { for (int scope : context.getScopes()) { Bindings bindings = context.getBindings(scope); if (bindings != null) { list.ensureCapacity(bindings.size()); for (String key : bindings.keySet()) { list.add(key); } } } } String[] res = new String[list.size()]; list.toArray(res); return res; }
private String[] getAllKeys() { ArrayList<String> list = new ArrayList<String>(); synchronized (context) { for (int scope : context.getScopes()) { Bindings bindings = context.getBindings(scope); if (bindings != null) { list.ensureCapacity(bindings.size()); for (String key : bindings.keySet()) { list.add(key); } } } } String[] res = new String[list.size()]; list.toArray(res); return res; }
private String[] getAllKeys() { ArrayList<String> list = new ArrayList<String>(); synchronized (context) { for (int scope : context.getScopes()) { Bindings bindings = context.getBindings(scope); if (bindings != null) { list.ensureCapacity(bindings.size()); for (String key : bindings.keySet()) { list.add(key); } } } } String[] res = new String[list.size()]; list.toArray(res); return res; }
private static LispObject makeBindings(Bindings bindings) { if (bindings == null || bindings.size() == 0) { return Lisp.NIL; } LispObject[] argList = new LispObject[bindings.size()]; int i = 0; for (Map.Entry<String, Object> entry : bindings.entrySet()) { argList[i++] = Symbol.CONS.execute(new SimpleString(entry.getKey()), JavaObject.getInstance(entry.getValue(), true)); } return Symbol.LIST.getSymbolFunction().execute(argList); }
Bindings bindings = engine.getBindings(ScriptContext.ENGINE_SCOPE); fr.close(); if (bindings.size() > 0)
@Override public Object eval(final Reader reader) throws ScriptException { final Bindings bindings = getBindings(ScriptContext.ENGINE_SCOPE); return bindings.size(); } }
@Test public void shouldRemoveGlobalBindings() throws Exception { final DefaultGremlinScriptEngineManager manager = new DefaultGremlinScriptEngineManager(); manager.put("x", 100); final GremlinScriptEngine engine1 = manager.getEngineByName(ENGINE_TO_TEST); assertThat(engine1.getBindings(ScriptContext.GLOBAL_SCOPE).size(), is(1)); assertEquals(101, (int) engine1.eval("x+1")); manager.getBindings().remove("x"); final GremlinScriptEngine engine2 = manager.getEngineByName(ENGINE_TO_TEST); assertThat(engine2.getBindings(ScriptContext.GLOBAL_SCOPE).size(), is(0)); }
@Test public void shouldAddLazyGlobalBindingsViaPlugin() throws Exception { final Bindings bindings = new SimpleBindings(); bindings.put("x", 100); final BindingsGremlinPlugin plugin = new BindingsGremlinPlugin(() -> bindings); final DefaultGremlinScriptEngineManager manager = new DefaultGremlinScriptEngineManager(); manager.addPlugin(plugin); final GremlinScriptEngine engine = manager.getEngineByName(ENGINE_TO_TEST); assertThat(engine.getBindings(ScriptContext.GLOBAL_SCOPE).size(), is(1)); assertEquals(101, (int) engine.eval("x+1")); }
/** * Serializes this {@link Bindings} instance into a JSON formatted StringBuilder {@code target} * with the specified {@code indent} of spaces. * * @param target A {@link StringBuilder} to write the JSON in * @param margin The margin of spaces to indent the resulting block of JSON */ public static void toJson( @This Bindings thiz, StringBuilder target, int margin ) { int iKey = 0; if( isNewLine( target ) ) { indent( target, margin ); } if( thiz.size() > 0 ) { target.append( "{\n" ); for( String key: thiz.keySet() ) { indent( target, margin + 2 ); target.append( '\"' ).append( key ).append( '\"' ).append( ": " ); Object value = thiz.get( key ); JsonUtil.toJson( target, margin, value ); appendCommaNewLine( target, iKey < thiz.size() - 1 ); iKey++; } } indent( target, margin ); target.append( "}" ); }
if( thiz.size() > 0 )
if( ((Bindings)elem).size() == 1 && ((Bindings)elem).containsKey( JSCH_REQUIRED ) )
if( elemBindings.size() == 1 && elemBindings.containsKey( JSCH_REQUIRED ) )