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 |
| |
24 |
| |
25 |
| |
26 |
| |
27 |
| |
28 |
| |
29 |
| |
30 |
| |
31 |
| abstract class AbstractToken implements IScriptToken |
32 |
| { |
33 |
| private List _tokens; |
34 |
| |
35 |
| private Location _location; |
36 |
| |
37 |
166
| protected AbstractToken(Location location)
|
38 |
| { |
39 |
166
| _location = location;
|
40 |
| } |
41 |
| |
42 |
12
| public Location getLocation()
|
43 |
| { |
44 |
12
| return _location;
|
45 |
| } |
46 |
| |
47 |
130
| public void addToken(IScriptToken token)
|
48 |
| { |
49 |
130
| if (_tokens == null)
|
50 |
72
| _tokens = new ArrayList();
|
51 |
| |
52 |
130
| _tokens.add(token);
|
53 |
| } |
54 |
| |
55 |
| |
56 |
| |
57 |
| |
58 |
| |
59 |
| |
60 |
78
| protected void writeChildren(StringBuffer buffer, ScriptSession session)
|
61 |
| { |
62 |
78
| if (_tokens == null)
|
63 |
2
| return;
|
64 |
| |
65 |
76
| Iterator i = _tokens.iterator();
|
66 |
| |
67 |
76
| while (i.hasNext())
|
68 |
| { |
69 |
146
| IScriptToken token = (IScriptToken) i.next();
|
70 |
| |
71 |
146
| token.write(buffer, session);
|
72 |
| } |
73 |
| } |
74 |
| |
75 |
| |
76 |
| |
77 |
| |
78 |
| |
79 |
12
| protected Object evaluate(String expression, ScriptSession session)
|
80 |
| { |
81 |
| |
82 |
12
| try
|
83 |
| { |
84 |
12
| return session.evaluate(expression);
|
85 |
| } |
86 |
| catch (Exception ex) |
87 |
| { |
88 |
0
| throw new ApplicationRuntimeException(ex.getMessage(), _location, ex);
|
89 |
| } |
90 |
| } |
91 |
| |
92 |
| |
93 |
| |
94 |
| |
95 |
| |
96 |
| |
97 |
| |
98 |
8
| protected boolean evaluateBoolean(String expression, ScriptSession session)
|
99 |
| { |
100 |
8
| try
|
101 |
| { |
102 |
8
| Boolean b = (Boolean) session.evaluate(expression, Boolean.class);
|
103 |
| |
104 |
6
| return b.booleanValue();
|
105 |
| } |
106 |
| catch (Exception ex) |
107 |
| { |
108 |
2
| throw new ApplicationRuntimeException(ex.getMessage(), _location, ex);
|
109 |
| } |
110 |
| } |
111 |
| } |