1 18 19 package org.apache.jmeter.config; 20 21 import java.io.Serializable ; 22 import java.util.ArrayList ; 23 import java.util.HashMap ; 24 import java.util.List ; 25 import java.util.Map ; 26 27 import org.apache.jmeter.testelement.property.CollectionProperty; 28 import org.apache.jmeter.testelement.property.PropertyIterator; 29 import org.apache.jmeter.testelement.property.TestElementProperty; 30 31 36 43 public class Arguments extends ConfigTestElement implements Serializable 44 { 45 46 public static final String ARGUMENTS = "Arguments.arguments"; 47 48 51 public Arguments() 52 { 53 setProperty(new CollectionProperty(ARGUMENTS, new ArrayList ())); 54 } 55 56 61 public CollectionProperty getArguments() 62 { 63 return (CollectionProperty) getProperty(ARGUMENTS); 64 } 65 66 69 public void clear() 70 { 71 super.clear(); 72 setProperty(new CollectionProperty(ARGUMENTS, new ArrayList ())); 73 } 74 75 80 public void setArguments(List arguments) 81 { 82 setProperty(new CollectionProperty(ARGUMENTS, arguments)); 83 } 84 85 91 public Map getArgumentsAsMap() 92 { 93 PropertyIterator iter = getArguments().iterator(); 94 Map argMap = new HashMap (); 95 while (iter.hasNext()) 96 { 97 Argument arg = (Argument) iter.next().getObjectValue(); 98 if (! argMap.containsKey(arg.getName())) argMap.put(arg.getName(), arg.getValue()); 103 } 104 return argMap; 105 } 106 107 113 public void addArgument(String name, String value) 114 { 115 addArgument(new Argument(name, value, null)); 116 } 117 118 123 public void addArgument(Argument arg) 124 { 125 TestElementProperty newArg = 126 new TestElementProperty(arg.getName(), arg); 127 if (isRunningVersion()) 128 { 129 this.setTemporary(newArg); 130 } 131 getArguments().addItem(newArg); 132 } 133 134 141 public void addArgument(String name, String value, String metadata) 142 { 143 addArgument(new Argument(name, value, metadata)); 144 } 145 146 151 public PropertyIterator iterator() 152 { 153 return getArguments().iterator(); 154 } 155 156 161 public String toString() 162 { 163 StringBuffer str = new StringBuffer (); 164 PropertyIterator iter = getArguments().iterator(); 165 while (iter.hasNext()) 166 { 167 Argument arg = (Argument) iter.next().getObjectValue(); 168 if (arg.getMetaData() == null) 169 { 170 str.append(arg.getName() + "=" + arg.getValue()); 171 } 172 else 173 { 174 str.append(arg.getName() + arg.getMetaData() + arg.getValue()); 175 } 176 if (iter.hasNext()) 177 { 178 str.append("&"); 179 } 180 } 181 return str.toString(); 182 } 183 184 189 public void removeArgument(int row) 190 { 191 if (row < getArguments().size()) 192 { 193 getArguments().remove(row); 194 } 195 } 196 197 202 public void removeArgument(Argument arg) 203 { 204 PropertyIterator iter = getArguments().iterator(); 205 while (iter.hasNext()) 206 { 207 Argument item = (Argument) iter.next().getObjectValue(); 208 if (arg.equals(item)) 209 { 210 iter.remove(); 211 } 212 } 213 } 214 215 220 public void removeArgument(String argName) 221 { 222 PropertyIterator iter = getArguments().iterator(); 223 while (iter.hasNext()) 224 { 225 Argument arg = (Argument) iter.next().getObjectValue(); 226 if (arg.getName().equals(argName)) 227 { 228 iter.remove(); 229 } 230 } 231 } 232 233 236 public void removeAllArguments() 237 { 238 getArguments().clear(); 239 } 240 241 245 public void addEmptyArgument() 246 { 247 addArgument(new Argument("", "", null)); 248 } 249 250 255 public int getArgumentCount() 256 { 257 return getArguments().size(); 258 } 259 260 267 public Argument getArgument(int row) 268 { 269 Argument argument = null; 270 271 if (row < getArguments().size()) 272 { 273 argument = (Argument) getArguments().get(row).getObjectValue(); 274 } 275 276 return argument; 277 } 278 } 279 | Popular Tags |