1 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 38 39 public class DefaultScriptSource implements IScriptSource, ResetEventListener 40 { 41 private ClassResolver _classResolver; 42 43 44 private ExpressionEvaluator _expressionEvaluator; 45 46 47 private ValueConverter _valueConverter; 48 49 private Map _cache = new HashMap (); 50 51 public synchronized void resetEventDidOccur() 52 { 53 _cache.clear(); 54 } 55 56 public synchronized IScript getScript(Resource resource) 57 { 58 IScript result = (IScript) _cache.get(resource); 59 60 if (result != null) 61 return result; 62 63 result = parse(resource); 64 65 _cache.put(resource, result); 66 67 return result; 68 } 69 70 private IScript parse(Resource resource) 71 { 72 ScriptParser parser = new ScriptParser(_classResolver, _expressionEvaluator, 73 _valueConverter); 74 75 try 76 { 77 return parser.parse(resource); 78 } 79 catch (DocumentParseException ex) 80 { 81 throw new ApplicationRuntimeException(Tapestry.format( 82 "DefaultScriptSource.unable-to-parse-script", 83 resource), ex); 84 } 85 } 86 87 public void setClassResolver(ClassResolver classResolver) 88 { 89 _classResolver = classResolver; 90 } 91 92 93 public void setExpressionEvaluator(ExpressionEvaluator expressionEvaluator) 94 { 95 _expressionEvaluator = expressionEvaluator; 96 } 97 98 99 public void setValueConverter(ValueConverter valueConverter) 100 { 101 _valueConverter = valueConverter; 102 } 103 } | Popular Tags |