01: /*
02: * Copyright 2002,2004 The Apache Software Foundation.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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: * A tag which conditionally evaluates its body if
24: * none of its preceeding sibling {@link CaseTag <case>}
25: * tags have been evaluated.
26: *
27: * This tag must be contained within the body of some
28: * {@link SwitchTag <switch>} tag.
29: *
30: * @see SwitchTag
31: *
32: * @author Rodney Waldhoff
33: * @version $Revision: 155420 $ $Date: 2005-02-27 00:06:03 +1100 (Sun, 27 Feb 2005) $
34: */
35: public class DefaultTag extends TagSupport {
36:
37: public DefaultTag() {
38: }
39:
40: // Tag interface
41: //-------------------------------------------------------------------------
42:
43: public void setFallThru(boolean fallThru) {
44: this .fallThru = fallThru;
45: }
46:
47: public void doTag(XMLOutput output) throws JellyTagException {
48: SwitchTag tag = (SwitchTag) findAncestorWithClass(SwitchTag.class);
49: if (null == tag) {
50: throw new JellyTagException(
51: "This tag must be enclosed inside a <switch> tag");
52: }
53: if (tag.hasDefaultBeenEncountered()) {
54: throw new JellyTagException(
55: "Only one <default> tag is allowed per <switch>.");
56: }
57: tag.defaultEncountered();
58: if (tag.isFallingThru() || (!tag.hasSomeCaseMatched())) {
59: tag.caseMatched();
60: tag.setFallingThru(fallThru);
61: invokeBody(output);
62: }
63: }
64:
65: // Attributes
66: //-------------------------------------------------------------------------
67: private boolean fallThru = false;
68:
69: }
|