package jfun.yan.xml.nuts.optional;
import jfun.yan.Component;
import jfun.yan.Components;
/**
* Nut class for conditional statement. For example:
* <pre>
* <nut name="if" class="IfElseNut"/>
* <components>
* <if cond="true" then="$a" else="$b">
* </components>
* </pre>
* Evaluates to the component referenced by "b".
* <p>
* The "else" attribute is optional.
* </p>
* <p>
* @author Ben Yu
* Nov 10, 2005 12:01:47 AM
*/
public class IfElseNut extends ConditionalNut {
public Component eval(){
final boolean c = isCond();
final Component then = getThen();
checkMandatory("then", then);
if(c)
return then;
else{
final Component alt = getElse();
return alt==null?Components.value(false):alt;
}
}
}