%line | %branch | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
org.apache.commons.jelly.tags.core.DefaultTag |
|
|
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.TagSupport; |
|
20 | import org.apache.commons.jelly.XMLOutput; |
|
21 | ||
22 | ||
23 | /** |
|
24 | * A tag which conditionally evaluates its body if |
|
25 | * none of its preceeding sibling {@link CaseTag <case>} |
|
26 | * tags have been evaluated. |
|
27 | * |
|
28 | * This tag must be contained within the body of some |
|
29 | * {@link SwitchTag <switch>} tag. |
|
30 | * |
|
31 | * @see SwitchTag |
|
32 | * |
|
33 | * @author Rodney Waldhoff |
|
34 | * @version $Revision: 1.8 $ $Date: 2004/09/09 12:27:53 $ |
|
35 | */ |
|
36 | 2 | public class DefaultTag extends TagSupport { |
37 | ||
38 | 28 | public DefaultTag() { |
39 | 28 | } |
40 | ||
41 | // Tag interface |
|
42 | //------------------------------------------------------------------------- |
|
43 | ||
44 | public void setFallThru(boolean fallThru) { |
|
45 | 0 | this.fallThru = fallThru; |
46 | 0 | } |
47 | ||
48 | public void doTag(XMLOutput output) throws JellyTagException { |
|
49 | 28 | SwitchTag tag = (SwitchTag)findAncestorWithClass(SwitchTag.class); |
50 | 28 | if(null == tag) { |
51 | 2 | throw new JellyTagException("This tag must be enclosed inside a <switch> tag" ); |
52 | } |
|
53 | 26 | if(tag.hasDefaultBeenEncountered()) { |
54 | 2 | throw new JellyTagException("Only one <default> tag is allowed per <switch>."); |
55 | } |
|
56 | 24 | tag.defaultEncountered(); |
57 | 24 | if(tag.isFallingThru() || (!tag.hasSomeCaseMatched())) { |
58 | 6 | tag.caseMatched(); |
59 | 6 | tag.setFallingThru(fallThru); |
60 | 6 | invokeBody(output); |
61 | } |
|
62 | 24 | } |
63 | ||
64 | // Attributes |
|
65 | //------------------------------------------------------------------------- |
|
66 | 28 | private boolean fallThru = false; |
67 | ||
68 | } |
This report is generated by jcoverage, Maven and Maven JCoverage Plugin. |