%line | %branch | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
org.apache.commons.jelly.tags.core.SwitchTag |
|
|
1 | /* |
|
2 | * Copyright 2002,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 | 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: 155420 $ $Date: 2005-02-27 00:06:03 +1100 (Sun, 27 Feb 2005) $ |
|
35 | */ |
|
36 | public class SwitchTag extends TagSupport { |
|
37 | ||
38 | 195 | public SwitchTag() { |
39 | 195 | } |
40 | ||
41 | // Tag interface |
|
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 | 195 | this.on = on; |
52 | 195 | } |
53 | ||
54 | public void doTag(XMLOutput output) throws MissingAttributeException, JellyTagException { |
|
55 | 208 | this.defaultEncountered = false; |
56 | 208 | this.someCaseMatched = false; |
57 | 208 | this.fallingThru = false; |
58 | ||
59 | 208 | if(null == on) { |
60 | 13 | throw new MissingAttributeException("on"); |
61 | } else { |
|
62 | 195 | value = on.evaluate(context); |
63 | 195 | invokeBody(output); |
64 | } |
|
65 | 156 | } |
66 | ||
67 | // Protected properties |
|
68 | //------------------------------------------------------------------------- |
|
69 | protected boolean hasSomeCaseMatched() { |
|
70 | 182 | return this.someCaseMatched; |
71 | } |
|
72 | ||
73 | protected void caseMatched() { |
|
74 | 195 | this.someCaseMatched = true; |
75 | 195 | } |
76 | ||
77 | protected boolean isFallingThru() { |
|
78 | 767 | return this.fallingThru; |
79 | } |
|
80 | ||
81 | protected void setFallingThru(boolean fallingThru) { |
|
82 | 195 | this.fallingThru = fallingThru; |
83 | 195 | } |
84 | ||
85 | protected Object getValue() { |
|
86 | 1261 | return value; |
87 | } |
|
88 | ||
89 | protected boolean hasDefaultBeenEncountered() { |
|
90 | 793 | return defaultEncountered; |
91 | } |
|
92 | ||
93 | protected void defaultEncountered() { |
|
94 | 182 | this.defaultEncountered = true; |
95 | 182 | } |
96 | ||
97 | // Attributes |
|
98 | //------------------------------------------------------------------------- |
|
99 | 195 | private boolean someCaseMatched = false; |
100 | 195 | private boolean fallingThru = false; |
101 | 195 | private boolean defaultEncountered = false; |
102 | 195 | private Expression on = null; |
103 | 195 | private Object value = null; |
104 | ||
105 | } |
This report is generated by jcoverage, Maven and Maven JCoverage Plugin. |