1 20 package org.enhydra.barracuda.plankton.data; 21 22 import java.io.*; 23 import java.util.*; 24 import javax.servlet.*; 25 import javax.servlet.http.*; 26 27 34 public class ServletRequestParameterStateMap implements StateMap { 35 36 protected ServletRequest request = null; 38 private String NULL = "~Null~"; 39 40 45 public ServletRequestParameterStateMap(ServletRequest irequest) { 46 request = irequest; 47 } 48 49 56 public void putState(Object key, Object val) { 57 throw new UnsupportedOperationException (); } 59 60 68 public Object getState(Object key) { 69 if (key==null) key = NULL; 70 Object [] vals = request.getParameterValues(key.toString()); 71 if (vals==null) return null; 72 else if (vals.length==1) return (vals[0].equals(NULL) ? null : vals[0]); 73 else { 74 List list = new ArrayList(); 75 for (int i=0, max=vals.length; i<max; i++) { 76 list.add(vals[i]); 77 } 78 return list; 79 } 80 } 81 82 89 public Object removeState(Object key) { 90 throw new UnsupportedOperationException (); } 93 94 100 public List getStateKeys() { 101 Enumeration e = request.getParameterNames(); 102 List list = new ArrayList(); 103 while (e.hasMoreElements()) { 104 list.add(e.nextElement()); 105 } 106 return list; 107 } 108 109 116 public Map getStateValues() { 117 Map map = new HashMap(); 118 List keys = getStateKeys(); 120 Iterator it = keys.iterator(); 121 while (it.hasNext()) { 122 Object key = it.next(); 123 Object val = getState(key); 124 map.put(key,val); 125 } 126 return map; 127 } 128 129 133 public void clearState() { 134 throw new UnsupportedOperationException (); 135 } 136 137 142 public ServletRequest getRequest() { 143 return request; 144 } 145 } 146 | Popular Tags |