1 55 56 package org.apache.commons.el; 57 58 import java.util.List ; 59 import java.util.Map ; 60 import javax.servlet.jsp.el.ELException ; 61 import javax.servlet.jsp.el.VariableResolver ; 62 import javax.servlet.jsp.el.FunctionMapper ; 63 64 74 75 public class ConditionalExpression 76 extends Expression 77 { 78 83 Expression mCondition; 84 public Expression getCondition () 85 { return mCondition; } 86 public void setCondition (Expression pCondition) 87 { mCondition = pCondition; } 88 89 92 Expression mTrueBranch; 93 public Expression getTrueBranch () 94 { return mTrueBranch; } 95 public void setTrueBranch (Expression pTrueBranch) 96 { mTrueBranch = pTrueBranch; } 97 98 101 Expression mFalseBranch; 102 public Expression getFalseBranch () 103 { return mFalseBranch; } 104 public void setFalseBranch (Expression pFalseBranch) 105 { mFalseBranch = pFalseBranch; } 106 107 112 public ConditionalExpression (Expression pCondition, 113 Expression pTrueBranch, 114 Expression pFalseBranch) 115 { 116 mCondition = pCondition; 117 mTrueBranch = pTrueBranch; 118 mFalseBranch = pFalseBranch; 119 } 120 121 128 public String getExpressionString () 129 { 130 return 131 "( " + mCondition.getExpressionString() + " ? " + 132 mTrueBranch.getExpressionString() + " : " + 133 mFalseBranch.getExpressionString() + " )"; 134 } 135 136 141 public Object evaluate (VariableResolver vr, 142 FunctionMapper f, 143 Logger l) 144 throws ELException 145 { 146 boolean condition = 148 Coercions.coerceToBoolean( 149 mCondition.evaluate(vr, f, l), l).booleanValue(); 150 151 if (condition) 153 return mTrueBranch.evaluate(vr, f, l); 154 else 155 return mFalseBranch.evaluate(vr, f, l); 156 } 157 158 } 160 | Popular Tags |