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 72 73 public class BinaryOperatorExpression 74 extends Expression 75 { 76 81 Expression mExpression; 82 public Expression getExpression () 83 { return mExpression; } 84 public void setExpression (Expression pExpression) 85 { mExpression = pExpression; } 86 87 90 List mOperators; 91 public List getOperators () 92 { return mOperators; } 93 public void setOperators (List pOperators) 94 { mOperators = pOperators; } 95 96 99 List mExpressions; 100 public List getExpressions () 101 { return mExpressions; } 102 public void setExpressions (List pExpressions) 103 { mExpressions = pExpressions; } 104 105 110 public BinaryOperatorExpression (Expression pExpression, 111 List pOperators, 112 List pExpressions) 113 { 114 mExpression = pExpression; 115 mOperators = pOperators; 116 mExpressions = pExpressions; 117 } 118 119 126 public String getExpressionString () 127 { 128 StringBuffer buf = new StringBuffer (); 129 buf.append ("("); 130 buf.append (mExpression.getExpressionString ()); 131 for (int i = 0; i < mOperators.size (); i++) { 132 BinaryOperator operator = (BinaryOperator) mOperators.get (i); 133 Expression expression = (Expression) mExpressions.get (i); 134 buf.append (" "); 135 buf.append (operator.getOperatorSymbol ()); 136 buf.append (" "); 137 buf.append (expression.getExpressionString ()); 138 } 139 buf.append (")"); 140 141 return buf.toString (); 142 } 143 144 149 public Object evaluate (VariableResolver pResolver, 150 FunctionMapper functions, 151 Logger pLogger) 152 throws ELException 153 { 154 Object value = mExpression.evaluate (pResolver, functions, pLogger); 155 for (int i = 0; i < mOperators.size (); i++) { 156 BinaryOperator operator = (BinaryOperator) mOperators.get (i); 157 158 if (operator.shouldCoerceToBoolean ()) { 161 value = Coercions.coerceToBoolean (value, pLogger); 162 } 163 164 if (operator.shouldEvaluate (value)) { 165 Expression expression = (Expression) mExpressions.get (i); 166 Object nextValue = expression.evaluate (pResolver, 167 functions, 168 pLogger); 169 170 value = operator.apply (value, nextValue, pLogger); 171 } 172 } 173 return value; 174 } 175 176 } 178 | Popular Tags |