KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jfun > yan > xml > nuts > optional > IfElseNut


1 package jfun.yan.xml.nuts.optional;
2
3 import jfun.yan.Component;
4 import jfun.yan.Components;
5
6 /**
7  * Nut class for conditional statement. For example:
8  * <pre>
9  * &lt;nut name="if" class="IfElseNut"/&gt;
10  * &lt;components&gt;
11  * &lt;if cond="true" then="$a" else="$b"&gt;
12  * &lt;/components&gt;
13  * </pre>
14  * Evaluates to the component referenced by "b".
15  * <p>
16  * The "else" attribute is optional.
17  * </p>
18  * <p>
19  * @author Ben Yu
20  * Nov 10, 2005 12:01:47 AM
21  */

22 public class IfElseNut extends ConditionalNut {
23   public Component eval(){
24     final boolean c = isCond();
25     final Component then = getThen();
26     checkMandatory("then", then);
27     if(c)
28       return then;
29     else{
30       final Component alt = getElse();
31       return alt==null?Components.value(false):alt;
32     }
33   }
34 }
35
Popular Tags