KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis2 > context > AbstractContext


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

23
24 public abstract class AbstractContext implements Serializable JavaDoc {
25
26     protected transient final HashMap JavaDoc nonPersistentMap;
27     protected final HashMap JavaDoc persistentMap;
28     protected AbstractContext parent;
29
30     protected AbstractContext(AbstractContext parent) {
31         this.persistentMap = new HashMap JavaDoc();
32         this.nonPersistentMap = new HashMap JavaDoc();
33         this.parent = parent;
34     }
35
36     /**
37      * Store an object. depending on the persistent flag the
38      * object is either saved in the persistent way or the non-persistent
39      * way
40      *
41      * @param key
42      * @param value
43      * @param persistent
44      */

45     public void setProperty(String JavaDoc key, Object JavaDoc value, boolean persistent) {
46         if (persistent) {
47             persistentMap.put(key, value);
48         } else {
49             nonPersistentMap.put(key, value);
50         }
51     }
52
53     /**
54      * Store an object with the default persistent flag.
55      * default is no persistance
56      *
57      * @param key
58      * @param value
59      */

60     public void setProperty(String JavaDoc key, Object JavaDoc value) {
61         this.setProperty(key, value, false);
62     }
63
64     /**
65      * Retrieve an object. Default search is done in the non persistent
66      * group
67      *
68      * @param key
69      * @return
70      */

71     public Object JavaDoc getProperty(String JavaDoc key) {
72         return this.getProperty(key, false);
73     }
74
75     /**
76      * @param key
77      * @param persistent
78      * @return
79      */

80     public Object JavaDoc getProperty(String JavaDoc key, boolean persistent) {
81         Object JavaDoc obj = null;
82         if (persistent) {
83             obj = persistentMap.get(key);
84         }
85         if(obj == null){
86             obj = nonPersistentMap.get(key);
87         }
88         if (obj == null && parent != null) {
89             obj = parent.getProperty(key, persistent);
90         }
91         return obj;
92     }
93     /**
94      * @param context
95      */

96     public void setParent(AbstractContext context) {
97         parent = context;
98     }
99
100     /**
101      * @return
102      */

103     public AbstractContext getParent() {
104         return parent;
105     }
106
107 }
108
Popular Tags