KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jmeter > functions > AbstractFunction


1 // $Header: /home/cvs/jakarta-jmeter/src/core/org/apache/jmeter/functions/AbstractFunction.java,v 1.11 2004/03/02 00:07:51 sebb 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.functions;
20
21 //import java.io.UnsupportedEncodingException;
22
import java.util.Collection JavaDoc;
23 //import java.util.LinkedList;
24
//import java.util.List;
25
//import java.util.StringTokenizer;
26

27 import org.apache.jmeter.samplers.SampleResult;
28 import org.apache.jmeter.samplers.Sampler;
29 import org.apache.jmeter.threads.JMeterContext;
30 import org.apache.jmeter.threads.JMeterContextService;
31 import org.apache.jmeter.threads.JMeterVariables;
32 //import org.apache.jorphan.util.JOrphanUtils;
33

34 /**
35  * @version $Revision: 1.11 $ on $Date: 2004/03/02 00:07:51 $
36  */

37 public abstract class AbstractFunction implements Function
38 {
39     
40     /**
41      * @see Function#execute(SampleResult, Sampler)
42      */

43     abstract public String JavaDoc execute(
44         SampleResult previousResult,
45         Sampler currentSampler)
46         throws InvalidVariableException;
47
48     public String JavaDoc execute() throws InvalidVariableException
49     {
50         JMeterContext context = JMeterContextService.getContext();
51         SampleResult previousResult = context.getPreviousResult();
52         Sampler currentSampler = context.getCurrentSampler();
53         return execute(previousResult, currentSampler);
54     }
55
56
57     /**
58      * @see Function#setParameters(Collection)
59      */

60     abstract public void setParameters(Collection JavaDoc parameters)
61         throws InvalidVariableException;
62
63     /**
64      * @see Function#getReferenceKey()
65      */

66     abstract public String JavaDoc getReferenceKey();
67
68 // Not used
69
// /**
70
// * Provides a convenient way to parse the given argument string into a
71
// * collection of individual arguments. Takes care of splitting the string
72
// * based on commas, generates blank strings for values between adjacent
73
// * commas, and decodes the string using URLDecoder.
74
// *
75
// * @deprecated
76
// */
77
// protected Collection parseArguments(String params)
78
// {
79
// StringTokenizer tk = new StringTokenizer(params, ",", true);
80
// List arguments = new LinkedList();
81
// String previous = "";
82
// while (tk.hasMoreTokens())
83
// {
84
// String arg = tk.nextToken();
85
//
86
// if (arg.equals(",") && previous.equals(","))
87
// {
88
// arguments.add("");
89
// }
90
// else if (!arg.equals(","))
91
// {
92
// try
93
// {
94
// arguments.add(JOrphanUtils.decode(arg, "UTF-8"));
95
// }
96
// catch (UnsupportedEncodingException e)
97
// {
98
// // UTF-8 unsupported? You must be joking!
99
// throw new Error("Should not happen: "+e.toString());
100
// }
101
// }
102
// previous = arg;
103
// }
104
// return arguments;
105
// }
106

107     /**
108      * Provides a convenient way to parse the given argument string into a
109      * collection of individual arguments. Takes care of splitting the string
110      * based on commas, generates blank strings for values between adjacent
111      * commas, and decodes the string using URLDecoder.
112      */

113 /*
114     protected Collection parseArguments2(String params)
115     {
116         StringTokenizer tk = new StringTokenizer(params, ",", true);
117         List arguments = new LinkedList();
118         String previous = "";
119         while (tk.hasMoreTokens())
120         {
121             String arg = tk.nextToken();
122
123             if (arg.equals(",")
124                 && (previous.equals(",") || previous.length() == 0))
125             {
126                 arguments.add(new CompoundVariable());
127             }
128             else if (!arg.equals(","))
129             {
130                 try
131                 {
132                     CompoundVariable compoundArg = new CompoundVariable();
133                     compoundArg.setParameters(URLDecoder.decode(arg));
134                     arguments.add(compoundArg);
135                 }
136                 catch (InvalidVariableException e)
137                 {
138                 }
139             }
140             previous = arg;
141         }
142
143         if (previous.equals(","))
144         {
145             arguments.add(new CompoundVariable());
146         }
147
148         return arguments;
149     }
150 */

151
152     protected JMeterVariables getVariables()
153     {
154         return JMeterContextService.getContext().getVariables();
155     }
156 }
157
Popular Tags