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.IRequestCycle;
022    import org.apache.tapestry.IScript;
023    import org.apache.tapestry.IScriptProcessor;
024    import org.apache.tapestry.coerce.ValueConverter;
025    import org.apache.tapestry.services.ExpressionEvaluator;
026    
027    /**
028     * A top level container for a number of {@link IScriptToken script tokens}.
029     * 
030     * @author Howard Lewis Ship
031     * @since 0.2.9
032     */
033    
034    public class ParsedScript extends AbstractToken implements IScript
035    {
036        private Resource _scriptResource;
037    
038        private ExpressionEvaluator _evaluator;
039    
040        /** @since 4.0 */
041    
042        private ValueConverter _valueConverter;
043    
044        public ParsedScript(ExpressionEvaluator evaluator, ValueConverter valueConverter,
045                Location location)
046        {
047            super(location);
048    
049            _evaluator = evaluator;
050            _valueConverter = valueConverter;
051            _scriptResource = location.getResource();
052        }
053    
054        public Resource getScriptResource()
055        {
056            return _scriptResource;
057        }
058    
059        /**
060         * Creates the {@link ScriptSessionImpl}and invokes
061         * {@link org.apache.tapestry.script.AbstractToken#writeChildren(java.lang.StringBuffer, org.apache.tapestry.script.ScriptSession)}.
062         */
063        public void execute(IRequestCycle cycle, IScriptProcessor processor, Map symbols)
064        {
065            ScriptSession session = new ScriptSessionImpl(_scriptResource, cycle, processor,
066                    _evaluator, _valueConverter, symbols);
067    
068            writeChildren(null, session);
069        }
070    
071        /**
072         * Does nothing; never invoked.
073         */
074        public void write(StringBuffer buffer, ScriptSession session)
075        {
076    
077        }
078    
079    }