1 20 package org.enhydra.barracuda.plankton.data; 21 22 import java.io.*; 23 import java.util.*; 24 25 import org.apache.log4j.*; 26 27 45 public class DefaultStateMap implements StateMap { 46 47 protected static final Logger logger = Logger.getLogger(DefaultStateMap.class.getName()); 49 50 protected Map props = null; 53 59 public void putState(Object key, Object val) { 60 if (props==null) props = new HashMap(); 61 if (logger.isDebugEnabled()) logger.debug("Setting queue state: [key]:"+key+" [val]:"+val); 62 props.put(key,val); 63 } 64 65 71 public Object getState(Object key) { 72 if (props==null) return null; 73 else return props.get(key); 74 } 75 76 89 public Object removeState(Object key) { 90 94 if (props==null) return null; 96 97 if (key!=null && (key instanceof String ) && ((String ) key).endsWith("*")) { 99 Map removed = new HashMap(); 100 String keystr = (String ) key; 101 String targetstr = keystr.substring(0,keystr.length()-1); 102 List keys = getStateKeys(); 103 Iterator it = keys.iterator(); 104 while (it.hasNext()) { 105 Object okey = it.next(); 106 if ((okey instanceof String ) && ((String ) okey).startsWith(targetstr)) { 107 Object oval = props.get(okey); 108 removed.put(okey, oval); 109 props.remove(okey); 110 } 111 } 112 return (removed.size()>0 ? removed : null); 113 } else { 114 return props.remove(key); 115 } 116 } 118 119 125 public List getStateKeys() { 126 if (props==null) return null; 127 else return new ArrayList(props.keySet()); 128 } 129 130 136 public Map getStateValues() { 137 if (props==null) props = new HashMap(); 138 return new HashMap(props); 139 } 141 142 146 public void clearState() { 147 if (props!=null) props.clear(); 148 } 149 150 } 151 | Popular Tags |