|
|||||||||||||||||||
30 day Evaluation License registered to hlship@comcast.net Your 30 day evaluation period has expired. Please visit http://www.cenqua.com to obtain a licensed version of Clover | |||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
DefaultScriptSource.java | 0% | 0% | 0% | 0% |
|
1 | // Copyright 2004, 2005 The Apache Software Foundation | |
2 | // | |
3 | // Licensed under the Apache License, Version 2.0 (the "License"); | |
4 | // you may not use this file except in compliance with the License. | |
5 | // You may obtain a copy of the License at | |
6 | // | |
7 | // http://www.apache.org/licenses/LICENSE-2.0 | |
8 | // | |
9 | // Unless required by applicable law or agreed to in writing, software | |
10 | // distributed under the License is distributed on an "AS IS" BASIS, | |
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
12 | // See the License for the specific language governing permissions and | |
13 | // limitations under the License. | |
14 | ||
15 | package org.apache.tapestry.engine; | |
16 | ||
17 | import java.util.HashMap; | |
18 | import java.util.Map; | |
19 | ||
20 | import org.apache.hivemind.ApplicationRuntimeException; | |
21 | import org.apache.hivemind.ClassResolver; | |
22 | import org.apache.hivemind.Resource; | |
23 | import org.apache.tapestry.IScript; | |
24 | import org.apache.tapestry.Tapestry; | |
25 | import org.apache.tapestry.coerce.ValueConverter; | |
26 | import org.apache.tapestry.event.ResetEventListener; | |
27 | import org.apache.tapestry.script.ScriptParser; | |
28 | import org.apache.tapestry.services.ExpressionEvaluator; | |
29 | import org.apache.tapestry.util.xml.DocumentParseException; | |
30 | ||
31 | /** | |
32 | * Provides basic access to scripts available on the classpath. Scripts are cached in memory once | |
33 | * parsed. | |
34 | * | |
35 | * @author Howard Lewis Ship | |
36 | * @since 1.0.2 | |
37 | */ | |
38 | ||
39 | public class DefaultScriptSource implements IScriptSource, ResetEventListener | |
40 | { | |
41 | private ClassResolver _classResolver; | |
42 | ||
43 | /** @since 4.0 */ | |
44 | private ExpressionEvaluator _expressionEvaluator; | |
45 | ||
46 | /** @since 4.0 */ | |
47 | private ValueConverter _valueConverter; | |
48 | ||
49 | private Map _cache = new HashMap(); | |
50 | ||
51 | 0 | public synchronized void resetEventDidOccur() |
52 | { | |
53 | 0 | _cache.clear(); |
54 | } | |
55 | ||
56 | 0 | public synchronized IScript getScript(Resource resource) |
57 | { | |
58 | 0 | IScript result = (IScript) _cache.get(resource); |
59 | ||
60 | 0 | if (result != null) |
61 | 0 | return result; |
62 | ||
63 | 0 | result = parse(resource); |
64 | ||
65 | 0 | _cache.put(resource, result); |
66 | ||
67 | 0 | return result; |
68 | } | |
69 | ||
70 | 0 | private IScript parse(Resource resource) |
71 | { | |
72 | 0 | ScriptParser parser = new ScriptParser(_classResolver, _expressionEvaluator, |
73 | _valueConverter); | |
74 | ||
75 | 0 | try |
76 | { | |
77 | 0 | return parser.parse(resource); |
78 | } | |
79 | catch (DocumentParseException ex) | |
80 | { | |
81 | 0 | throw new ApplicationRuntimeException(Tapestry.format( |
82 | "DefaultScriptSource.unable-to-parse-script", | |
83 | resource), ex); | |
84 | } | |
85 | } | |
86 | ||
87 | 0 | public void setClassResolver(ClassResolver classResolver) |
88 | { | |
89 | 0 | _classResolver = classResolver; |
90 | } | |
91 | ||
92 | /** @since 4.0 */ | |
93 | 0 | public void setExpressionEvaluator(ExpressionEvaluator expressionEvaluator) |
94 | { | |
95 | 0 | _expressionEvaluator = expressionEvaluator; |
96 | } | |
97 | ||
98 | /** @since 4.0 */ | |
99 | 0 | public void setValueConverter(ValueConverter valueConverter) |
100 | { | |
101 | 0 | _valueConverter = valueConverter; |
102 | } | |
103 | } |
|