Clover coverage report - Code Coverage for tapestry release 4.0-rc-2
Coverage timestamp: Sat Dec 17 2005 09:39:46 PST
file stats: LOC: 119   Methods: 8
NCLOC: 72   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
DefaultScriptSource.java 0% 0% 0% 0%
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.engine;
 16   
 17    import java.util.HashMap;
 18    import java.util.Map;
 19   
 20    import org.apache.hivemind.ApplicationRuntimeException;
 21    import org.apache.hivemind.ClassResolver;
 22    import org.apache.hivemind.Resource;
 23    import org.apache.tapestry.IScript;
 24    import org.apache.tapestry.Tapestry;
 25    import org.apache.tapestry.coerce.ValueConverter;
 26    import org.apache.tapestry.event.ReportStatusEvent;
 27    import org.apache.tapestry.event.ReportStatusListener;
 28    import org.apache.tapestry.event.ResetEventListener;
 29    import org.apache.tapestry.script.ScriptParser;
 30    import org.apache.tapestry.services.ExpressionEvaluator;
 31    import org.apache.tapestry.util.xml.DocumentParseException;
 32   
 33    /**
 34    * Provides basic access to scripts available on the classpath. Scripts are cached in memory once
 35    * parsed.
 36    *
 37    * @author Howard Lewis Ship
 38    * @since 1.0.2
 39    */
 40   
 41    public class DefaultScriptSource implements IScriptSource, ResetEventListener, ReportStatusListener
 42    {
 43    private String _serviceId;
 44   
 45    private ClassResolver _classResolver;
 46   
 47    /** @since 4.0 */
 48    private ExpressionEvaluator _expressionEvaluator;
 49   
 50    /** @since 4.0 */
 51    private ValueConverter _valueConverter;
 52   
 53    private Map _cache = new HashMap();
 54   
 55  0 public synchronized void resetEventDidOccur()
 56    {
 57  0 _cache.clear();
 58    }
 59   
 60  0 public synchronized void reportStatus(ReportStatusEvent event)
 61    {
 62  0 event.title(_serviceId);
 63  0 event.property("parsed script count", _cache.size());
 64  0 event.collection("parsed scripts", _cache.keySet());
 65    }
 66   
 67  0 public synchronized IScript getScript(Resource resource)
 68    {
 69  0 IScript result = (IScript) _cache.get(resource);
 70   
 71  0 if (result != null)
 72  0 return result;
 73   
 74  0 result = parse(resource);
 75   
 76  0 _cache.put(resource, result);
 77   
 78  0 return result;
 79    }
 80   
 81  0 private IScript parse(Resource resource)
 82    {
 83  0 ScriptParser parser = new ScriptParser(_classResolver, _expressionEvaluator,
 84    _valueConverter);
 85   
 86  0 try
 87    {
 88  0 return parser.parse(resource);
 89    }
 90    catch (DocumentParseException ex)
 91    {
 92  0 throw new ApplicationRuntimeException(Tapestry.format(
 93    "DefaultScriptSource.unable-to-parse-script",
 94    resource), ex);
 95    }
 96    }
 97   
 98  0 public void setClassResolver(ClassResolver classResolver)
 99    {
 100  0 _classResolver = classResolver;
 101    }
 102   
 103    /** @since 4.0 */
 104  0 public void setExpressionEvaluator(ExpressionEvaluator expressionEvaluator)
 105    {
 106  0 _expressionEvaluator = expressionEvaluator;
 107    }
 108   
 109    /** @since 4.0 */
 110  0 public void setValueConverter(ValueConverter valueConverter)
 111    {
 112  0 _valueConverter = valueConverter;
 113    }
 114   
 115  0 public void setServiceId(String serviceId)
 116    {
 117  0 _serviceId = serviceId;
 118    }
 119    }