|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| package org.apache.tapestry.binding; |
|
16 |
| |
|
17 |
| import org.apache.hivemind.Location; |
|
18 |
| import org.apache.tapestry.BindingException; |
|
19 |
| import org.apache.tapestry.IComponent; |
|
20 |
| import org.apache.tapestry.coerce.ValueConverter; |
|
21 |
| import org.apache.tapestry.services.ExpressionCache; |
|
22 |
| import org.apache.tapestry.services.ExpressionEvaluator; |
|
23 |
| |
|
24 |
| |
|
25 |
| |
|
26 |
| |
|
27 |
| |
|
28 |
| |
|
29 |
| |
|
30 |
| |
|
31 |
| |
|
32 |
| |
|
33 |
| |
|
34 |
| public class ExpressionBinding extends AbstractBinding |
|
35 |
| { |
|
36 |
| |
|
37 |
| |
|
38 |
| |
|
39 |
| |
|
40 |
| private final IComponent _root; |
|
41 |
| |
|
42 |
| |
|
43 |
| |
|
44 |
| |
|
45 |
| |
|
46 |
| private String _expression; |
|
47 |
| |
|
48 |
| |
|
49 |
| |
|
50 |
| |
|
51 |
| |
|
52 |
| private boolean _invariant = false; |
|
53 |
| |
|
54 |
| |
|
55 |
| |
|
56 |
| |
|
57 |
| |
|
58 |
| private Object _parsedExpression; |
|
59 |
| |
|
60 |
| |
|
61 |
| |
|
62 |
| |
|
63 |
| |
|
64 |
| private boolean _initialized; |
|
65 |
| |
|
66 |
| |
|
67 |
| |
|
68 |
| |
|
69 |
| |
|
70 |
| private ExpressionEvaluator _evaluator; |
|
71 |
| |
|
72 |
| |
|
73 |
| |
|
74 |
| private ExpressionCache _cache; |
|
75 |
| |
|
76 |
| |
|
77 |
| |
|
78 |
| |
|
79 |
| |
|
80 |
3333
| public ExpressionBinding(String description, Location location, ValueConverter valueConverter,
|
|
81 |
| IComponent root, String expression, ExpressionEvaluator evaluator, |
|
82 |
| ExpressionCache cache) |
|
83 |
| { |
|
84 |
3333
| super(description, valueConverter, location);
|
|
85 |
| |
|
86 |
3333
| _root = root;
|
|
87 |
3333
| _expression = expression;
|
|
88 |
3333
| _evaluator = evaluator;
|
|
89 |
3333
| _cache = cache;
|
|
90 |
| } |
|
91 |
| |
|
92 |
| |
|
93 |
| |
|
94 |
| |
|
95 |
| |
|
96 |
| |
|
97 |
| |
|
98 |
| |
|
99 |
6360
| public Object getObject()
|
|
100 |
| { |
|
101 |
6360
| initialize();
|
|
102 |
| |
|
103 |
6360
| return resolveExpression();
|
|
104 |
| } |
|
105 |
| |
|
106 |
6360
| private Object resolveExpression()
|
|
107 |
| { |
|
108 |
6360
| try
|
|
109 |
| { |
|
110 |
6360
| return _evaluator.readCompiled(_root, _parsedExpression);
|
|
111 |
| } |
|
112 |
| catch (Throwable t) |
|
113 |
| { |
|
114 |
6
| throw new BindingException(t.getMessage(), this, t);
|
|
115 |
| } |
|
116 |
| } |
|
117 |
| |
|
118 |
| |
|
119 |
| |
|
120 |
| |
|
121 |
| |
|
122 |
6864
| public boolean isInvariant()
|
|
123 |
| { |
|
124 |
6864
| initialize();
|
|
125 |
| |
|
126 |
6861
| return _invariant;
|
|
127 |
| } |
|
128 |
| |
|
129 |
| |
|
130 |
| |
|
131 |
| |
|
132 |
| |
|
133 |
| |
|
134 |
16794
| private void initialize()
|
|
135 |
| { |
|
136 |
16794
| if (_initialized)
|
|
137 |
14016
| return;
|
|
138 |
| |
|
139 |
2778
| _initialized = true;
|
|
140 |
| |
|
141 |
2778
| try
|
|
142 |
| { |
|
143 |
2778
| _parsedExpression = _cache.getCompiledExpression(_expression);
|
|
144 |
| |
|
145 |
2775
| _invariant = _evaluator.isConstant(_expression);
|
|
146 |
| } |
|
147 |
| catch (Exception ex) |
|
148 |
| { |
|
149 |
3
| throw new BindingException(ex.getMessage(), this, ex);
|
|
150 |
| } |
|
151 |
| } |
|
152 |
| |
|
153 |
| |
|
154 |
| |
|
155 |
| |
|
156 |
| |
|
157 |
| |
|
158 |
| |
|
159 |
| |
|
160 |
| |
|
161 |
| |
|
162 |
| |
|
163 |
3570
| public void setObject(Object value)
|
|
164 |
| { |
|
165 |
3570
| initialize();
|
|
166 |
| |
|
167 |
3570
| if (_invariant)
|
|
168 |
3
| throw createReadOnlyBindingException(this);
|
|
169 |
| |
|
170 |
3567
| try
|
|
171 |
| { |
|
172 |
3567
| _evaluator.writeCompiled(_root, _parsedExpression, value);
|
|
173 |
| } |
|
174 |
| catch (Throwable ex) |
|
175 |
| { |
|
176 |
3
| throw new BindingException(ex.getMessage(), this, ex);
|
|
177 |
| } |
|
178 |
| } |
|
179 |
| |
|
180 |
| |
|
181 |
| |
|
182 |
| |
|
183 |
| |
|
184 |
| |
|
185 |
| |
|
186 |
12
| public String toString()
|
|
187 |
| { |
|
188 |
12
| StringBuffer buffer = new StringBuffer();
|
|
189 |
| |
|
190 |
12
| buffer.append("ExpressionBinding[");
|
|
191 |
12
| buffer.append(_root.getExtendedId());
|
|
192 |
| |
|
193 |
12
| if (_expression != null)
|
|
194 |
| { |
|
195 |
12
| buffer.append(' ');
|
|
196 |
12
| buffer.append(_expression);
|
|
197 |
| } |
|
198 |
| |
|
199 |
12
| buffer.append(']');
|
|
200 |
| |
|
201 |
12
| return buffer.toString();
|
|
202 |
| } |
|
203 |
| |
|
204 |
| |
|
205 |
3
| public Object getComponent()
|
|
206 |
| { |
|
207 |
3
| return _root;
|
|
208 |
| } |
|
209 |
| } |