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