1 18 19 package org.apache.jmeter.functions; 20 21 import java.io.Serializable ; 22 import java.util.Collection ; 23 import java.util.LinkedList ; 24 import java.util.List ; 25 26 import org.apache.jmeter.engine.util.CompoundVariable; 27 import org.apache.jmeter.samplers.SampleResult; 28 import org.apache.jmeter.samplers.Sampler; 29 import org.apache.jmeter.util.JMeterUtils; 30 31 58 public class Property2 extends AbstractFunction implements Serializable 59 { 60 61 private static final List desc = new LinkedList (); 62 private static final String KEY = "__P"; 63 64 private static final int MIN_PARAMETER_COUNT = 1; 66 private static final int MAX_PARAMETER_COUNT = 2; 67 static { 68 desc.add(JMeterUtils.getResString("property_name_param")); 69 desc.add(JMeterUtils.getResString("property_default_param")); 70 } 71 72 private Object [] values; 73 74 public Property2() 75 { 76 } 77 78 public Object clone() 79 { 80 return new Property2(); 81 } 82 83 public synchronized String execute( 84 SampleResult previousResult, 85 Sampler currentSampler) 86 throws InvalidVariableException 87 { 88 String propertyName = ((CompoundVariable) values[0]).execute(); 89 90 String propertyDefault = "1"; if (values.length > 1){ propertyDefault= ((CompoundVariable) values[1]).execute(); 93 } 94 95 String propertyValue = 96 JMeterUtils.getPropDefault(propertyName, propertyDefault); 97 98 return propertyValue; 99 100 } 101 102 public void setParameters(Collection parameters) 103 throws InvalidVariableException 104 { 105 106 values = parameters.toArray(); 107 108 if ((values.length < MIN_PARAMETER_COUNT) 109 || (values.length > MAX_PARAMETER_COUNT)) 110 { 111 throw new InvalidVariableException( 112 "Parameter Count not between " 113 + MIN_PARAMETER_COUNT 114 + " & " 115 + MAX_PARAMETER_COUNT); 116 } 117 118 } 119 120 public String getReferenceKey() 121 { 122 return KEY; 123 } 124 125 public List getArgumentDesc() 126 { 127 return desc; 128 } 129 130 } | Popular Tags |