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 47 public class Property extends AbstractFunction implements Serializable 48 { 49 50 private static final List desc = new LinkedList (); 51 private static final String KEY = "__property"; 52 53 private static final int MIN_PARAMETER_COUNT = 1; 55 private static final int MAX_PARAMETER_COUNT = 3; 56 static { 57 desc.add(JMeterUtils.getResString("property_name_param")); 58 desc.add(JMeterUtils.getResString("function_name_param")); 59 desc.add(JMeterUtils.getResString("property_default_param")); 60 } 61 62 private Object [] values; 63 64 public Property() 65 { 66 } 67 68 public Object clone() 69 { 70 return new Property(); 71 } 72 73 public synchronized String execute( 74 SampleResult previousResult, 75 Sampler currentSampler) 76 throws InvalidVariableException 77 { 78 String propertyName = ((CompoundVariable) values[0]).execute(); 79 String propertyDefault = propertyName; 80 if (values.length > 2){ propertyDefault= ((CompoundVariable) values[2]).execute(); 82 } 83 String propertyValue = 84 JMeterUtils.getPropDefault(propertyName, propertyDefault); 85 if (values.length > 1) 86 { 87 String variableName = ((CompoundVariable) values[1]).execute(); 88 if (variableName.length() > 0){ getVariables().put(variableName, propertyValue); 90 } 91 } 92 return propertyValue; 93 94 } 95 96 public void setParameters(Collection parameters) 97 throws InvalidVariableException 98 { 99 100 values = parameters.toArray(); 101 102 if ((values.length < MIN_PARAMETER_COUNT) 103 || (values.length > MAX_PARAMETER_COUNT)) 104 { 105 throw new InvalidVariableException( 106 "Parameter Count not between " 107 + MIN_PARAMETER_COUNT 108 + " & " 109 + MAX_PARAMETER_COUNT); 110 } 111 112 } 113 114 public String getReferenceKey() 115 { 116 return KEY; 117 } 118 119 public List getArgumentDesc() 120 { 121 return desc; 122 } 123 124 } | Popular Tags |