KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jmeter > engine > PreCompiler


1 // $Header: /home/cvs/jakarta-jmeter/src/core/org/apache/jmeter/engine/PreCompiler.java,v 1.22.2.1 2004/05/20 15:23:11 mstover1 Exp $
2
/*
3  * Copyright 2001-2004 The Apache Software Foundation.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17 */

18
19 package org.apache.jmeter.engine;
20
21 import java.util.Map JavaDoc;
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 /**
36  * @author Michael Stover
37  * @author <a HREF="mailto:jsalvata@apache.org">Jordi Salvat i Alabart</a>
38  * @version $Revision: 1.22.2.1 $ updated on $Date: 2004/05/20 15:23:11 $
39  */

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     /* (non-Javadoc)
51      * @see HashTreeTraverser#addNode(Object, HashTree)
52      */

53     public void addNode(Object JavaDoc node, HashTree subTree)
54     {
55         if (node instanceof TestPlan)
56         {
57             Map JavaDoc 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 JavaDoc args= ((Arguments)node).getArgumentsAsMap();
78             replacer.addVariables(args);
79             JMeterContextService.getContext().getVariables().putAll(args);
80         }
81     }
82
83     /* (non-Javadoc)
84      * @see HashTreeTraverser#subtractNode()
85      */

86     public void subtractNode()
87     {
88     }
89
90     /* (non-Javadoc)
91      * @see HashTreeTraverser#processPath()
92      */

93     public void processPath()
94     {
95     }
96 }
97
Popular Tags