1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.el;
18
19 import java.util.List;
20
21 import javax.servlet.jsp.el.ELException;
22 import javax.servlet.jsp.el.FunctionMapper;
23 import javax.servlet.jsp.el.VariableResolver;
24
25
26
27
28
29
30
31
32
33
34
35 public class UnaryOperatorExpression
36 extends Expression
37 {
38
39
40
41
42
43 UnaryOperator mOperator;
44 public UnaryOperator getOperator ()
45 { return mOperator; }
46 public void setOperator (UnaryOperator pOperator)
47 { mOperator = pOperator; }
48
49
50
51
52 List mOperators;
53 public List getOperators ()
54 { return mOperators; }
55 public void setOperators (List pOperators)
56 { mOperators = pOperators; }
57
58
59
60
61 Expression mExpression;
62 public Expression getExpression ()
63 { return mExpression; }
64 public void setExpression (Expression pExpression)
65 { mExpression = pExpression; }
66
67
68
69
70
71
72 public UnaryOperatorExpression (UnaryOperator pOperator,
73 List pOperators,
74 Expression pExpression)
75 {
76 mOperator = pOperator;
77 mOperators = pOperators;
78 mExpression = pExpression;
79 }
80
81
82
83
84
85
86
87
88 public String getExpressionString ()
89 {
90 StringBuffer buf = new StringBuffer ();
91 buf.append ("(");
92 if (mOperator != null) {
93 buf.append (mOperator.getOperatorSymbol ());
94 buf.append (" ");
95 }
96 else {
97 for (int i = 0, size = mOperators.size(); i < size; i++) {
98 UnaryOperator operator = (UnaryOperator) mOperators.get (i);
99 buf.append (operator.getOperatorSymbol ());
100 buf.append (" ");
101 }
102 }
103 buf.append (mExpression.getExpressionString ());
104 buf.append (")");
105 return buf.toString ();
106 }
107
108
109
110
111
112
113 public Object evaluate (VariableResolver pResolver, FunctionMapper functions)
114 throws ELException
115 {
116 Object value = mExpression.evaluate (pResolver, functions);
117 if (mOperator != null) {
118 value = mOperator.apply (value);
119 }
120 else {
121 for (int i = mOperators.size () - 1; i >= 0; i--) {
122 UnaryOperator operator = (UnaryOperator) mOperators.get (i);
123 value = operator.apply (value);
124 }
125 }
126 return value;
127 }
128
129 public Expression bindFunctions(final FunctionMapper functions) throws ELException {
130 return new UnaryOperatorExpression(
131 mOperator,
132 mOperators,
133 mExpression.bindFunctions(functions));
134 }
135
136
137 }