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;
023     *  it provides the context for mutually exclusive conditional evaluation.
024     *
025     *  [<a href="../../../../../../ComponentReference/contrib.Choose.html">Component Reference</a>]
026     *
027     *  @author David Solis
028     * 
029     */
030    public abstract class Choose extends Conditional {
031    
032    
033            public void addBody(IRender element)
034            {
035                    super.addBody(element);
036                    if (element instanceof When)
037                            ((When) element).setChoose(this);       
038            }
039            
040            protected void cleanupAfterRender(IRequestCycle cycle)
041            {
042                    setConditionMet(false);
043                    super.cleanupAfterRender(cycle);
044            }
045            
046            protected boolean evaluateCondition()
047            {
048                    return getCondition();
049            }
050    
051            public boolean getInvert()
052            {
053                    // This component doesn't require invert parameter.
054                    return false;
055            }
056    
057            public abstract boolean getCondition();
058            
059            public abstract boolean isConditionMet();
060            public abstract void setConditionMet(boolean value);
061    }