01: /* SummaryAttribute.java */
02:
03: package org.quilt.frontend.ant;
04:
05: import org.apache.tools.ant.BuildException;
06:
07: /**
08: * Accept a limited set of String values for the summary attribute.
09: */
10: public class SummaryAttribute {
11:
12: private String value;
13: private boolean bVal;
14:
15: /**
16: * Constructor.
17: * @param v A candidate value; causes exception if invalid.
18: */
19: public SummaryAttribute(String v) {
20: setValue(v);
21: }
22:
23: /**
24: * Return the value successfully set.
25: *
26: * @return The String passed as the value of the summary attribute.
27: */
28: public String getValue() {
29: return value;
30: }
31:
32: /**
33: * Ant-compatible set method. Interprets on/true/withoutanderr/yes
34: * as true, false/no/off as false, and throws exception otherwise.
35: *
36: * @param v String, converted to lower case before checking.
37: */
38: public final void setValue(String value) throws BuildException {
39: this .value = value.toLowerCase();
40: if (value.equals("on") || value.equals("true")
41: || value.equals("withoutanderr") || value.equals("yes")) {
42: bVal = true;
43: } else if (value.equals("false") || value.equals("no")
44: || value.equals("off")) {
45: bVal = false;
46: } else {
47: throw new BuildException(
48: "invalid summary attribute value: " + value);
49: }
50: }
51:
52: /**
53: * @return True if the value was on/true/withoutanderr/yes, false
54: * otherwise.
55: */
56: public boolean asBoolean() {
57: return bVal;
58: }
59: }
|