KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > components > persistence > RequestDataStoreImpl


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.components.persistence;
17
18 import java.util.HashMap JavaDoc;
19 import java.util.Map JavaDoc;
20
21 import org.apache.avalon.framework.component.Component;
22 import org.apache.avalon.framework.context.Context;
23 import org.apache.avalon.framework.context.ContextException;
24 import org.apache.avalon.framework.context.Contextualizable;
25 import org.apache.avalon.framework.logger.AbstractLogEnabled;
26 import org.apache.avalon.framework.thread.ThreadSafe;
27 import org.apache.cocoon.components.ContextHelper;
28 import org.apache.cocoon.environment.ObjectModelHelper;
29
30 /**
31  * The default implementation
32  *
33  * @author <a HREF="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
34  *
35  * @version CVS $Id: RequestDataStoreImpl.java 30932 2004-07-29 17:35:38Z vgritsenko $
36  * @since 2.1.1
37  */

38 public class RequestDataStoreImpl
39     extends AbstractLogEnabled
40     implements Component, ThreadSafe, RequestDataStore, Contextualizable {
41         
42     protected Context context;
43
44     protected final String JavaDoc requestDataKey = this.getClass().getName() + "/RD";
45     
46     protected final String JavaDoc globalRequestDataKey = this.getClass().getName() + "/GRD";
47     
48     /* (non-Javadoc)
49      * @see org.apache.avalon.framework.context.Contextualizable#contextualize(org.apache.avalon.framework.context.Context)
50      */

51     public void contextualize(Context context) throws ContextException {
52         this.context = context;
53     }
54
55     /* (non-Javadoc)
56      * @see org.apache.cocoon.components.persistance.RequestDataStore#getGlobalRequestData(java.lang.String)
57      */

58     public Object JavaDoc getGlobalRequestData(String JavaDoc key) {
59         Object JavaDoc value = null;
60         final Map JavaDoc objectModel = ContextHelper.getObjectModel(this.context);
61         Map JavaDoc m = (Map JavaDoc)objectModel.get(this.globalRequestDataKey);
62         if ( m != null ) {
63             value = m.get( key );
64         }
65         return value;
66     }
67
68     /* (non-Javadoc)
69      * @see org.apache.cocoon.components.persistance.RequestDataStore#getRequestData(java.lang.String)
70      */

71     public Object JavaDoc getRequestData(String JavaDoc key) {
72         Object JavaDoc value = null;
73         final Map JavaDoc objectModel = ContextHelper.getObjectModel(this.context);
74         Map JavaDoc m = (Map JavaDoc)objectModel.get(this.requestDataKey + ObjectModelHelper.getRequest(objectModel).hashCode());
75         if ( m != null ) {
76             value = m.get( key );
77         }
78         return value;
79     }
80
81     /* (non-Javadoc)
82      * @see org.apache.cocoon.components.persistance.RequestDataStore#removeGlobalRequestData(java.lang.String)
83      */

84     public void removeGlobalRequestData(String JavaDoc key) {
85         final Map JavaDoc objectModel = ContextHelper.getObjectModel(this.context);
86         Map JavaDoc m = (Map JavaDoc)objectModel.get(this.globalRequestDataKey);
87         if ( m != null ) {
88             objectModel.remove( key );
89         }
90     }
91
92     /* (non-Javadoc)
93      * @see org.apache.cocoon.components.persistance.RequestDataStore#removeRequestData(java.lang.String)
94      */

95     public void removeRequestData(String JavaDoc key) {
96         final Map JavaDoc objectModel = ContextHelper.getObjectModel(this.context);
97         Map JavaDoc m = (Map JavaDoc)objectModel.get(this.requestDataKey + ObjectModelHelper.getRequest(objectModel).hashCode());
98         if ( m != null ) {
99             objectModel.remove( key );
100         }
101     }
102
103     /* (non-Javadoc)
104      * @see org.apache.cocoon.components.persistance.RequestDataStore#setGlobalRequestData(java.lang.String, java.lang.Object)
105      */

106     public void setGlobalRequestData(String JavaDoc key, Object JavaDoc value) {
107         final Map JavaDoc objectModel = ContextHelper.getObjectModel(this.context);
108         Map JavaDoc m = (Map JavaDoc)objectModel.get(this.globalRequestDataKey);
109         if ( m == null ) {
110             m = new HashMap JavaDoc();
111             objectModel.put(this.globalRequestDataKey, m);
112         }
113         m.put(key, value);
114     }
115
116     /* (non-Javadoc)
117      * @see org.apache.cocoon.components.persistance.RequestDataStore#setRequestData(java.lang.String, java.lang.Object)
118      */

119     public void setRequestData(String JavaDoc key, Object JavaDoc value) {
120         final Map JavaDoc objectModel = ContextHelper.getObjectModel(this.context);
121         Map JavaDoc m = (Map JavaDoc)objectModel.get(this.requestDataKey + ObjectModelHelper.getRequest(objectModel).hashCode());
122         if ( m == null ) {
123             m = new HashMap JavaDoc();
124             objectModel.put(this.requestDataKey + ObjectModelHelper.getRequest(objectModel).hashCode(), m);
125         }
126         m.put(key, value);
127     }
128
129 }
130
Popular Tags