1 24 package org.riotfamily.components.context; 25 26 import java.io.Serializable ; 27 import java.util.HashMap ; 28 import java.util.Iterator ; 29 import java.util.Map ; 30 31 public class ContextMap implements Serializable { 32 33 private transient Map map; 34 35 public void removeExpiredContexts() { 36 if (map != null) { 37 Iterator it = map.values().iterator(); 38 while (it.hasNext()) { 39 PageRequestContexts contexts = (PageRequestContexts) it.next(); 40 if (contexts.isExpired()) { 41 it.remove(); 42 } 43 } 44 } 45 } 46 47 public void touch(String pageUri) { 48 if (map != null) { 49 PageRequestContexts contexts = (PageRequestContexts) map.get(pageUri); 50 if (contexts != null) { 51 contexts.touch(); 52 } 53 } 54 } 55 56 public void put(String pageUri, Object contextKey, 57 PageRequestContext context, long timeToLive) { 58 59 if (map == null) { 60 map = new HashMap (); 61 } 62 PageRequestContexts contexts = (PageRequestContexts) map.get(pageUri); 63 if (contexts == null) { 64 contexts = new PageRequestContexts(timeToLive); 65 map.put(pageUri, contexts); 66 } 67 contexts.put(contextKey, context); 68 } 69 70 public PageRequestContext get(String pageUri, Object contextKey) { 71 if (map == null) { 72 return null; 73 } 74 PageRequestContexts contexts = (PageRequestContexts) map.get(pageUri); 75 if (contexts == null) { 76 return null; 77 } 78 return contexts.get(contextKey); 79 } 80 81 } 82 | Popular Tags |