%line | %branch | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
org.apache.commons.jelly.tags.core.CaseTag |
|
|
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 | * A tag which conditionally evaluates its body if |
|
26 | * my {@link #setValue value} attribute equals my ancestor |
|
27 | * {@link SwitchTag <switch>} tag's |
|
28 | * {@link SwitchTag#setOn "on"} attribute. |
|
29 | * |
|
30 | * This tag must be contained within the body of some |
|
31 | * {@link SwitchTag <switch>} tag. |
|
32 | * |
|
33 | * @see SwitchTag |
|
34 | * |
|
35 | * @author Rodney Waldhoff |
|
36 | * @version $Revision: 155420 $ $Date: 2005-02-27 00:06:03 +1100 (Sun, 27 Feb 2005) $ |
|
37 | */ |
|
38 | public class CaseTag extends TagSupport { |
|
39 | ||
40 | 598 | public CaseTag() { |
41 | 598 | } |
42 | ||
43 | // Tag interface |
|
44 | //------------------------------------------------------------------------- |
|
45 | public void setValue(Expression value) { |
|
46 | 611 | this.valueExpression = value; |
47 | 611 | } |
48 | ||
49 | public void setFallThru(boolean fallThru) { |
|
50 | 130 | this.fallThru = fallThru; |
51 | 130 | } |
52 | ||
53 | public void doTag(XMLOutput output) throws MissingAttributeException, JellyTagException { |
|
54 | 624 | if(null == this.valueExpression) { |
55 | 13 | throw new MissingAttributeException("value"); |
56 | } |
|
57 | 624 | SwitchTag tag = (SwitchTag)findAncestorWithClass(SwitchTag.class); |
58 | 611 | if(null == tag) { |
59 | 13 | throw new JellyTagException("This tag must be enclosed inside a <switch> tag" ); |
60 | } |
|
61 | 598 | if(tag.hasDefaultBeenEncountered()) { |
62 | 13 | throw new JellyTagException("<default> should be the last tag within a <switch>" ); |
63 | } |
|
64 | 585 | Object value = valueExpression.evaluate(context); |
65 | 585 | if(tag.isFallingThru() || |
66 | (null == tag.getValue() && class="keyword">null == value) || |
|
67 | (null != tag.getValue() && tag.getValue().equals(value))) { |
|
68 | 130 | tag.caseMatched(); |
69 | 130 | tag.setFallingThru(fallThru); |
70 | 130 | invokeBody(output); |
71 | } |
|
72 | 585 | } |
73 | ||
74 | // Attributes |
|
75 | //------------------------------------------------------------------------- |
|
76 | 598 | private Expression valueExpression = null; |
77 | 598 | private boolean fallThru = false; |
78 | ||
79 | } |
This report is generated by jcoverage, Maven and Maven JCoverage Plugin. |