KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > faces > context > ApplicationMap


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.cocoon.faces.context;
17
18 import org.apache.cocoon.environment.Context;
19
20 import java.util.Enumeration JavaDoc;
21 import java.util.HashSet JavaDoc;
22 import java.util.Set JavaDoc;
23
24 /**
25  * Application context attributes map
26  *
27  * @author <a HREF="mailto:vgritsenko@apache.org">Vadim Gritsenko</a>
28  * @version CVS $Id: ApplicationMap.java 46253 2004-09-17 14:36:29Z vgritsenko $
29  */

30 class ApplicationMap extends BaseMap {
31
32     private Context context;
33
34
35     ApplicationMap(Context context) {
36         this.context = context;
37     }
38
39     public Object JavaDoc get(Object JavaDoc key) {
40         return context.getAttribute(key.toString());
41     }
42
43     public Object JavaDoc put(Object JavaDoc key, Object JavaDoc value) {
44         String JavaDoc sKey = key.toString();
45         Object JavaDoc old = context.getAttribute(sKey);
46         context.setAttribute(sKey, value);
47         return old;
48     }
49
50     public Object JavaDoc remove(Object JavaDoc key) {
51         String JavaDoc sKey = key.toString();
52         Object JavaDoc old = context.getAttribute(sKey);
53         context.removeAttribute(sKey);
54         return old;
55     }
56
57     public Set JavaDoc entrySet() {
58         Set JavaDoc entries = new HashSet JavaDoc();
59         for (Enumeration JavaDoc e = context.getAttributeNames(); e.hasMoreElements();) {
60             String JavaDoc name = (String JavaDoc) e.nextElement();
61             entries.add(new BaseMap.Entry(name, context.getAttribute(name)));
62         }
63
64         return entries;
65     }
66
67     public boolean equals(Object JavaDoc obj) {
68         if (obj == null || !(obj instanceof ApplicationMap)) {
69             return false;
70         }
71
72         return super.equals(obj);
73     }
74 }
75
Popular Tags