1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| |
8 |
| |
9 |
| |
10 |
| |
11 |
| |
12 |
| |
13 |
| |
14 |
| |
15 |
| package org.apache.tapestry.script; |
16 |
| |
17 |
| import org.apache.hivemind.ApplicationRuntimeException; |
18 |
| import org.apache.hivemind.Location; |
19 |
| import org.apache.tapestry.Tapestry; |
20 |
| |
21 |
| |
22 |
| |
23 |
| |
24 |
| |
25 |
| |
26 |
| |
27 |
| |
28 |
| |
29 |
| |
30 |
| |
31 |
| class InputSymbolToken extends AbstractToken |
32 |
| { |
33 |
| private String _key; |
34 |
| private Class _class; |
35 |
| private boolean _required; |
36 |
| |
37 |
4
| InputSymbolToken(String key, Class clazz, boolean required, Location location)
|
38 |
| { |
39 |
4
| super(location);
|
40 |
| |
41 |
4
| _key = key;
|
42 |
4
| _class = clazz;
|
43 |
4
| _required = required;
|
44 |
| } |
45 |
| |
46 |
4
| public void write(StringBuffer buffer, ScriptSession session)
|
47 |
| { |
48 |
4
| Object value = session.getSymbols().get(_key);
|
49 |
| |
50 |
4
| if (_required && value == null)
|
51 |
1
| throw new ApplicationRuntimeException(
|
52 |
| Tapestry.format("InputSymbolToken.required", _key), |
53 |
| getLocation(), |
54 |
| null); |
55 |
| |
56 |
3
| if (value != null && _class != null && !_class.isAssignableFrom(value.getClass()))
|
57 |
1
| throw new ApplicationRuntimeException(
|
58 |
| Tapestry.format( |
59 |
| "InputSymbolToken.wrong-type", |
60 |
| _key, |
61 |
| value.getClass().getName(), |
62 |
| _class.getName()), |
63 |
| getLocation(), |
64 |
| null); |
65 |
| } |
66 |
| |
67 |
| } |