Coverage Report - org.apache.tapestry.script.ScriptSessionImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
ScriptSessionImpl
0%
0/50
0%
0/8
1.211
 
 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.script;
 16  
 
 17  
 import org.apache.hivemind.Resource;
 18  
 import org.apache.tapestry.IComponent;
 19  
 import org.apache.tapestry.IRequestCycle;
 20  
 import org.apache.tapestry.IScriptProcessor;
 21  
 import org.apache.tapestry.coerce.ValueConverter;
 22  
 import org.apache.tapestry.services.ExpressionEvaluator;
 23  
 
 24  
 import java.util.Map;
 25  
 
 26  
 /**
 27  
  * The result of executing a script, the session is used during the parsing
 28  
  * process as well. Following
 29  
  * {@link org.apache.tapestry.IScript#execute(IComponent, org.apache.tapestry.IRequestCycle, org.apache.tapestry.IScriptProcessor, java.util.Map)},
 30  
  * the session provides access to output symbols as well as the body and
 31  
  * initialization blocks created by the script tokens.
 32  
  *
 33  
  * @author Howard Lewis Ship
 34  
  * @since 0.2.9
 35  
  */
 36  
 
 37  
 public class ScriptSessionImpl implements ScriptSession
 38  
 {
 39  
 
 40  
     private IRequestCycle _cycle;
 41  
 
 42  
     private IScriptProcessor _processor;
 43  
 
 44  
     private Resource _scriptTemplateResource;
 45  
 
 46  
     private Map _symbols;
 47  
 
 48  
     /** @since 4.0 */
 49  
     private ExpressionEvaluator _evaluator;
 50  
 
 51  
     /** @since 4.0 */
 52  
     private ValueConverter _valueConverter;
 53  
 
 54  
     private IComponent _component;
 55  
 
 56  
     public ScriptSessionImpl(Resource scriptTemplateResource,
 57  
                              IRequestCycle cycle, IScriptProcessor processor,
 58  
                              ExpressionEvaluator evaluator, ValueConverter valueConverter,
 59  
                              Map symbols)
 60  0
     {
 61  0
         _scriptTemplateResource = scriptTemplateResource;
 62  0
         _cycle = cycle;
 63  0
         _processor = processor;
 64  0
         _symbols = symbols;
 65  0
         _evaluator = evaluator;
 66  0
         _valueConverter = valueConverter;
 67  0
     }
 68  
 
 69  
     public ScriptSessionImpl(Resource scriptTemplateResource,
 70  
                              IComponent component,
 71  
                              IRequestCycle cycle, IScriptProcessor processor,
 72  
                              ExpressionEvaluator evaluator, ValueConverter valueConverter,
 73  
                              Map symbols)
 74  0
     {
 75  0
         _scriptTemplateResource = scriptTemplateResource;
 76  0
         _component = component;
 77  0
         _cycle = cycle;
 78  0
         _processor = processor;
 79  0
         _symbols = symbols;
 80  0
         _evaluator = evaluator;
 81  0
         _valueConverter = valueConverter;
 82  0
     }
 83  
 
 84  
     public Object evaluate(String expression)
 85  
     {
 86  0
         return _evaluator.read(_symbols, expression); //_evaluator.read(_symbols, expression);
 87  
     }
 88  
 
 89  
     public Object evaluate(String expression, Class desiredType)
 90  
     {
 91  0
         Object raw = evaluate(expression);
 92  
 
 93  0
         return _valueConverter.coerceValue(raw, desiredType);
 94  
     }
 95  
 
 96  
     public Resource getScriptTemplateResource()
 97  
     {
 98  0
         return _scriptTemplateResource;
 99  
     }
 100  
 
 101  
     public Map getSymbols()
 102  
     {
 103  0
         return _symbols;
 104  
     }
 105  
 
 106  
     public IRequestCycle getRequestCycle()
 107  
     {
 108  0
         return _cycle;
 109  
     }
 110  
 
 111  
     public void addBodyScript(String script)
 112  
     {
 113  0
         addBodyScript(_component, script);
 114  0
     }
 115  
 
 116  
     /**
 117  
      * {@inheritDoc}
 118  
      */
 119  
     public boolean isBodyScriptAllowed(IComponent target)
 120  
     {
 121  0
         return _processor.isBodyScriptAllowed(target);
 122  
     }
 123  
 
 124  
     /**
 125  
      * {@inheritDoc}
 126  
      */
 127  
     public boolean isExternalScriptAllowed(IComponent target)
 128  
     {
 129  0
         return _processor.isExternalScriptAllowed(target);
 130  
     }
 131  
 
 132  
     /**
 133  
      * {@inheritDoc}
 134  
      */
 135  
     public boolean isInitializationScriptAllowed(IComponent target)
 136  
     {
 137  0
         return _processor.isInitializationScriptAllowed(target);
 138  
     }
 139  
 
 140  
     public void addBodyScript(IComponent target, String script)
 141  
     {
 142  0
         if (_processor.isBodyScriptAllowed(target))
 143  0
             _processor.addBodyScript(target, script);
 144  0
     }
 145  
 
 146  
     public void addExternalScript(Resource resource)
 147  
     {
 148  0
         addExternalScript(_component, resource);
 149  0
     }
 150  
 
 151  
     public void addExternalScript(IComponent target, Resource resource)
 152  
     {
 153  0
         if (_processor.isExternalScriptAllowed(target))
 154  0
             _processor.addExternalScript(target, resource);
 155  0
     }
 156  
 
 157  
     public void addInitializationScript(String script)
 158  
     {
 159  0
         addInitializationScript(_component, script);
 160  0
     }
 161  
 
 162  
     public void addInitializationScript(IComponent target, String script)
 163  
     {
 164  0
         if (_processor.isInitializationScriptAllowed(target))
 165  0
             _processor.addInitializationScript(target, script);
 166  0
     }
 167  
 
 168  
     public void addScriptAfterInitialization(IComponent target, String script)
 169  
     {
 170  0
         if (_processor.isInitializationScriptAllowed(target))
 171  0
             _processor.addScriptAfterInitialization(target, script);
 172  0
     }
 173  
 
 174  
     public String getUniqueString(String baseValue)
 175  
     {
 176  0
         return _processor.getUniqueString(baseValue);
 177  
     }
 178  
 
 179  
     public String toString()
 180  
     {
 181  0
         StringBuffer buffer = new StringBuffer();
 182  
 
 183  0
         buffer.append("ScriptSession[");
 184  0
         buffer.append(_scriptTemplateResource);
 185  0
         buffer.append(']');
 186  
 
 187  0
         return buffer.toString();
 188  
     }
 189  
 }