KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.apache.avalon.framework.component.Component;
19 import org.apache.avalon.framework.context.Context;
20 import org.apache.avalon.framework.context.ContextException;
21 import org.apache.avalon.framework.context.Contextualizable;
22 import org.apache.avalon.framework.logger.AbstractLogEnabled;
23 import org.apache.avalon.framework.thread.ThreadSafe;
24 import org.apache.cocoon.components.ContextHelper;
25 import org.apache.cocoon.environment.Session;
26 import org.apache.cocoon.portal.aspect.AspectDataStore;
27 import org.apache.cocoon.portal.aspect.Aspectalizable;
28
29 /**
30  * An aspect data store is a component that manages aspect data objects.
31  *
32  * @author <a HREF="mailto:cziegeler@s-und-n.de">Carsten Ziegeler</a>
33  *
34  * @version CVS $Id: SessionAspectDataStore.java 30932 2004-07-29 17:35:38Z vgritsenko $
35  */

36 public class SessionAspectDataStore
37     extends AbstractLogEnabled
38     implements Component, ThreadSafe, AspectDataStore, Contextualizable {
39     
40     protected Context context;
41     
42     protected String JavaDoc getKey(Aspectalizable owner, String JavaDoc aspectName) {
43         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc(this.getClass().getName());
44         buffer.append('/');
45         buffer.append(owner.getClass().getName());
46         buffer.append('/');
47         buffer.append(owner.hashCode());
48         buffer.append('/');
49         buffer.append(aspectName);
50         return buffer.toString();
51     }
52     
53     public Object JavaDoc getAspectData(Aspectalizable owner, String JavaDoc aspectName) {
54         final Session session = ContextHelper.getRequest(this.context).getSession();
55         return session.getAttribute( this.getKey( owner, aspectName ) );
56     }
57     
58     public void setAspectData(Aspectalizable owner, String JavaDoc aspectName, Object JavaDoc data) {
59         final Session session = ContextHelper.getRequest(this.context).getSession();
60         if ( data == null ) {
61             session.removeAttribute( this.getKey( owner, aspectName) );
62         } else {
63             session.setAttribute( this.getKey( owner, aspectName), data );
64         }
65     }
66
67     public boolean isPersistent() {
68         return false;
69     }
70
71     /* (non-Javadoc)
72      * @see org.apache.avalon.framework.context.Contextualizable#contextualize(org.apache.avalon.framework.context.Context)
73      */

74     public void contextualize(Context context) throws ContextException {
75         this.context = context;
76
77     }
78
79 }
80
Popular Tags