KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > opensymphony > webwork > util > AttributeMap


1 /*
2  * Copyright (c) 2002-2003 by OpenSymphony
3  * All rights reserved.
4  */

5 package com.opensymphony.webwork.util;
6
7 import com.opensymphony.webwork.ServletActionContext;
8
9 import javax.servlet.jsp.PageContext JavaDoc;
10 import java.util.Collection JavaDoc;
11 import java.util.Map JavaDoc;
12 import java.util.Set JavaDoc;
13
14
15 /**
16  * User: plightbo
17  * Date: Nov 13, 2003
18  * Time: 6:29:49 PM
19  */

20 public class AttributeMap implements Map JavaDoc {
21     //~ Static fields/initializers /////////////////////////////////////////////
22

23     protected static final String JavaDoc UNSUPPORTED = "method makes no sense for a simplified map";
24
25     //~ Instance fields ////////////////////////////////////////////////////////
26

27     Map JavaDoc context;
28
29     //~ Constructors ///////////////////////////////////////////////////////////
30

31     public AttributeMap(Map JavaDoc context) {
32         this.context = context;
33     }
34
35     //~ Methods ////////////////////////////////////////////////////////////////
36

37     public boolean isEmpty() {
38         throw new UnsupportedOperationException JavaDoc(UNSUPPORTED);
39     }
40
41     public void clear() {
42         throw new UnsupportedOperationException JavaDoc(UNSUPPORTED);
43     }
44
45     public boolean containsKey(Object JavaDoc key) {
46         return (get(key) != null);
47     }
48
49     public boolean containsValue(Object JavaDoc value) {
50         throw new UnsupportedOperationException JavaDoc(UNSUPPORTED);
51     }
52
53     public Set JavaDoc entrySet() {
54         throw new UnsupportedOperationException JavaDoc(UNSUPPORTED);
55     }
56
57     public Object JavaDoc get(Object JavaDoc key) {
58         PageContext JavaDoc pc = getPageContext();
59
60         if (pc == null) {
61             Map JavaDoc request = (Map JavaDoc) context.get("request");
62             Map JavaDoc session = (Map JavaDoc) context.get("session");
63             Map JavaDoc application = (Map JavaDoc) 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 JavaDoc keySet() {
80         throw new UnsupportedOperationException JavaDoc(UNSUPPORTED);
81     }
82
83     public Object JavaDoc put(Object JavaDoc key, Object JavaDoc value) {
84         throw new UnsupportedOperationException JavaDoc(UNSUPPORTED);
85     }
86
87     public void putAll(Map JavaDoc t) {
88         throw new UnsupportedOperationException JavaDoc(UNSUPPORTED);
89     }
90
91     public Object JavaDoc remove(Object JavaDoc key) {
92         throw new UnsupportedOperationException JavaDoc(UNSUPPORTED);
93     }
94
95     public int size() {
96         throw new UnsupportedOperationException JavaDoc(UNSUPPORTED);
97     }
98
99     public Collection JavaDoc values() {
100         throw new UnsupportedOperationException JavaDoc(UNSUPPORTED);
101     }
102
103     private PageContext JavaDoc getPageContext() {
104         return (PageContext JavaDoc) context.get(ServletActionContext.PAGE_CONTEXT);
105     }
106 }
107
Popular Tags