1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.commons.jelly.tags.core;
17
18 import org.apache.commons.jelly.JellyTagException;
19 import org.apache.commons.jelly.MissingAttributeException;
20 import org.apache.commons.jelly.TagSupport;
21 import org.apache.commons.jelly.XMLOutput;
22 import org.apache.commons.jelly.expression.Expression;
23
24
25 /***
26 * Executes the child <case> tag whose value equals my on attribute.
27 * Executes a child <default> tag when present and no <case> tag has
28 * yet matched.
29 *
30 * @see CaseTag
31 * @see DefaultTag
32 *
33 * @author Rodney Waldhoff
34 * @version $Revision: 1.7 $ $Date: 2004/09/09 12:27:53 $
35 */
36 public class SwitchTag extends TagSupport {
37
38 public SwitchTag() {
39 }
40
41
42
43
44 /***
45 * Sets the value to switch on.
46 * Note that the {@link Expression} is evaluated only once, when the
47 * <switch> tag is evaluated.
48 * @param on the value to switch on
49 */
50 public void setOn(Expression on) {
51 this.on = on;
52 }
53
54 public void doTag(XMLOutput output) throws MissingAttributeException, JellyTagException {
55 if(null == on) {
56 throw new MissingAttributeException("on");
57 } else {
58 value = on.evaluate(context);
59 invokeBody(output);
60 }
61 }
62
63
64
65 protected boolean hasSomeCaseMatched() {
66 return this.someCaseMatched;
67 }
68
69 protected void caseMatched() {
70 this.someCaseMatched = true;
71 }
72
73 protected boolean isFallingThru() {
74 return this.fallingThru;
75 }
76
77 protected void setFallingThru(boolean fallingThru) {
78 this.fallingThru = fallingThru;
79 }
80
81 protected Object getValue() {
82 return value;
83 }
84
85 protected boolean hasDefaultBeenEncountered() {
86 return defaultEncountered;
87 }
88
89 protected void defaultEncountered() {
90 this.defaultEncountered = true;
91 }
92
93
94
95 private boolean someCaseMatched = false;
96 private boolean fallingThru = false;
97 private boolean defaultEncountered = false;
98 private Expression on = null;
99 private Object value = null;
100
101 }