001 // Copyright 2004, 2005 The Apache Software Foundation
002 //
003 // Licensed under the Apache License, Version 2.0 (the "License");
004 // you may not use this file except in compliance with the License.
005 // You may obtain a copy of the License at
006 //
007 // http://www.apache.org/licenses/LICENSE-2.0
008 //
009 // Unless required by applicable law or agreed to in writing, software
010 // distributed under the License is distributed on an "AS IS" BASIS,
011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012 // See the License for the specific language governing permissions and
013 // limitations under the License.
014
015 package org.apache.tapestry.contrib.components;
016
017 import org.apache.tapestry.IRender;
018 import org.apache.tapestry.IRequestCycle;
019 import org.apache.tapestry.components.Conditional;
020
021 /**
022 * This component is a container for {@link When} or Otherwise components; it
023 * provides the context for mutually exclusive conditional evaluation. [<a
024 * href="../../../../../../ComponentReference/contrib.Choose.html">Component
025 * Reference</a>]
026 *
027 * @author David Solis
028 */
029 public abstract class Choose extends Conditional
030 {
031
032 public void addBody(IRender element)
033 {
034 super.addBody(element);
035 if (element instanceof When) ((When) element).setChoose(this);
036 }
037
038 protected void cleanupAfterRender(IRequestCycle cycle)
039 {
040 setConditionMet(false);
041 super.cleanupAfterRender(cycle);
042 }
043
044 protected boolean evaluateCondition()
045 {
046 return getCondition();
047 }
048
049 public boolean getInvert()
050 {
051 // This component doesn't require invert parameter.
052 return false;
053 }
054
055 public abstract boolean getCondition();
056
057 public abstract boolean isConditionMet();
058
059 public abstract void setConditionMet(boolean value);
060 }