/** * Creates the {@code ScriptContext} using a {@link GremlinScriptContext} which avoids a significant amount of * additional object creation on script evaluation. */ @Override protected ScriptContext getScriptContext(final Bindings nn) { final GremlinScriptContext ctxt = new GremlinScriptContext(context.getReader(), context.getWriter(), context.getErrorWriter()); final Bindings gs = getBindings(ScriptContext.GLOBAL_SCOPE); if (gs != null) ctxt.setBindings(gs, ScriptContext.GLOBAL_SCOPE); if (nn != null) { ctxt.setBindings(nn, ScriptContext.ENGINE_SCOPE); } else { throw new NullPointerException("Engine scope Bindings may not be null."); } return ctxt; }
/** * {@inheritDoc} */ @Override public Object getAttribute(final String name) { checkName(name); if (engineScope.containsKey(name)) { return getAttribute(name, ENGINE_SCOPE); } else if (globalScope != null && globalScope.containsKey(name)) { return getAttribute(name, GLOBAL_SCOPE); } return null; }
/** * {@inheritDoc} */ @Override public Object removeAttribute(final String name, final int scope) { checkName(name); switch (scope) { case ENGINE_SCOPE: return getBindings(ENGINE_SCOPE) != null ? getBindings(ENGINE_SCOPE).remove(name) : null; case GLOBAL_SCOPE: return getBindings(GLOBAL_SCOPE) != null ? getBindings(GLOBAL_SCOPE).remove(name) : null; default: throw new IllegalArgumentException("Illegal scope value."); } }
/** * {@inheritDoc} */ @Override public void setAttribute(final String name, final Object value, final int scope) { checkName(name); switch (scope) { case ENGINE_SCOPE: engineScope.put(name, value); return; case GLOBAL_SCOPE: if (globalScope != null) globalScope.put(name, value); return; default: throw new IllegalArgumentException("Illegal scope value."); } }
/** * {@inheritDoc} */ @Override public Object getAttribute(final String name, final int scope) { checkName(name); switch (scope) { case ENGINE_SCOPE: return engineScope.get(name); case GLOBAL_SCOPE: return globalScope != null ? globalScope.get(name) : null; default: throw new IllegalArgumentException("Illegal scope value."); } }
/** * {@inheritDoc} */ @Override public Object getAttribute(final String name) { checkName(name); if (engineScope.containsKey(name)) { return getAttribute(name, ENGINE_SCOPE); } else if (globalScope != null && globalScope.containsKey(name)) { return getAttribute(name, GLOBAL_SCOPE); } return null; }
/** * Creates the {@code ScriptContext} using a {@link GremlinScriptContext} which avoids a significant amount of * additional object creation on script evaluation. */ @Override protected ScriptContext getScriptContext(final Bindings nn) { final GremlinScriptContext ctxt = new GremlinScriptContext(context.getReader(), context.getWriter(), context.getErrorWriter()); final Bindings gs = getBindings(ScriptContext.GLOBAL_SCOPE); if (gs != null) ctxt.setBindings(gs, ScriptContext.GLOBAL_SCOPE); if (nn != null) { ctxt.setBindings(nn, ScriptContext.ENGINE_SCOPE); } else { throw new NullPointerException("Engine scope Bindings may not be null."); } return ctxt; }
/** * {@inheritDoc} */ @Override public Object removeAttribute(final String name, final int scope) { checkName(name); switch (scope) { case ENGINE_SCOPE: return getBindings(ENGINE_SCOPE) != null ? getBindings(ENGINE_SCOPE).remove(name) : null; case GLOBAL_SCOPE: return getBindings(GLOBAL_SCOPE) != null ? getBindings(GLOBAL_SCOPE).remove(name) : null; default: throw new IllegalArgumentException("Illegal scope value."); } }
/** * {@inheritDoc} */ @Override public int getAttributesScope(final String name) { checkName(name); if (engineScope.containsKey(name)) return ENGINE_SCOPE; else if (globalScope != null && globalScope.containsKey(name)) return GLOBAL_SCOPE; else return -1; }
/** * {@inheritDoc} */ @Override public void setAttribute(final String name, final Object value, final int scope) { checkName(name); switch (scope) { case ENGINE_SCOPE: engineScope.put(name, value); return; case GLOBAL_SCOPE: if (globalScope != null) globalScope.put(name, value); return; default: throw new IllegalArgumentException("Illegal scope value."); } }
/** * {@inheritDoc} */ @Override public Object getAttribute(final String name, final int scope) { checkName(name); switch (scope) { case ENGINE_SCOPE: return engineScope.get(name); case GLOBAL_SCOPE: return globalScope != null ? globalScope.get(name) : null; default: throw new IllegalArgumentException("Illegal scope value."); } }
/** * {@inheritDoc} */ @Override public int getAttributesScope(final String name) { checkName(name); if (engineScope.containsKey(name)) return ENGINE_SCOPE; else if (globalScope != null && globalScope.containsKey(name)) return GLOBAL_SCOPE; else return -1; }