Clover coverage report - Code Coverage for tapestry release 4.0-beta-2
Coverage timestamp: Sat Jul 9 2005 22:02:17 EDT
file stats: LOC: 149   Methods: 10
NCLOC: 100   Classes: 1
30 day Evaluation License registered to hlship@comcast.net Your 30 day evaluation period has expired. Please visit http://www.cenqua.com to obtain a licensed version of Clover
 
 Source file Conditionals Statements Methods TOTAL
ExpressionEvaluatorImpl.java 100% 100% 100% 100%
coverage
 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.services.impl;
 16   
 17    import java.util.Iterator;
 18    import java.util.List;
 19    import java.util.Map;
 20   
 21    import ognl.ClassResolver;
 22    import ognl.Ognl;
 23    import ognl.OgnlRuntime;
 24    import ognl.TypeConverter;
 25   
 26    import org.apache.hivemind.ApplicationRuntimeException;
 27    import org.apache.tapestry.Tapestry;
 28    import org.apache.tapestry.services.ExpressionCache;
 29    import org.apache.tapestry.services.ExpressionEvaluator;
 30    import org.apache.tapestry.spec.IApplicationSpecification;
 31   
 32    /**
 33    * @author Howard M. Lewis Ship
 34    * @since 4.0
 35    */
 36    public class ExpressionEvaluatorImpl implements ExpressionEvaluator
 37    {
 38    // Uses Thread's context class loader
 39   
 40    private ClassResolver _ognlResolver = new OgnlClassResolver();
 41   
 42    private ExpressionCache _expressionCache;
 43   
 44    private IApplicationSpecification _applicationSpecification;
 45   
 46    private TypeConverter _typeConverter;
 47   
 48    private List _contributions;
 49   
 50  41 public void setApplicationSpecification(IApplicationSpecification applicationSpecification)
 51    {
 52  41 _applicationSpecification = applicationSpecification;
 53    }
 54   
 55  41 public void initializeService()
 56    {
 57  41 if (_applicationSpecification.checkExtension(Tapestry.OGNL_TYPE_CONVERTER))
 58  1 _typeConverter = (TypeConverter) _applicationSpecification.getExtension(
 59    Tapestry.OGNL_TYPE_CONVERTER,
 60    TypeConverter.class);
 61   
 62  41 Iterator i = _contributions.iterator();
 63   
 64  41 while (i.hasNext())
 65    {
 66  80 PropertyAccessorContribution c = (PropertyAccessorContribution) i.next();
 67   
 68  80 OgnlRuntime.setPropertyAccessor(c.getSubjectClass(), c.getAccessor());
 69    }
 70   
 71    }
 72   
 73  12 public Object read(Object target, String expression)
 74    {
 75  12 return readCompiled(target, _expressionCache.getCompiledExpression(expression));
 76    }
 77   
 78  2236 public Object readCompiled(Object target, Object expression)
 79    {
 80  2236 try
 81    {
 82  2236 Map context = createContext(target);
 83   
 84  2236 return Ognl.getValue(expression, context, target);
 85    }
 86    catch (Exception ex)
 87    {
 88  2 throw new ApplicationRuntimeException(ImplMessages.unableToReadExpression(ImplMessages
 89    .parsedExpression(), target, ex), target, null, ex);
 90    }
 91    }
 92   
 93  3589 private Map createContext(Object target)
 94    {
 95  3589 Map result = Ognl.createDefaultContext(target, _ognlResolver);
 96   
 97  3589 if (_typeConverter != null)
 98  1 Ognl.setTypeConverter(result, _typeConverter);
 99   
 100  3589 return result;
 101    }
 102   
 103  3 public void write(Object target, String expression, Object value)
 104    {
 105  3 writeCompiled(target, _expressionCache.getCompiledExpression(expression), value);
 106    }
 107   
 108  1353 public void writeCompiled(Object target, Object expression, Object value)
 109    {
 110  1353 try
 111    {
 112  1353 Map context = createContext(target);
 113   
 114  1353 Ognl.setValue(expression, context, target, value);
 115    }
 116    catch (Exception ex)
 117    {
 118  1 throw new ApplicationRuntimeException(ImplMessages.unableToWriteExpression(ImplMessages
 119    .parsedExpression(), target, value, ex), target, null, ex);
 120    }
 121   
 122    }
 123   
 124  897 public boolean isConstant(String expression)
 125    {
 126  897 Object compiled = _expressionCache.getCompiledExpression(expression);
 127   
 128  897 try
 129    {
 130  897 return Ognl.isConstant(compiled);
 131    }
 132    catch (Exception ex)
 133    {
 134  1 throw new ApplicationRuntimeException(ImplMessages.isConstantExpressionError(
 135    expression,
 136    ex), ex);
 137    }
 138    }
 139   
 140  64 public void setExpressionCache(ExpressionCache expressionCache)
 141    {
 142  64 _expressionCache = expressionCache;
 143    }
 144   
 145  41 public void setContributions(List contributions)
 146    {
 147  41 _contributions = contributions;
 148    }
 149    }