1 5 package com.opensymphony.webwork.util; 6 7 import com.opensymphony.webwork.ServletActionContext; 8 9 import javax.servlet.jsp.PageContext ; 10 import java.util.Collection ; 11 import java.util.Map ; 12 import java.util.Set ; 13 14 15 20 public class AttributeMap implements Map { 21 23 protected static final String UNSUPPORTED = "method makes no sense for a simplified map"; 24 25 27 Map context; 28 29 31 public AttributeMap(Map context) { 32 this.context = context; 33 } 34 35 37 public boolean isEmpty() { 38 throw new UnsupportedOperationException (UNSUPPORTED); 39 } 40 41 public void clear() { 42 throw new UnsupportedOperationException (UNSUPPORTED); 43 } 44 45 public boolean containsKey(Object key) { 46 return (get(key) != null); 47 } 48 49 public boolean containsValue(Object value) { 50 throw new UnsupportedOperationException (UNSUPPORTED); 51 } 52 53 public Set entrySet() { 54 throw new UnsupportedOperationException (UNSUPPORTED); 55 } 56 57 public Object get(Object key) { 58 PageContext pc = getPageContext(); 59 60 if (pc == null) { 61 Map request = (Map ) context.get("request"); 62 Map session = (Map ) context.get("session"); 63 Map application = (Map ) context.get("application"); 64 65 if ((request != null) && (request.get(key) != null)) { 66 return request.get(key); 67 } else if ((session != null) && (session.get(key) != null)) { 68 return session.get(key); 69 } else if ((application != null) && (application.get(key) != null)) { 70 return application.get(key); 71 } 72 } else { 73 return pc.findAttribute(key.toString()); 74 } 75 76 return null; 77 } 78 79 public Set keySet() { 80 throw new UnsupportedOperationException (UNSUPPORTED); 81 } 82 83 public Object put(Object key, Object value) { 84 throw new UnsupportedOperationException (UNSUPPORTED); 85 } 86 87 public void putAll(Map t) { 88 throw new UnsupportedOperationException (UNSUPPORTED); 89 } 90 91 public Object remove(Object key) { 92 throw new UnsupportedOperationException (UNSUPPORTED); 93 } 94 95 public int size() { 96 throw new UnsupportedOperationException (UNSUPPORTED); 97 } 98 99 public Collection values() { 100 throw new UnsupportedOperationException (UNSUPPORTED); 101 } 102 103 private PageContext getPageContext() { 104 return (PageContext ) context.get(ServletActionContext.PAGE_CONTEXT); 105 } 106 } 107 | Popular Tags |