Clover coverage report - Code Coverage for tapestry release 4.0.1
Coverage timestamp: Fri Mar 31 2006 09:12:14 EST
file stats: LOC: 84   Methods: 5
NCLOC: 51   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
ExpressionCacheImpl.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.HashMap;
 18    import java.util.Map;
 19   
 20    import ognl.Ognl;
 21   
 22    import org.apache.hivemind.ApplicationRuntimeException;
 23    import org.apache.tapestry.event.ReportStatusEvent;
 24    import org.apache.tapestry.event.ReportStatusListener;
 25    import org.apache.tapestry.event.ResetEventListener;
 26    import org.apache.tapestry.services.ExpressionCache;
 27   
 28    /**
 29    * @author Howard M. Lewis Ship
 30    * @since 4.0
 31    */
 32    public class ExpressionCacheImpl implements ExpressionCache, ResetEventListener,
 33    ReportStatusListener
 34    {
 35    private String _serviceId;
 36   
 37    private Map _cache = new HashMap();
 38   
 39  2 public synchronized void resetEventDidOccur()
 40    {
 41  2 _cache.clear();
 42    }
 43   
 44  34 public void reportStatus(ReportStatusEvent event)
 45    {
 46  34 event.title(_serviceId);
 47   
 48  34 event.property("cached expression count", _cache.size());
 49  34 event.collection("cached expressions", _cache.keySet());
 50    }
 51   
 52  3794 public synchronized Object getCompiledExpression(String expression)
 53    {
 54  3794 Object result = _cache.get(expression);
 55   
 56  3794 if (result == null)
 57    {
 58  1060 result = parse(expression);
 59  1058 _cache.put(expression, result);
 60    }
 61   
 62  3792 return result;
 63    }
 64   
 65  1060 private Object parse(String expression)
 66    {
 67  1060 try
 68    {
 69  1060 return Ognl.parseExpression(expression);
 70    }
 71    catch (Exception ex)
 72    {
 73  2 throw new ApplicationRuntimeException(ImplMessages.unableToParseExpression(
 74    expression,
 75    ex), ex);
 76    }
 77    }
 78   
 79  76 public void setServiceId(String serviceId)
 80    {
 81  76 _serviceId = serviceId;
 82    }
 83   
 84    }