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 javax.servlet.jsp.el.ELException;
20 import javax.servlet.jsp.el.FunctionMapper;
21 import javax.servlet.jsp.el.VariableResolver;
22
23
24
25
26
27
28
29
30
31
32
33
34 public class ConditionalExpression
35 extends Expression
36 {
37
38
39
40
41
42 Expression mCondition;
43 public Expression getCondition ()
44 { return mCondition; }
45 public void setCondition (Expression pCondition)
46 { mCondition = pCondition; }
47
48
49
50
51 Expression mTrueBranch;
52 public Expression getTrueBranch ()
53 { return mTrueBranch; }
54 public void setTrueBranch (Expression pTrueBranch)
55 { mTrueBranch = pTrueBranch; }
56
57
58
59
60 Expression mFalseBranch;
61 public Expression getFalseBranch ()
62 { return mFalseBranch; }
63 public void setFalseBranch (Expression pFalseBranch)
64 { mFalseBranch = pFalseBranch; }
65
66
67
68
69
70
71 public ConditionalExpression (Expression pCondition,
72 Expression pTrueBranch,
73 Expression pFalseBranch)
74 {
75 mCondition = pCondition;
76 mTrueBranch = pTrueBranch;
77 mFalseBranch = pFalseBranch;
78 }
79
80
81
82
83
84
85
86
87 public String getExpressionString ()
88 {
89 return
90 "( " + mCondition.getExpressionString() + " ? " +
91 mTrueBranch.getExpressionString() + " : " +
92 mFalseBranch.getExpressionString() + " )";
93 }
94
95
96
97
98
99
100 public Object evaluate (VariableResolver vr,
101 FunctionMapper f)
102 throws ELException
103 {
104
105 boolean condition =
106 Coercions.coerceToBoolean(
107 mCondition.evaluate(vr, f)).booleanValue();
108
109
110 if (condition)
111 return mTrueBranch.evaluate(vr, f);
112 else
113 return mFalseBranch.evaluate(vr, f);
114 }
115
116 public Expression bindFunctions(final FunctionMapper functions) throws ELException {
117 return new ConditionalExpression(
118 mCondition.bindFunctions(functions),
119 mTrueBranch.bindFunctions(functions),
120 mFalseBranch.bindFunctions(functions));
121 }
122
123
124 }