package jfun.yan.xml.nuts.optional;
import jfun.yan.Component;
import jfun.yan.Components;
/**
* Nut class for conditional statement. For example:
* <pre>
* <nut name="unless" class="UnlessNut"/>
* <components>
* <unless cond="true" then="$a" else="$b">
* </components>
* </pre>
* Evaluates to the component referenced by "a".
* <p>
* The "else" attribute is optional.
* </p>
* <p>
* @author Ben Yu
* Nov 10, 2005 12:01:47 AM
*/
public class UnlessNut 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(true):alt;
}
}
}