Coverage Report - org.apache.tapestry.engine.DefaultScriptSource
 
Classes in this File Line Coverage Branch Coverage Complexity
DefaultScriptSource
0%
0/26
0%
0/2
1.625
 
 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 edu.emory.mathcs.backport.java.util.concurrent.ConcurrentHashMap;
 18  
 import org.apache.hivemind.ApplicationRuntimeException;
 19  
 import org.apache.hivemind.ClassResolver;
 20  
 import org.apache.hivemind.Resource;
 21  
 import org.apache.tapestry.IScript;
 22  
 import org.apache.tapestry.Tapestry;
 23  
 import org.apache.tapestry.coerce.ValueConverter;
 24  
 import org.apache.tapestry.event.ReportStatusEvent;
 25  
 import org.apache.tapestry.event.ReportStatusListener;
 26  
 import org.apache.tapestry.event.ResetEventListener;
 27  
 import org.apache.tapestry.script.ScriptParser;
 28  
 import org.apache.tapestry.services.ExpressionEvaluator;
 29  
 import org.apache.tapestry.util.xml.DocumentParseException;
 30  
 
 31  
 import java.util.Map;
 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  0
 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  0
     private Map _cache = new ConcurrentHashMap();
 54  
 
 55  
     public void resetEventDidOccur()
 56  
     {
 57  0
         _cache.clear();
 58  0
     }
 59  
 
 60  
     public 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  0
     }
 66  
 
 67  
     public 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  
     private IScript parse(Resource resource)
 82  
     {
 83  0
         ScriptParser parser = new ScriptParser(_classResolver, _expressionEvaluator, _valueConverter);
 84  
         try
 85  
         {
 86  0
             return parser.parse(resource);
 87  
         }
 88  0
         catch (DocumentParseException ex)
 89  
         {
 90  0
             throw new ApplicationRuntimeException(Tapestry.format("DefaultScriptSource.unable-to-parse-script",
 91  
                                                                   resource), ex);
 92  
         }
 93  
     }
 94  
 
 95  
     public void setClassResolver(ClassResolver classResolver)
 96  
     {
 97  0
         _classResolver = classResolver;
 98  0
     }
 99  
 
 100  
     /** @since 4.0 */
 101  
     public void setExpressionEvaluator(ExpressionEvaluator expressionEvaluator)
 102  
     {
 103  0
         _expressionEvaluator = expressionEvaluator;
 104  0
     }
 105  
 
 106  
     /** @since 4.0 */
 107  
     public void setValueConverter(ValueConverter valueConverter)
 108  
     {
 109  0
         _valueConverter = valueConverter;
 110  0
     }
 111  
 
 112  
     public void setServiceId(String serviceId)
 113  
     {
 114  0
         _serviceId = serviceId;
 115  0
     }
 116  
 }