001 // Copyright 2004, 2005 The Apache Software Foundation 002 // 003 // Licensed under the Apache License, Version 2.0 (the "License"); 004 // you may not use this file except in compliance with the License. 005 // You may obtain a copy of the License at 006 // 007 // http://www.apache.org/licenses/LICENSE-2.0 008 // 009 // Unless required by applicable law or agreed to in writing, software 010 // distributed under the License is distributed on an "AS IS" BASIS, 011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 012 // See the License for the specific language governing permissions and 013 // limitations under the License. 014 015 package org.apache.tapestry.script; 016 017 import java.util.Map; 018 019 import org.apache.hivemind.Location; 020 import org.apache.hivemind.Resource; 021 import org.apache.tapestry.IComponent; 022 import org.apache.tapestry.IRequestCycle; 023 import org.apache.tapestry.IScript; 024 import org.apache.tapestry.IScriptProcessor; 025 import org.apache.tapestry.coerce.ValueConverter; 026 import org.apache.tapestry.services.ExpressionEvaluator; 027 028 /** 029 * A top level container for a number of {@link IScriptToken script tokens}. 030 * 031 * @author Howard Lewis Ship 032 * @since 0.2.9 033 */ 034 035 public class ParsedScript extends AbstractToken implements IScript 036 { 037 038 private Resource _scriptResource; 039 040 private ExpressionEvaluator _evaluator; 041 042 /** @since 4.0 */ 043 044 private ValueConverter _valueConverter; 045 046 public ParsedScript(ExpressionEvaluator evaluator, 047 ValueConverter valueConverter, Location location) 048 { 049 super(location); 050 051 _evaluator = evaluator; 052 _valueConverter = valueConverter; 053 _scriptResource = location.getResource(); 054 } 055 056 public Resource getScriptResource() 057 { 058 return _scriptResource; 059 } 060 061 /** 062 * Creates the {@link ScriptSessionImpl}and invokes 063 * {@link org.apache.tapestry.script.AbstractToken#writeChildren(java.lang.StringBuffer, org.apache.tapestry.script.ScriptSession)}. 064 */ 065 public void execute(IRequestCycle cycle, IScriptProcessor processor, Map symbols) 066 { 067 ScriptSession session = new ScriptSessionImpl(_scriptResource, cycle, 068 processor, _evaluator, _valueConverter, symbols); 069 070 writeChildren(null, session); 071 } 072 073 /** 074 * {@inheritDoc} 075 */ 076 public void execute(IComponent target, IRequestCycle cycle, IScriptProcessor processor, 077 Map symbols) 078 { 079 ScriptSession session = new ScriptSessionImpl(_scriptResource, target, cycle, 080 processor, _evaluator, _valueConverter, symbols); 081 082 writeChildren(null, session); 083 } 084 085 /** 086 * Does nothing; never invoked. 087 */ 088 public void write(StringBuffer buffer, ScriptSession session) 089 { 090 091 } 092 093 }