1 15 package org.apache.tapestry.script; 16 17 import java.util.Map ; 18 19 import org.apache.hivemind.Resource; 20 import org.apache.tapestry.IRequestCycle; 21 import org.apache.tapestry.IScriptProcessor; 22 import org.apache.tapestry.coerce.ValueConverter; 23 import org.apache.tapestry.services.ExpressionEvaluator; 24 25 35 36 public class ScriptSessionImpl implements ScriptSession 37 { 38 private IRequestCycle _cycle; 39 40 private IScriptProcessor _processor; 41 42 private Resource _scriptTemplateResource; 43 44 private Map _symbols; 45 46 47 private ExpressionEvaluator _evaluator; 48 49 50 private ValueConverter _valueConverter; 51 52 public ScriptSessionImpl(Resource scriptTemplateResource, IRequestCycle cycle, 53 IScriptProcessor processor, ExpressionEvaluator evaluator, 54 ValueConverter valueConverter, Map symbols) 55 { 56 _scriptTemplateResource = scriptTemplateResource; 57 _cycle = cycle; 58 _processor = processor; 59 _symbols = symbols; 60 _evaluator = evaluator; 61 _valueConverter = valueConverter; 62 } 63 64 public Object evaluate(String expression) 65 { 66 return _evaluator.read(_symbols, expression); 67 } 68 69 public Object evaluate(String expression, Class desiredType) 70 { 71 Object raw = evaluate(expression); 72 73 return _valueConverter.coerceValue(raw, desiredType); 74 } 75 76 public Resource getScriptTemplateResource() 77 { 78 return _scriptTemplateResource; 79 } 80 81 public Map getSymbols() 82 { 83 return _symbols; 84 } 85 86 public IRequestCycle getRequestCycle() 87 { 88 return _cycle; 89 } 90 91 public void addBodyScript(String script) 92 { 93 _processor.addBodyScript(script); 94 } 95 96 public void addExternalScript(Resource resource) 97 { 98 _processor.addExternalScript(resource); 99 } 100 101 public void addInitializationScript(String script) 102 { 103 _processor.addInitializationScript(script); 104 } 105 106 public String getUniqueString(String baseValue) 107 { 108 return _processor.getUniqueString(baseValue); 109 } 110 111 public String toString() 112 { 113 StringBuffer buffer = new StringBuffer (); 114 115 buffer.append("ScriptSession["); 116 buffer.append(_scriptTemplateResource); 117 buffer.append(']'); 118 119 return buffer.toString(); 120 } 121 } | Popular Tags |