1 55 56 package org.apache.commons.el; 57 58 import java.util.List ; 59 import javax.servlet.jsp.el.ELException ; 60 import javax.servlet.jsp.el.VariableResolver ; 61 import javax.servlet.jsp.el.FunctionMapper ; 62 63 72 73 public class UnaryOperatorExpression 74 extends Expression 75 { 76 81 UnaryOperator mOperator; 82 public UnaryOperator getOperator () 83 { return mOperator; } 84 public void setOperator (UnaryOperator pOperator) 85 { mOperator = pOperator; } 86 87 90 List mOperators; 91 public List getOperators () 92 { return mOperators; } 93 public void setOperators (List pOperators) 94 { mOperators = pOperators; } 95 96 99 Expression mExpression; 100 public Expression getExpression () 101 { return mExpression; } 102 public void setExpression (Expression pExpression) 103 { mExpression = pExpression; } 104 105 110 public UnaryOperatorExpression (UnaryOperator pOperator, 111 List pOperators, 112 Expression pExpression) 113 { 114 mOperator = pOperator; 115 mOperators = pOperators; 116 mExpression = pExpression; 117 } 118 119 126 public String getExpressionString () 127 { 128 StringBuffer buf = new StringBuffer (); 129 buf.append ("("); 130 if (mOperator != null) { 131 buf.append (mOperator.getOperatorSymbol ()); 132 buf.append (" "); 133 } 134 else { 135 for (int i = 0; i < mOperators.size (); i++) { 136 UnaryOperator operator = (UnaryOperator) mOperators.get (i); 137 buf.append (operator.getOperatorSymbol ()); 138 buf.append (" "); 139 } 140 } 141 buf.append (mExpression.getExpressionString ()); 142 buf.append (")"); 143 return buf.toString (); 144 } 145 146 151 public Object evaluate (VariableResolver pResolver, 152 FunctionMapper functions, 153 Logger pLogger) 154 throws ELException 155 { 156 Object value = mExpression.evaluate (pResolver, functions, pLogger); 157 if (mOperator != null) { 158 value = mOperator.apply (value, pLogger); 159 } 160 else { 161 for (int i = mOperators.size () - 1; i >= 0; i--) { 162 UnaryOperator operator = (UnaryOperator) mOperators.get (i); 163 value = operator.apply (value, pLogger); 164 } 165 } 166 return value; 167 } 168 169 } 171 | Popular Tags |