01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.cocoon.portal.aspect.impl;
18:
19: import org.apache.avalon.framework.component.Component;
20: import org.apache.avalon.framework.context.Context;
21: import org.apache.avalon.framework.context.ContextException;
22: import org.apache.avalon.framework.context.Contextualizable;
23: import org.apache.avalon.framework.logger.AbstractLogEnabled;
24: import org.apache.avalon.framework.thread.ThreadSafe;
25: import org.apache.cocoon.components.ContextHelper;
26: import org.apache.cocoon.environment.Session;
27: import org.apache.cocoon.portal.aspect.AspectDataStore;
28: import org.apache.cocoon.portal.aspect.Aspectalizable;
29:
30: /**
31: * An aspect data store is a component that manages aspect data objects.
32: *
33: * @author <a href="mailto:cziegeler@s-und-n.de">Carsten Ziegeler</a>
34: *
35: * @version CVS $Id: SessionAspectDataStore.java 433543 2006-08-22 06:22:54Z crossley $
36: */
37: public class SessionAspectDataStore extends AbstractLogEnabled
38: implements Component, ThreadSafe, AspectDataStore,
39: Contextualizable {
40:
41: protected Context context;
42:
43: protected String getKey(Aspectalizable owner, String aspectName) {
44: StringBuffer buffer = new StringBuffer(this .getClass()
45: .getName());
46: buffer.append('/');
47: buffer.append(owner.getClass().getName());
48: buffer.append('/');
49: buffer.append(owner.hashCode());
50: buffer.append('/');
51: buffer.append(aspectName);
52: return buffer.toString();
53: }
54:
55: public Object getAspectData(Aspectalizable owner, String aspectName) {
56: final Session session = ContextHelper.getRequest(this .context)
57: .getSession();
58: return session.getAttribute(this .getKey(owner, aspectName));
59: }
60:
61: public void setAspectData(Aspectalizable owner, String aspectName,
62: Object data) {
63: final Session session = ContextHelper.getRequest(this .context)
64: .getSession();
65: if (data == null) {
66: session.removeAttribute(this .getKey(owner, aspectName));
67: } else {
68: session.setAttribute(this .getKey(owner, aspectName), data);
69: }
70: }
71:
72: public boolean isPersistent() {
73: return false;
74: }
75:
76: /* (non-Javadoc)
77: * @see org.apache.avalon.framework.context.Contextualizable#contextualize(org.apache.avalon.framework.context.Context)
78: */
79: public void contextualize(Context context) throws ContextException {
80: this.context = context;
81:
82: }
83:
84: }
|