Clover coverage report - Code Coverage for tapestry release 4.0.2
Coverage timestamp: Thu Apr 13 2006 10:52:06 EDT
file stats: LOC: 129   Methods: 8
NCLOC: 77   Classes: 3
 
 Source file Conditionals Statements Methods TOTAL
EngineFactoryImpl.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.Locale;
 18   
 19    import org.apache.hivemind.ApplicationRuntimeException;
 20    import org.apache.hivemind.ClassResolver;
 21    import org.apache.hivemind.ErrorLog;
 22    import org.apache.tapestry.IEngine;
 23    import org.apache.tapestry.engine.BaseEngine;
 24    import org.apache.tapestry.services.EngineFactory;
 25    import org.apache.tapestry.spec.IApplicationSpecification;
 26   
 27    /**
 28    * Standard implementation of {@link org.apache.tapestry.services.EngineFactory} service. This
 29    * should do for most purposes, since a major focus of Tapestry 4.0 is to no longer require
 30    * subclassing of {@link org.apache.tapestry.engine.BaseEngine}.
 31    *
 32    * @author Howard Lewis Ship
 33    * @since 4.0
 34    */
 35    public class EngineFactoryImpl implements EngineFactory
 36    {
 37    private IApplicationSpecification _applicationSpecification;
 38   
 39    private String _defaultEngineClassName;
 40   
 41    private EngineConstructor _constructor;
 42   
 43    private ClassResolver _classResolver;
 44   
 45    private ErrorLog _errorLog;
 46   
 47    interface EngineConstructor
 48    {
 49    IEngine construct();
 50    }
 51   
 52    // TODO: Create a BaseEngineConstructor that is hardcoded to
 53    // instantiate a BaseEngine instance, without using reflection
 54    // (for efficiency).
 55   
 56    static class ReflectiveEngineConstructor implements EngineConstructor
 57    {
 58    private Class _engineClass;
 59   
 60  43 ReflectiveEngineConstructor(Class engineClass)
 61    {
 62  43 _engineClass = engineClass;
 63    }
 64   
 65  51 public IEngine construct()
 66    {
 67  51 try
 68    {
 69  51 return (IEngine) _engineClass.newInstance();
 70    }
 71    catch (Exception ex)
 72    {
 73  1 throw new ApplicationRuntimeException(ImplMessages.errorInstantiatingEngine(
 74    _engineClass,
 75    ex), ex);
 76    }
 77    }
 78    }
 79   
 80  43 public void initializeService()
 81    {
 82  43 String engineClassName = _applicationSpecification.getEngineClassName();
 83   
 84    // TODO: Check in web.xml first.
 85   
 86  43 if (engineClassName == null)
 87  35 engineClassName = _defaultEngineClassName;
 88   
 89  43 Class engineClass = _classResolver.checkForClass(engineClassName);
 90   
 91  43 if (engineClass == null)
 92    {
 93  1 _errorLog.error(ImplMessages.engineClassNotFound(engineClassName), null, null);
 94  1 engineClass = BaseEngine.class;
 95    }
 96   
 97  43 _constructor = new ReflectiveEngineConstructor(engineClass);
 98    }
 99   
 100  51 public IEngine constructNewEngineInstance(Locale locale)
 101    {
 102  51 IEngine result = _constructor.construct();
 103   
 104  50 result.setLocale(locale);
 105   
 106  50 return result;
 107    }
 108   
 109  43 public void setApplicationSpecification(IApplicationSpecification specification)
 110    {
 111  43 _applicationSpecification = specification;
 112    }
 113   
 114  43 public void setClassResolver(ClassResolver resolver)
 115    {
 116  43 _classResolver = resolver;
 117    }
 118   
 119  41 public void setDefaultEngineClassName(String string)
 120    {
 121  41 _defaultEngineClassName = string;
 122    }
 123   
 124  40 public void setErrorLog(ErrorLog errorLog)
 125    {
 126  40 _errorLog = errorLog;
 127    }
 128   
 129    }