1 16 package org.apache.cocoon.portal.aspect.impl; 17 18 import java.util.HashMap ; 19 import java.util.Map ; 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 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 54 public void service(ServiceManager manager) throws ServiceException { 55 this.manager = manager; 56 } 57 58 protected Map getMap(Aspectalizable owner) { 59 final Request request = ContextHelper.getRequest(this.context); 60 Map componentMap = (Map )request.getAttribute(this.getClass().getName()); 61 if ( componentMap == null) { 62 componentMap = new HashMap (3); 63 request.setAttribute(this.getClass().getName(), componentMap); 64 } 65 Map ownerMap = (Map )componentMap.get( owner ); 66 if ( ownerMap == null ) { 67 ownerMap = new HashMap (3); 68 componentMap.put( owner, ownerMap ); 69 } 70 return ownerMap; 71 } 72 73 public Object getAspectData(Aspectalizable owner, String aspectName) { 74 return this.getMap(owner).get( aspectName ); 75 } 76 77 public void setAspectData(Aspectalizable owner, String aspectName, Object data) { 78 this.getMap(owner).put(aspectName, data); 79 } 80 81 public boolean isPersistent() { 82 return false; 83 } 84 85 88 public void contextualize(Context context) throws ContextException { 89 this.context = context; 90 91 } 92 93 } 94 | Popular Tags |