KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jmeter > engine > util > SimpleVariable


1 // $Header: /home/cvs/jakarta-jmeter/src/core/org/apache/jmeter/engine/util/SimpleVariable.java,v 1.7 2004/02/14 03:34:28 sebb Exp $
2
/*
3  * Copyright 2003-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.util;
20
21 import org.apache.jmeter.threads.JMeterContext;
22 import org.apache.jmeter.threads.JMeterContextService;
23 import org.apache.jmeter.threads.JMeterVariables;
24
25 /**
26  * @version $Revision: 1.7 $
27  */

28 public class SimpleVariable
29 {
30
31     private String JavaDoc name;
32
33     public SimpleVariable(String JavaDoc name)
34     {
35         this.name = name;
36     }
37
38     public SimpleVariable()
39     {
40         this.name = "";
41     }
42
43     public String JavaDoc getName()
44     {
45         return name;
46     }
47
48     public void setName(String JavaDoc name)
49     {
50         this.name = name;
51     }
52
53     /**
54      * @see org.apache.jmeter.functions.Function#execute(SampleResult, Sampler)
55      */

56     public String JavaDoc toString()
57     {
58         String JavaDoc ret = null;
59         JMeterVariables vars = getVariables();
60
61         if (vars != null)
62         {
63             ret = vars.get(name);
64         }
65
66         if (ret == null)
67         {
68             return "${" + name + "}";
69         }
70
71         return ret;
72     }
73
74     private JMeterVariables getVariables()
75     {
76         JMeterContext context = JMeterContextService.getContext();
77         return context.getVariables();
78     }
79
80 }
81
Popular Tags