
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.RunnableTagSupport;

/** A sample RunnableTag for implementing efficient
  * switch statements in JSP custom tags
  */
public class CaseTag extends RunnableTagSupport {

    private Object value;
    
    public CaseTag() {
    }
    
    /** Sets the value used to compare against */
    public void setValue(Object value) {
        this.value = value;
    }
    
    public void release() {
        value = null; // help the GC
    }
    
    public void doRegister() throws JspException {
        LoopTag loopTag 
            = (LoopTag) findAncestorWithClass( this, LoopTag.class );
        if ( loopTag != null ) {
            loopTag.addCase( value, this );
        }
        else {
            throw new JspException( "CaseTag should appear inside a LoopTag" );
        }
    }
}


