1 15 package org.apache.tapestry.util; 16 17 import java.util.Arrays ; 18 import java.util.HashMap ; 19 import java.util.Map ; 20 21 import org.apache.hivemind.util.Defense; 22 23 30 public class QueryParameterMap 31 { 32 private final Map _parameters; 33 34 public QueryParameterMap() 35 { 36 this(new HashMap ()); 37 } 38 39 44 45 public QueryParameterMap(Map parameterMap) 46 { 47 Defense.notNull(parameterMap, "parameterMap"); 48 49 _parameters = parameterMap; 50 } 51 52 55 56 public void setParameterValue(String name, String value) 57 { 58 Defense.notNull(name, "name"); 59 60 _parameters.put(name, value); 61 } 62 63 67 68 public void setParameterValues(String name, String [] values) 69 { 70 Defense.notNull(name, "name"); 71 72 _parameters.put(name, values); 73 } 74 75 79 80 public String getParameterValue(String name) 81 { 82 Defense.notNull(name, "name"); 83 84 Object values = _parameters.get(name); 85 86 if (values == null || values instanceof String ) 87 return (String ) values; 88 89 String [] array = (String []) values; 90 91 return array[0]; 92 } 93 94 99 public String [] getParameterValues(String name) 100 { 101 Defense.notNull(name, "name"); 102 103 Object values = _parameters.get(name); 104 105 if (values == null || values instanceof String []) 106 return (String []) values; 107 108 String loneValue = (String ) values; 109 110 return new String [] 111 { loneValue }; 112 } 113 114 117 public String [] getParameterNames() 118 { 119 int count = _parameters.size(); 120 121 String [] result = (String []) _parameters.keySet().toArray(new String [count]); 122 123 Arrays.sort(result); 124 125 return result; 126 } 127 } | Popular Tags |