Clover coverage report - Code Coverage for tapestry release 4.0.1
Coverage timestamp: Fri Mar 31 2006 09:12:14 EST
file stats: LOC: 156   Methods: 10
NCLOC: 102   Classes: 1
 
 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 final 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    // Context, with a root of null, used when evaluating an expression
 51    // to see if it is a constant.
 52   
 53    private Map _defaultContext;
 54   
 55  80 public void setApplicationSpecification(IApplicationSpecification applicationSpecification)
 56    {
 57  80 _applicationSpecification = applicationSpecification;
 58    }
 59   
 60  80 public void initializeService()
 61    {
 62  80 if (_applicationSpecification.checkExtension(Tapestry.OGNL_TYPE_CONVERTER))
 63  2 _typeConverter = (TypeConverter) _applicationSpecification.getExtension(
 64    Tapestry.OGNL_TYPE_CONVERTER,
 65    TypeConverter.class);
 66   
 67  80 Iterator i = _contributions.iterator();
 68   
 69  80 while (i.hasNext())
 70    {
 71  152 PropertyAccessorContribution c = (PropertyAccessorContribution) i.next();
 72   
 73  152 OgnlRuntime.setPropertyAccessor(c.getSubjectClass(), c.getAccessor());
 74    }
 75   
 76  80 _defaultContext = Ognl.createDefaultContext(null, _ognlResolver, _typeConverter);
 77   
 78    }
 79   
 80  86 public Object read(Object target, String expression)
 81    {
 82  86 return readCompiled(target, _expressionCache.getCompiledExpression(expression));
 83    }
 84   
 85  4290 public Object readCompiled(Object target, Object expression)
 86    {
 87  4290 try
 88    {
 89  4290 Map context = createContext(target);
 90   
 91  4290 return Ognl.getValue(expression, context, target);
 92    }
 93    catch (Exception ex)
 94    {
 95  4 throw new ApplicationRuntimeException(ImplMessages.unableToReadExpression(ImplMessages
 96    .parsedExpression(), target, ex), target, null, ex);
 97    }
 98    }
 99   
 100  6642 private Map createContext(Object target)
 101    {
 102  6642 Map result = Ognl.createDefaultContext(target, _ognlResolver);
 103   
 104  6642 if (_typeConverter != null)
 105  2 Ognl.setTypeConverter(result, _typeConverter);
 106   
 107  6642 return result;
 108    }
 109   
 110  6 public void write(Object target, String expression, Object value)
 111    {
 112  6 writeCompiled(target, _expressionCache.getCompiledExpression(expression), value);
 113    }
 114   
 115  2352 public void writeCompiled(Object target, Object expression, Object value)
 116    {
 117  2352 try
 118    {
 119  2352 Map context = createContext(target);
 120   
 121  2352 Ognl.setValue(expression, context, target, value);
 122    }
 123    catch (Exception ex)
 124    {
 125  2 throw new ApplicationRuntimeException(ImplMessages.unableToWriteExpression(ImplMessages
 126    .parsedExpression(), target, value, ex), target, null, ex);
 127    }
 128   
 129    }
 130   
 131  1850 public boolean isConstant(String expression)
 132    {
 133  1850 Object compiled = _expressionCache.getCompiledExpression(expression);
 134   
 135  1850 try
 136    {
 137  1850 return Ognl.isConstant(compiled, _defaultContext);
 138    }
 139    catch (Exception ex)
 140    {
 141  2 throw new ApplicationRuntimeException(ImplMessages.isConstantExpressionError(
 142    expression,
 143    ex), ex);
 144    }
 145    }
 146   
 147  124 public void setExpressionCache(ExpressionCache expressionCache)
 148    {
 149  124 _expressionCache = expressionCache;
 150    }
 151   
 152  80 public void setContributions(List contributions)
 153    {
 154  80 _contributions = contributions;
 155    }
 156    }