KickJava   Java API By Example, From Geeks To Geeks.

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


1 package jfun.yan.xml.nuts.optional;
2
3 import jfun.yan.Component;
4 import jfun.yan.xml.nut.ComponentNut;
5
6 /**
7  * Super class for binary conditional statement such as if/unless.
8  * <p>
9  * It supports three attributes: cond, then, else.
10  * </p>
11  *
12  * <p>
13  * @author Ben Yu
14  * Nov 11, 2005 11:56:15 AM
15  */

16 public abstract class ConditionalNut extends ComponentNut {
17
18   private boolean cond;
19   private boolean condition_set = false;
20   private Component consequence;
21   private Component alternative;
22   public Component getElse() {
23     return alternative;
24   }
25
26   public void setElse(Component alternative) {
27     this.alternative = alternative;
28   }
29
30   public boolean isCond() {
31     if(!condition_set){
32       throw raise("missing mandatory attribute <cond>");
33     }
34     return cond;
35   }
36
37   public void setCond(boolean cond) {
38     this.cond = cond;
39     this.condition_set = true;
40   }
41
42   public Component getThen() {
43     return consequence;
44   }
45
46   public void setThen(Component consequence) {
47     this.consequence = consequence;
48   }
49   public void set(Component[] branches){
50     if(branches.length>2){
51       throw raise("at most 2 branches can be specified.");
52     }
53     if(branches.length>0){
54       checkDuplicate("then", consequence);
55       this.consequence = branches[0];
56     }
57     if(branches.length>1){
58       checkDuplicate("else", alternative);
59       this.alternative = branches[1];
60     }
61   }
62   /*
63   public void addThen(Branch brach){
64     checkDuplicate("then", consequence);
65     this.consequence = brach.getComponent();
66   }
67   public void addElse(Branch brach){
68     checkDuplicate("else", alternative);
69     this.alternative = brach.getComponent();
70   }*/

71 }
72
Popular Tags