Clover coverage report - Code Coverage for tapestry release 4.0.1
Coverage timestamp: Fri Mar 31 2006 09:12:14 EST
file stats: LOC: 91   Methods: 3
NCLOC: 53   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
InjectBeanWorker.java 100% 100% 100% 100%
coverage
 1    // Copyright 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.enhance;
 16   
 17    import java.lang.reflect.Modifier;
 18    import java.util.Iterator;
 19   
 20    import org.apache.hivemind.ErrorLog;
 21    import org.apache.hivemind.Location;
 22    import org.apache.hivemind.service.ClassFabUtils;
 23    import org.apache.hivemind.service.MethodSignature;
 24    import org.apache.hivemind.util.Defense;
 25    import org.apache.tapestry.spec.IBeanSpecification;
 26    import org.apache.tapestry.spec.IComponentSpecification;
 27   
 28    /**
 29    * Injects a property that will dynamically access a managed bean.
 30    *
 31    * @author Howard M. Lewis Ship
 32    * @since 4.0
 33    */
 34    public class InjectBeanWorker implements EnhancementWorker
 35    {
 36    private ErrorLog _errorLog;
 37   
 38  784 public void performEnhancement(EnhancementOperation op, IComponentSpecification spec)
 39    {
 40  784 Iterator i = spec.getBeanNames().iterator();
 41   
 42  784 while (i.hasNext())
 43    {
 44  50 String name = (String) i.next();
 45   
 46  50 IBeanSpecification bs = spec.getBeanSpecification(name);
 47   
 48  50 String propertyName = bs.getPropertyName();
 49  50 if (propertyName != null)
 50    {
 51  12 try
 52    {
 53  12 injectBean(op, name, propertyName, bs.getLocation());
 54    }
 55    catch (Exception ex)
 56    {
 57  2 _errorLog.error(EnhanceMessages.errorAddingProperty(propertyName, op
 58    .getBaseClass(), ex), bs.getLocation(), ex);
 59    }
 60    }
 61    }
 62    }
 63   
 64  12 public void injectBean(EnhancementOperation op, String beanName, String propertyName,
 65    Location location)
 66    {
 67  12 Defense.notNull(op, "op");
 68  12 Defense.notNull(beanName, "beanName");
 69  12 Defense.notNull(propertyName, "propertyName");
 70   
 71  12 op.claimReadonlyProperty(propertyName);
 72   
 73  10 Class propertyType = EnhanceUtils.extractPropertyType(op, propertyName, null);
 74   
 75  10 String methodName = op.getAccessorMethodName(propertyName);
 76   
 77  10 MethodSignature sig = new MethodSignature(propertyType, methodName, null, null);
 78   
 79    // i.e.
 80    // return (foo.bar.Baz) getBeans().getBean("baz");
 81   
 82  10 op.addMethod(Modifier.PUBLIC, sig, "return ("
 83    + ClassFabUtils.getJavaClassName(propertyType) + ") getBeans().getBean(\""
 84    + beanName + "\");", location);
 85    }
 86   
 87  80 public void setErrorLog(ErrorLog errorLog)
 88    {
 89  80 _errorLog = errorLog;
 90    }
 91    }