< prev index next >

src/java.scripting/share/classes/javax/script/SimpleScriptContext.java

Print this page

        

*** 138,147 **** --- 138,148 ---- * null if no attribute with the name exists in any scope. * @throws NullPointerException if the name is null. * @throws IllegalArgumentException if the name is empty. */ public Object getAttribute(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); }
*** 160,170 **** * @throws IllegalArgumentException * if the name is empty or if the value of scope is invalid. * @throws NullPointerException if the name is null. */ public Object getAttribute(String name, int scope) { ! switch (scope) { case ENGINE_SCOPE: return engineScope.get(name); --- 161,171 ---- * @throws IllegalArgumentException * if the name is empty or if the value of scope is invalid. * @throws NullPointerException if the name is null. */ public Object getAttribute(String name, int scope) { ! checkName(name); switch (scope) { case ENGINE_SCOPE: return engineScope.get(name);
*** 189,199 **** * @throws IllegalArgumentException * if the name is empty or if the scope is invalid. * @throws NullPointerException if the name is null. */ public Object removeAttribute(String name, int scope) { ! switch (scope) { case ENGINE_SCOPE: if (getBindings(ENGINE_SCOPE) != null) { return getBindings(ENGINE_SCOPE).remove(name); --- 190,200 ---- * @throws IllegalArgumentException * if the name is empty or if the scope is invalid. * @throws NullPointerException if the name is null. */ public Object removeAttribute(String name, int scope) { ! checkName(name); switch (scope) { case ENGINE_SCOPE: if (getBindings(ENGINE_SCOPE) != null) { return getBindings(ENGINE_SCOPE).remove(name);
*** 221,231 **** * @throws IllegalArgumentException * if the name is empty or if the scope is invalid. * @throws NullPointerException if the name is null. */ public void setAttribute(String name, Object value, int scope) { ! switch (scope) { case ENGINE_SCOPE: engineScope.put(name, value); return; --- 222,232 ---- * @throws IllegalArgumentException * if the name is empty or if the scope is invalid. * @throws NullPointerException if the name is null. */ public void setAttribute(String name, Object value, int scope) { ! checkName(name); switch (scope) { case ENGINE_SCOPE: engineScope.put(name, value); return;
*** 279,288 **** --- 280,290 ---- * name is defined in any scope. * @throws NullPointerException if name is null. * @throws IllegalArgumentException if name is empty. */ public int getAttributesScope(String name) { + checkName(name); if (engineScope.containsKey(name)) { return ENGINE_SCOPE; } else if (globalScope != null && globalScope.containsKey(name)) { return GLOBAL_SCOPE; } else {
*** 312,321 **** --- 314,330 ---- /** {@inheritDoc} */ public List<Integer> getScopes() { return scopes; } + private void checkName(String name) { + Objects.requireNonNull(name); + if (name.isEmpty()) { + throw new IllegalArgumentException("name cannot be empty"); + } + } + private static List<Integer> scopes; static { scopes = new ArrayList<Integer>(2); scopes.add(ENGINE_SCOPE); scopes.add(GLOBAL_SCOPE);
< prev index next >