1 package jfun.yan.xml.nuts.optional; 2 3 import jfun.yan.Component; 4 import jfun.yan.xml.nut.ComponentNut; 5 6 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 71 } 72 | Popular Tags |