Line 0
Link Here
|
|
|
1 |
/* |
2 |
* Copyright 2001-2004 The Apache Software Foundation. |
3 |
* |
4 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
5 |
* you may not use this file except in compliance with the License. |
6 |
* You may obtain a copy of the License at |
7 |
* |
8 |
* http://www.apache.org/licenses/LICENSE-2.0 |
9 |
* |
10 |
* Unless required by applicable law or agreed to in writing, software |
11 |
* distributed under the License is distributed on an "AS IS" BASIS, |
12 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13 |
* See the License for the specific language governing permissions and |
14 |
* limitations under the License. |
15 |
* |
16 |
*/ |
17 |
|
18 |
package org.apache.jmeter.control; |
19 |
|
20 |
import java.io.Serializable; |
21 |
import java.util.List; |
22 |
import java.util.Iterator; |
23 |
import org.apache.jmeter.testelement.TestElement; |
24 |
import org.apache.jmeter.samplers.AbstractSampler; |
25 |
import org.apache.jmeter.control.GenericController; |
26 |
|
27 |
import org.apache.jmeter.testelement.property.StringProperty; |
28 |
|
29 |
public class CaseController extends InterleaveControl implements Serializable { |
30 |
private final static String CASE_VALUE = "CaseController.value"; |
31 |
|
32 |
public CaseController() { |
33 |
super(); |
34 |
this.setStyle(USE_SUB_CONTROLLERS); |
35 |
} |
36 |
|
37 |
public void reInitialize() { |
38 |
super.reInitialize(); |
39 |
current = getSelectionAsInt(); |
40 |
} |
41 |
|
42 |
/** |
43 |
* @see org.apache.jmeter.control.GenericController#resetCurrent() |
44 |
*/ |
45 |
protected void resetCurrent() { |
46 |
int c = getSubControllers().size(); |
47 |
if (c > 0) { |
48 |
current = getSelectionAsInt(); |
49 |
} else { |
50 |
current = 0; |
51 |
} |
52 |
} |
53 |
|
54 |
/** |
55 |
* @see org.apache.jmeter.control.GenericController#incrementCurrent() |
56 |
*/ |
57 |
protected void incrementCurrent() { |
58 |
super.incrementCurrent(); |
59 |
current = getSelectionAsInt(); |
60 |
} |
61 |
|
62 |
public void setSelection(String inputValue) { |
63 |
setProperty(new StringProperty(CASE_VALUE, inputValue)); |
64 |
} |
65 |
|
66 |
private int getSelectionAsInt() { |
67 |
int ret; |
68 |
getProperty(CASE_VALUE).recoverRunningVersion(null); |
69 |
String sel = getSelection(); |
70 |
Iterator iter = getSubControllers().iterator(); |
71 |
int i = 0; |
72 |
int default_pos = -1; |
73 |
while(iter.hasNext()) { |
74 |
String name; |
75 |
TestElement el = (TestElement)iter.next(); |
76 |
if (el instanceof AbstractSampler) { |
77 |
AbstractSampler s = (AbstractSampler) el; |
78 |
name = s.getName(); |
79 |
} else { |
80 |
GenericController c = (GenericController) el; |
81 |
name = c.getName(); |
82 |
} |
83 |
if (name.equals(sel)) return i; |
84 |
if (name.toLowerCase().equals("default")) default_pos = i; |
85 |
i++; |
86 |
} |
87 |
// if selection not found -> return default element if found |
88 |
if (default_pos != -1) return default_pos; |
89 |
// no element found -> return non-existing element |
90 |
setDone(true); |
91 |
return getSubControllers().size(); |
92 |
} |
93 |
|
94 |
|
95 |
public String getSelection() { |
96 |
return getPropertyAsString(CASE_VALUE); |
97 |
} |
98 |
} |