1 18 19 package org.apache.jmeter.engine; 20 21 import java.util.Map ; 22 23 import org.apache.jmeter.config.Arguments; 24 import org.apache.jmeter.engine.util.ValueReplacer; 25 import org.apache.jmeter.functions.InvalidVariableException; 26 import org.apache.jmeter.testelement.TestElement; 27 import org.apache.jmeter.testelement.TestPlan; 28 import org.apache.jmeter.threads.JMeterContextService; 29 import org.apache.jmeter.threads.JMeterVariables; 30 import org.apache.jorphan.collections.HashTree; 31 import org.apache.jorphan.collections.HashTreeTraverser; 32 import org.apache.jorphan.logging.LoggingManager; 33 import org.apache.log.Logger; 34 35 40 public class PreCompiler implements HashTreeTraverser 41 { 42 transient private static Logger log = LoggingManager.getLoggerForClass(); 43 private ValueReplacer replacer; 44 45 public PreCompiler() 46 { 47 replacer = new ValueReplacer(); 48 } 49 50 53 public void addNode(Object node, HashTree subTree) 54 { 55 if (node instanceof TestPlan) 56 { 57 Map args= ((TestPlan)node).getUserDefinedVariables(); 58 replacer.setUserDefinedVariables(args); 59 JMeterVariables vars= new JMeterVariables(); 60 vars.putAll(args); 61 JMeterContextService.getContext().setVariables(vars); 62 } 63 else if (node instanceof TestElement) 64 { 65 try 66 { 67 replacer.replaceValues((TestElement) node); 68 } 69 catch (InvalidVariableException e) 70 { 71 log.error("invalid variables", e); 72 } 73 } 74 75 if (node instanceof Arguments) 76 { 77 Map args= ((Arguments)node).getArgumentsAsMap(); 78 replacer.addVariables(args); 79 JMeterContextService.getContext().getVariables().putAll(args); 80 } 81 } 82 83 86 public void subtractNode() 87 { 88 } 89 90 93 public void processPath() 94 { 95 } 96 } 97 | Popular Tags |