public Enumeration getAttributeNamesInScope(int scope) { Set keys; switch (scope) { case PAGE_SCOPE: keys = pageScopeMap.keySet(); break; case APPLICATION_SCOPE: return appCtx.getAttributeNames(); default: throw new IllegalArgumentException("invalid scope: " + scope); } final String[] array = (String[]) keys.toArray(new String[keys.size()]); return new Enumeration() { private int next = 0; public boolean hasMoreElements() { if (next >= array.length) { return false; } else { return true; } } public Object nextElement() throws NoSuchElementException { if (!hasMoreElements()) { throw new NoSuchElementException("no more elements."); } return array[next++]; } }; }
public Object getAttribute(String name, int scope) { switch (scope) { case PAGE_SCOPE: return pageScopeMap.get(name); case APPLICATION_SCOPE: return appCtx.getAttribute(name); default: throw new IllegalArgumentException("invalid scope: " + scope); } }
public void removeAttribute(String name, int scope) { switch (scope) { case PAGE_SCOPE: pageScopeMap.remove(name); break; case APPLICATION_SCOPE: appCtx.removeAttribute(name); break; default: throw new IllegalArgumentException("invalid scope: " + scope); } }
public void setAttribute(String name, Object obj, int scope) { if (null == obj) { removeAttribute(name, scope); } else { switch (scope) { case PAGE_SCOPE: pageScopeMap.put(name, obj); break; case APPLICATION_SCOPE: appCtx.setAttribute(name, obj); break; default: throw new IllegalArgumentException("invalid scope: " + scope); } } }