1 30 package com.genimen.djeneric.tools.scriptengine.core.nodes; 31 32 import com.genimen.djeneric.language.Messages; 33 import com.genimen.djeneric.tools.scriptengine.core.DjScriptParserEngine; 34 import com.genimen.djeneric.tools.scriptengine.core.SimpleNode; 35 import com.genimen.djeneric.tools.scriptengine.core.util.DjScriptExecutionException; 36 import com.genimen.djeneric.tools.scriptengine.core.util.DjScriptExecutionTimeScope; 37 38 public class IfNode extends SimpleNode 39 { 40 41 public IfNode(int i) 42 { 43 super(i); 44 } 45 46 public IfNode(DjScriptParserEngine p, int i) 47 { 48 super(p, i); 49 } 50 51 public String getName() 52 { 53 return "if"; 54 } 55 56 public String toString() 57 { 58 return "ifNode"; 59 } 60 61 public void execute(DjScriptExecutionTimeScope context) throws DjScriptExecutionException 62 { 63 if (!(getChild(0) instanceof BooleanExpression)) 64 { 65 if (getChild(0) instanceof ValueExpression) 66 { 67 ValueExpression ve = (ValueExpression) getChild(0); 68 Object o = ve.getValue(context); 69 if (o instanceof Boolean ) 70 { 71 Boolean b = (Boolean ) o; 72 if (b.booleanValue()) handleTrue(context); 73 else handleFalse(context); 74 return; 75 } 76 } 77 throw new DjScriptExecutionException(Messages.getString("IfNode.NotBoolean"), this); 78 } 79 80 BooleanExpression expr = (BooleanExpression) getChild(0); 81 if (expr.isTrue(context)) handleTrue(context); 82 else handleFalse(context); 83 } 84 85 void handleTrue(DjScriptExecutionTimeScope context) throws DjScriptExecutionException 86 { 87 getChild(1).execute(context); 88 } 89 90 void handleFalse(DjScriptExecutionTimeScope context) throws DjScriptExecutionException 91 { 92 if (getChildCount() == 3) 94 { 95 getChild(2).execute(context); 96 } 97 } 98 99 } | Popular Tags |