1 16 package org.apache.cocoon.components.persistence; 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.thread.ThreadSafe; 27 import org.apache.cocoon.components.ContextHelper; 28 import org.apache.cocoon.environment.ObjectModelHelper; 29 30 38 public class RequestDataStoreImpl 39 extends AbstractLogEnabled 40 implements Component, ThreadSafe, RequestDataStore, Contextualizable { 41 42 protected Context context; 43 44 protected final String requestDataKey = this.getClass().getName() + "/RD"; 45 46 protected final String globalRequestDataKey = this.getClass().getName() + "/GRD"; 47 48 51 public void contextualize(Context context) throws ContextException { 52 this.context = context; 53 } 54 55 58 public Object getGlobalRequestData(String key) { 59 Object value = null; 60 final Map objectModel = ContextHelper.getObjectModel(this.context); 61 Map m = (Map )objectModel.get(this.globalRequestDataKey); 62 if ( m != null ) { 63 value = m.get( key ); 64 } 65 return value; 66 } 67 68 71 public Object getRequestData(String key) { 72 Object value = null; 73 final Map objectModel = ContextHelper.getObjectModel(this.context); 74 Map m = (Map )objectModel.get(this.requestDataKey + ObjectModelHelper.getRequest(objectModel).hashCode()); 75 if ( m != null ) { 76 value = m.get( key ); 77 } 78 return value; 79 } 80 81 84 public void removeGlobalRequestData(String key) { 85 final Map objectModel = ContextHelper.getObjectModel(this.context); 86 Map m = (Map )objectModel.get(this.globalRequestDataKey); 87 if ( m != null ) { 88 objectModel.remove( key ); 89 } 90 } 91 92 95 public void removeRequestData(String key) { 96 final Map objectModel = ContextHelper.getObjectModel(this.context); 97 Map m = (Map )objectModel.get(this.requestDataKey + ObjectModelHelper.getRequest(objectModel).hashCode()); 98 if ( m != null ) { 99 objectModel.remove( key ); 100 } 101 } 102 103 106 public void setGlobalRequestData(String key, Object value) { 107 final Map objectModel = ContextHelper.getObjectModel(this.context); 108 Map m = (Map )objectModel.get(this.globalRequestDataKey); 109 if ( m == null ) { 110 m = new HashMap (); 111 objectModel.put(this.globalRequestDataKey, m); 112 } 113 m.put(key, value); 114 } 115 116 119 public void setRequestData(String key, Object value) { 120 final Map objectModel = ContextHelper.getObjectModel(this.context); 121 Map m = (Map )objectModel.get(this.requestDataKey + ObjectModelHelper.getRequest(objectModel).hashCode()); 122 if ( m == null ) { 123 m = new HashMap (); 124 objectModel.put(this.requestDataKey + ObjectModelHelper.getRequest(objectModel).hashCode(), m); 125 } 126 m.put(key, value); 127 } 128 129 } 130 | Popular Tags |