KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > portal > aspect > impl > TemporaryAspectDataStore


1 /*
2  * Copyright 1999-2002,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.portal.aspect.impl;
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.service.ServiceException;
27 import org.apache.avalon.framework.service.ServiceManager;
28 import org.apache.avalon.framework.service.Serviceable;
29 import org.apache.avalon.framework.thread.ThreadSafe;
30 import org.apache.cocoon.components.ContextHelper;
31 import org.apache.cocoon.environment.Request;
32 import org.apache.cocoon.portal.aspect.AspectDataStore;
33 import org.apache.cocoon.portal.aspect.Aspectalizable;
34
35 /**
36  * An aspect data store is a component that manages aspect data objects.
37  * This store holds the data for the current request.
38  *
39  * @author <a HREF="mailto:cziegeler@s-und-n.de">Carsten Ziegeler</a>
40  *
41  * @version CVS $Id: TemporaryAspectDataStore.java 30932 2004-07-29 17:35:38Z vgritsenko $
42  */

43 public class TemporaryAspectDataStore
44     extends AbstractLogEnabled
45     implements Component, Serviceable, ThreadSafe, AspectDataStore, Contextualizable {
46     
47     protected Context context;
48     
49     protected ServiceManager manager;
50     
51     /* (non-Javadoc)
52      * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
53      */

54     public void service(ServiceManager manager) throws ServiceException {
55         this.manager = manager;
56     }
57
58     protected Map JavaDoc getMap(Aspectalizable owner) {
59         final Request request = ContextHelper.getRequest(this.context);
60         Map JavaDoc componentMap = (Map JavaDoc)request.getAttribute(this.getClass().getName());
61         if ( componentMap == null) {
62             componentMap = new HashMap JavaDoc(3);
63             request.setAttribute(this.getClass().getName(), componentMap);
64         }
65         Map JavaDoc ownerMap = (Map JavaDoc)componentMap.get( owner );
66         if ( ownerMap == null ) {
67             ownerMap = new HashMap JavaDoc(3);
68             componentMap.put( owner, ownerMap );
69         }
70         return ownerMap;
71     }
72     
73     public Object JavaDoc getAspectData(Aspectalizable owner, String JavaDoc aspectName) {
74         return this.getMap(owner).get( aspectName );
75     }
76     
77     public void setAspectData(Aspectalizable owner, String JavaDoc aspectName, Object JavaDoc data) {
78         this.getMap(owner).put(aspectName, data);
79     }
80
81     public boolean isPersistent() {
82         return false;
83     }
84     
85     /* (non-Javadoc)
86      * @see org.apache.avalon.framework.context.Contextualizable#contextualize(org.apache.avalon.framework.context.Context)
87      */

88     public void contextualize(Context context) throws ContextException {
89         this.context = context;
90
91     }
92
93 }
94
Popular Tags