001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: */
018:
019: package org.apache.jmeter.protocol.http.modifier;
020:
021: import java.io.Serializable;
022:
023: import org.apache.jmeter.testelement.AbstractTestElement;
024: import org.apache.jmeter.testelement.property.LongProperty;
025:
026: /**
027: * This object defines with what a parameter has its value replaced, and the
028: * policies for how that value changes. Used in {@link ParamModifier}.
029: *
030: * @author David La France
031: * @author <a href="mailto:seade@backstagetech.com.au">Scott Eade</a>
032: * @version $Revision: 493789 $ updated on $Date: 2007-01-07 18:10:21 +0000 (Sun, 07 Jan 2007) $
033: */
034: public class ParamMask extends AbstractTestElement implements
035: Serializable {
036: private String PREFIX = "ParamModifier.prefix";
037:
038: private String FIELD_NAME = "ParamModifier.field_name";
039:
040: private String UPPER_BOUND = "ParamModifier.upper_bound";
041:
042: private String LOWER_BOUND = "ParamModifier.lower_bound";
043:
044: private String INCREMENT = "ParamModifier.increment";
045:
046: private String SUFFIX = "ParamModifier.suffix";
047:
048: private long _value = 0;
049:
050: /**
051: * Default constructor.
052: */
053: public ParamMask() {
054: setFieldName("");
055: setPrefix("");
056: setLowerBound(0);
057: setUpperBound(0);
058: setIncrement(0);
059: setSuffix("");
060: }
061:
062: /**
063: * Sets the prefix for the <code>long</code> value. The prefix, the value
064: * and the suffix are concatenated to give the parameter value. This allows
065: * a wider range of posibilities for the parameter values.
066: *
067: * @param prefix
068: * a string to prefix to the parameter value
069: */
070: public void setPrefix(String prefix) {
071: setProperty(PREFIX, prefix);
072: }
073:
074: /**
075: * Set the current value of the <code>long<code> portion of the parameter
076: * value to replace. This is usually not used, as the method
077: * {@link #resetValue} is used to define a policy for the starting value.
078: *
079: * @param val the new parameter value
080: */
081: public void setValue(long val) {
082: _value = val;
083: }
084:
085: public void setFieldName(String fieldName) {
086: setProperty(FIELD_NAME, fieldName);
087: }
088:
089: /**
090: * Sets the lowest possible value that the <code>long</code> portion of
091: * the parameter value may be.
092: *
093: * @param val
094: * the new lowest possible parameter value
095: */
096: public void setLowerBound(long val) {
097: setProperty(new LongProperty(LOWER_BOUND, val));
098: }
099:
100: /**
101: * Sets the highest possible value that the <code>long</code> portion of
102: * the parameter value may be.
103: *
104: * @param val
105: * the new highest possible parameter value
106: */
107: public void setUpperBound(long val) {
108: setProperty(new LongProperty(UPPER_BOUND, val));
109: }
110:
111: /**
112: * Sets the number by which the parameter value is incremented between
113: * loops.
114: *
115: * @param incr
116: * the new increment for the parameter value
117: */
118: public void setIncrement(long incr) {
119: setProperty(new LongProperty(INCREMENT, incr));
120: }
121:
122: /**
123: * Sets the suffix for the <code>long</code> value. The prefix, the value
124: * and the suffix are concatenated to give the parameter value. This allows
125: * a wider range of posibilities for the parameter values.
126: *
127: * @param suffix
128: * a string to suffix to the parameter value
129: */
130: public void setSuffix(String suffix) {
131: setProperty(SUFFIX, suffix);
132: }
133:
134: /**
135: * Accessor method to return the <code>String</code> that will be prefixed
136: * to the <code>long</code> value.
137: *
138: * @return the parameter value prefix
139: */
140: public String getPrefix() {
141: return getPropertyAsString(PREFIX);
142: }
143:
144: /**
145: * Accessor method, returns the lowest possible value that the
146: * <code>long</code> portion of the parameter value may be.
147: *
148: * @return the lower bound of the possible values
149: */
150: public long getLowerBound() {
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: return getPropertyAsLong(UPPER_BOUND);
162: }
163:
164: /**
165: * Accessor method, returns the number by which the parameter value is
166: * incremented between loops.
167: *
168: * @return the increment
169: */
170: public long getIncrement() {
171: return getPropertyAsLong(INCREMENT);
172: }
173:
174: /**
175: * Accessor method to return the <code>String</code> that will be suffixed
176: * to the <code>long</code> value.
177: *
178: * @return the parameter value suffix
179: */
180: public String getSuffix() {
181: return getPropertyAsString(SUFFIX);
182: }
183:
184: /*
185: * -----------------------------------------------------------------------
186: * Methods
187: * -----------------------------------------------------------------------
188: */
189:
190: /**
191: * Returns the current value, prefixed and suffixed, as a string, then
192: * increments it. If the incremented value is above the upper bound, the
193: * value is reset to the lower bound. <BR>
194: * <P>
195: * This method determines the policy of what happens when an upper bound is
196: * reached/surpassed.
197: *
198: * @return a <code>String</code> representing the current
199: * <code>long</code> value
200: */
201: public String getNextValue() {
202: // return the current value (don't forget the prefix!)
203: String retval = getPrefix() + Long.toString(_value)
204: + getSuffix();
205:
206: // increment the value
207: _value += getIncrement();
208: if (_value > getUpperBound()) {
209: _value = getLowerBound();
210: }
211:
212: return retval;
213: }
214:
215: /**
216: * This method determines the policy of what value to start (and re-start)
217: * at.
218: */
219: public void resetValue() {
220: _value = getLowerBound();
221: }
222:
223: public String getFieldName() {
224: return getPropertyAsString(FIELD_NAME);
225: }
226:
227: /**
228: * For debugging purposes.
229: *
230: * @return a <code>String</code> representing the object
231: */
232: public String toString() {
233: StringBuffer sb = new StringBuffer();
234: sb.append("-------------------------------\n");
235: sb.append("Dumping ParamMask Object\n");
236: sb.append("-------------------------------\n");
237: sb.append("Name = " + getFieldName() + "\n");
238: sb.append("Prefix = " + getPrefix() + "\n");
239: sb.append("Current Value = " + _value + "\n");
240: sb.append("Lower Bound = " + getLowerBound() + "\n");
241: sb.append("Upper Bound = " + getUpperBound() + "\n");
242: sb.append("Increment = " + getIncrement() + "\n");
243: sb.append("Suffix = " + getSuffix() + "\n");
244: sb.append("-------------------------------\n");
245:
246: return sb.toString();
247: }
248: }
|