1 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 36 public class SessionAspectDataStore 37 extends AbstractLogEnabled 38 implements Component, ThreadSafe, AspectDataStore, Contextualizable { 39 40 protected Context context; 41 42 protected String getKey(Aspectalizable owner, String aspectName) { 43 StringBuffer buffer = new StringBuffer (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 getAspectData(Aspectalizable owner, String 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 aspectName, Object 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 74 public void contextualize(Context context) throws ContextException { 75 this.context = context; 76 77 } 78 79 } 80 | Popular Tags |