|
|||||||||||||||||||
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover | |||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
DefaultScriptSource.java | 100% | 85.7% | 83.3% | 86.4% |
|
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 | 5 |
public synchronized IScript getScript(Resource resource) |
57 |
{ |
|
58 | 5 |
IScript result = (IScript) _cache.get(resource); |
59 |
|
|
60 | 5 |
if (result != null) |
61 | 3 |
return result;
|
62 |
|
|
63 | 2 |
result = parse(resource); |
64 |
|
|
65 | 2 |
_cache.put(resource, result); |
66 |
|
|
67 | 2 |
return result;
|
68 |
} |
|
69 |
|
|
70 | 2 |
private IScript parse(Resource resource)
|
71 |
{ |
|
72 | 2 |
ScriptParser parser = new ScriptParser(_classResolver, _expressionEvaluator,
|
73 |
_valueConverter); |
|
74 |
|
|
75 | 2 |
try
|
76 |
{ |
|
77 | 2 |
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 | 2 |
public void setClassResolver(ClassResolver classResolver) |
88 |
{ |
|
89 | 2 |
_classResolver = classResolver; |
90 |
} |
|
91 |
|
|
92 |
/** @since 4.0 */
|
|
93 | 2 |
public void setExpressionEvaluator(ExpressionEvaluator expressionEvaluator) |
94 |
{ |
|
95 | 2 |
_expressionEvaluator = expressionEvaluator; |
96 |
} |
|
97 |
|
|
98 |
/** @since 4.0 */
|
|
99 | 2 |
public void setValueConverter(ValueConverter valueConverter) |
100 |
{ |
|
101 | 2 |
_valueConverter = valueConverter; |
102 |
} |
|
103 |
} |
|