KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jmeter > protocol > http > modifier > ParamMask


1 // $Header: /home/cvs/jakarta-jmeter/src/protocol/http/org/apache/jmeter/protocol/http/modifier/ParamMask.java,v 1.8 2004/02/12 00:29:49 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.protocol.http.modifier;
20
21 import java.io.Serializable JavaDoc;
22
23 import org.apache.jmeter.testelement.AbstractTestElement;
24 import org.apache.jmeter.testelement.property.LongProperty;
25
26 /**
27  * This object defines with what a parameter has its value replaced, and the
28  * policies for how that value changes. Used in {@link ParamModifier}.
29  *
30  * @author David La France
31  * @author <a HREF="mailto:seade@backstagetech.com.au">Scott Eade</a>
32  * @version $Revision: 1.8 $ updated on $Date: 2004/02/12 00:29:49 $
33  */

34 public class ParamMask extends AbstractTestElement implements Serializable JavaDoc
35 {
36     private String JavaDoc PREFIX = "ParamModifier.prefix";
37     private String JavaDoc FIELD_NAME = "ParamModifier.field_name";
38     private String JavaDoc UPPER_BOUND = "ParamModifier.upper_bound";
39     private String JavaDoc LOWER_BOUND = "ParamModifier.lower_bound";
40     private String JavaDoc INCREMENT = "ParamModifier.increment";
41     private String JavaDoc SUFFIX = "ParamModifier.suffix";
42
43     private long _value = 0;
44
45     /**
46      * Default constructor.
47      */

48     public ParamMask()
49     {
50         setFieldName("");
51         setPrefix("");
52         setLowerBound(0);
53         setUpperBound(0);
54         setIncrement(0);
55         setSuffix("");
56     }
57
58     /**
59      * Sets the prefix for the <code>long</code> value. The prefix, the value
60      * and the suffix are concatenated to give the parameter value. This allows
61      * a wider range of posibilities for the parameter values.
62      *
63      * @param prefix a string to prefix to the parameter value
64      */

65     public void setPrefix(String JavaDoc prefix)
66     {
67         setProperty(PREFIX, prefix);
68     }
69
70     /**
71      * Set the current value of the <code>long<code> portion of the parameter
72      * value to replace. This is usually not used, as the method
73      * {@link #resetValue} is used to define a policy for the starting value.
74      *
75      * @param val the new parameter value
76      */

77     public void setValue(long val)
78     {
79         _value = val;
80     }
81
82     public void setFieldName(String JavaDoc fieldName)
83     {
84         setProperty(FIELD_NAME, fieldName);
85     }
86
87     /**
88      * Sets the lowest possible value that the <code>long</code> portion of the
89      * parameter value may be.
90      *
91      * @param val the new lowest possible parameter value
92      */

93     public void setLowerBound(long val)
94     {
95         setProperty(new LongProperty(LOWER_BOUND, val));
96     }
97
98     /**
99      * Sets the highest possible value that the <code>long</code> portion of the
100      * parameter value may be.
101      *
102      * @param val the new highest possible parameter value
103      */

104     public void setUpperBound(long val)
105     {
106         setProperty(new LongProperty(UPPER_BOUND, val));
107     }
108
109     /**
110      * Sets the number by which the parameter value is incremented between
111      * loops.
112      *
113      * @param incr the new increment for the parameter value
114      */

115     public void setIncrement(long incr)
116     {
117         setProperty(new LongProperty(INCREMENT, incr));
118     }
119
120     /**
121      * Sets the suffix for the <code>long</code> value. The prefix, the value
122      * and the suffix are concatenated to give the parameter value. This allows
123      * a wider range of posibilities for the parameter values.
124      *
125      * @param suffix a string to suffix to the parameter value
126      */

127     public void setSuffix(String JavaDoc suffix)
128     {
129         setProperty(SUFFIX, suffix);
130     }
131
132     /**
133      * Accessor method to return the <code>String</code> that will be prefixed
134      * to the <code>long</code> value.
135      *
136      * @return the parameter value prefix
137      */

138     public String JavaDoc getPrefix()
139     {
140         return getPropertyAsString(PREFIX);
141     }
142
143     /**
144      * Accessor method, returns the lowest possible value that the
145      * <code>long</code> portion of the parameter value may be.
146      *
147      * @return the lower bound of the possible values
148      */

149     public long getLowerBound()
150     {
151         return getPropertyAsLong(LOWER_BOUND);
152     }
153
154     /**
155      * Accessor method, returns the highest possible value that the
156      * <code>long</code> portion of the parameter value may be.
157      *
158      * @return the higher bound of the possible values
159      */

160     public long getUpperBound()
161     {
162         return getPropertyAsLong(UPPER_BOUND);
163     }
164
165     /**
166      * Accessor method, returns the number by which the parameter value is
167      * incremented between loops.
168      *
169      * @return the increment
170      */

171     public long getIncrement()
172     {
173         return getPropertyAsLong(INCREMENT);
174     }
175
176     /**
177      * Accessor method to return the <code>String</code> that will be suffixed
178      * to the <code>long</code> value.
179      *
180      * @return the parameter value suffix
181      */

182     public String JavaDoc getSuffix()
183     {
184         return getPropertyAsString(SUFFIX);
185     }
186
187     /*
188      * -----------------------------------------------------------------------
189      * Methods
190      * -----------------------------------------------------------------------
191      */

192
193     /**
194      * Returns the current value, prefixed and suffixed, as a string, then
195      * increments it. If the incremented value is above the upper bound, the
196      * value is reset to the lower bound. <BR>
197      * <P>
198      * This method determines the policy of what happens when an upper bound is
199      * reached/surpassed.
200      *
201      * @return a <code>String</code> representing the current <code>long</code>
202      * value
203      */

204     public String JavaDoc getNextValue()
205     {
206         // return the current value (don't forget the prefix!)
207
String JavaDoc retval = getPrefix() + Long.toString(_value) + getSuffix();
208
209         // increment the value
210
_value += getIncrement();
211         if (_value > getUpperBound())
212         {
213             _value = getLowerBound();
214         }
215
216         return retval;
217     }
218
219     /**
220      * This method determines the policy of what value to start (and re-start)
221      * at.
222      */

223     public void resetValue()
224     {
225         _value = getLowerBound();
226     }
227
228     public String JavaDoc getFieldName()
229     {
230         return getPropertyAsString(FIELD_NAME);
231     }
232
233     /**
234      * For debugging purposes.
235      *
236      * @return a <code>String</code> representing the object
237      */

238     public String JavaDoc toString()
239     {
240         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
241         sb.append("-------------------------------\n");
242         sb.append("Dumping ParamMask Object\n");
243         sb.append("-------------------------------\n");
244         sb.append("Name = " + getFieldName() + "\n");
245         sb.append("Prefix = " + getPrefix() + "\n");
246         sb.append("Current Value = " + _value + "\n");
247         sb.append("Lower Bound = " + getLowerBound() + "\n");
248         sb.append("Upper Bound = " + getUpperBound() + "\n");
249         sb.append("Increment = " + getIncrement() + "\n");
250         sb.append("Suffix = " + getSuffix() + "\n");
251         sb.append("-------------------------------\n");
252
253         return sb.toString();
254     }
255 }
256
Popular Tags