KickJava   Java API By Example, From Geeks To Geeks.

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


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

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