File D:\maven-qcr-plugin-testsunitaires\qcr4java\jenkins-master\target\site\qc\core\src\main\java\hudson\model\SimpleParameterDefinition.java.html

1 package hudson.model;
2
3 import org.kohsuke.stapler.StaplerRequest;
4 import hudson.cli.CLICommand;
5
6 import java.io.IOException;
7
8 /**
9 * Convenient base class for {@link ParameterDefinition} whose value can be represented in a context-independent single string token.
10 *
11 * @author Kohsuke Kawaguchi
12 */
13 public abstract class SimpleParameterDefinition extends ParameterDefinition {
14 protected SimpleParameterDefinition(String name) {
15 super(name);
16 }
17
18 protected SimpleParameterDefinition(String name, String description) {
19 super(name, description);
20 }
21
22 /**
23 * Creates a {@link ParameterValue} from the string representation.
24 */
25 public abstract ParameterValue createValue(String value);
26
27 @Override
28 public final ParameterValue createValue(StaplerRequest req) {
29 String[] value = req.getParameterValues(getName());
30 if (value == null) {
31 return getDefaultParameterValue();
32 } else if (value.length != 1) {
33 throw new IllegalArgumentException("Illegal number of parameter values for " + getName() + ": " + value.length);
34 } else {
35 return createValue(value[0]);
36 }
37 }
38
39 @Override
40 public final ParameterValue createValue(CLICommand command, String value) throws IOException, InterruptedException {
41 return createValue(value);
42 }
43 }
44