1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| |
8 |
| |
9 |
| |
10 |
| |
11 |
| |
12 |
| |
13 |
| |
14 |
| |
15 |
| package org.apache.tapestry.script; |
16 |
| |
17 |
| import java.util.ArrayList; |
18 |
| import java.util.Iterator; |
19 |
| import java.util.List; |
20 |
| |
21 |
| import org.apache.hivemind.ApplicationRuntimeException; |
22 |
| import org.apache.hivemind.Location; |
23 |
| import org.apache.tapestry.services.ExpressionEvaluator; |
24 |
| |
25 |
| |
26 |
| |
27 |
| |
28 |
| |
29 |
| |
30 |
| |
31 |
| |
32 |
| abstract class AbstractToken implements IScriptToken |
33 |
| { |
34 |
| private List _tokens; |
35 |
| |
36 |
| private Location _location; |
37 |
| |
38 |
83
| protected AbstractToken(Location location)
|
39 |
| { |
40 |
83
| _location = location;
|
41 |
| } |
42 |
| |
43 |
6
| public Location getLocation()
|
44 |
| { |
45 |
6
| return _location;
|
46 |
| } |
47 |
| |
48 |
65
| public void addToken(IScriptToken token)
|
49 |
| { |
50 |
65
| if (_tokens == null)
|
51 |
36
| _tokens = new ArrayList();
|
52 |
| |
53 |
65
| _tokens.add(token);
|
54 |
| } |
55 |
| |
56 |
| |
57 |
| |
58 |
| |
59 |
| |
60 |
| |
61 |
39
| protected void writeChildren(StringBuffer buffer, ScriptSession session)
|
62 |
| { |
63 |
39
| if (_tokens == null)
|
64 |
1
| return;
|
65 |
| |
66 |
38
| Iterator i = _tokens.iterator();
|
67 |
| |
68 |
38
| while (i.hasNext())
|
69 |
| { |
70 |
73
| IScriptToken token = (IScriptToken) i.next();
|
71 |
| |
72 |
73
| token.write(buffer, session);
|
73 |
| } |
74 |
| } |
75 |
| |
76 |
| |
77 |
| |
78 |
| |
79 |
| |
80 |
6
| protected Object evaluate(String expression, ScriptSession session)
|
81 |
| { |
82 |
| |
83 |
6
| try
|
84 |
| { |
85 |
6
| return session.evaluate(expression);
|
86 |
| } |
87 |
| catch (Exception ex) |
88 |
| { |
89 |
0
| throw new ApplicationRuntimeException(ex.getMessage(), _location, ex);
|
90 |
| } |
91 |
| } |
92 |
| |
93 |
| |
94 |
| |
95 |
| |
96 |
| |
97 |
| |
98 |
| |
99 |
4
| protected boolean evaluateBoolean(String expression, ScriptSession session)
|
100 |
| { |
101 |
4
| try
|
102 |
| { |
103 |
4
| Boolean b = (Boolean) session.evaluate(expression, Boolean.class);
|
104 |
| |
105 |
3
| return b.booleanValue();
|
106 |
| } |
107 |
| catch (Exception ex) |
108 |
| { |
109 |
1
| throw new ApplicationRuntimeException(ex.getMessage(), _location, ex);
|
110 |
| } |
111 |
| } |
112 |
| } |