예제 #1
0
  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++];
      }
    };
  }
예제 #2
0
 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);
   }
 }
예제 #3
0
 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);
   }
 }
예제 #4
0
 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);
     }
   }
 }