Clover coverage report - Code Coverage for tapestry release 3.1-alpha-1
Coverage timestamp: Mon Feb 21 2005 09:16:14 EST
file stats: LOC: 105   Methods: 4
NCLOC: 65   Classes: 1
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover
 
 Source file Conditionals Statements Methods TOTAL
InjectWorker.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.enhance;
 16   
 
 17   
 import java.lang.reflect.Modifier;
 18   
 import java.util.Iterator;
 19   
 
 20   
 import org.apache.hivemind.ApplicationRuntimeException;
 21   
 import org.apache.hivemind.ErrorLog;
 22   
 import org.apache.hivemind.service.MethodSignature;
 23   
 import org.apache.tapestry.services.InjectedValueProvider;
 24   
 import org.apache.tapestry.spec.IComponentSpecification;
 25   
 import org.apache.tapestry.spec.InjectSpecification;
 26   
 
 27   
 /**
 28   
  * Adds read-only properties to the enhanced class that contain data injected from HiveMind.
 29   
  * 
 30   
  * @author Howard M. Lewis Ship
 31   
  * @since 3.1
 32   
  */
 33   
 public class InjectWorker implements EnhancementWorker
 34   
 {
 35   
     private ErrorLog _errorLog;
 36   
 
 37   
     private InjectedValueProvider _provider;
 38   
 
 39  535
     public void performEnhancement(EnhancementOperation op, IComponentSpecification spec)
 40   
     {
 41  535
         Iterator i = spec.getInjectSpecifications().iterator();
 42   
 
 43  535
         while (i.hasNext())
 44   
         {
 45  247
             InjectSpecification is = (InjectSpecification) i.next();
 46   
 
 47  247
             try
 48   
             {
 49  247
                 performEnhancement(op, is);
 50   
             }
 51   
             catch (Exception ex)
 52   
             {
 53  2
                 _errorLog.error(EnhanceMessages.errorAddingProperty(
 54   
                         is.getProperty(),
 55   
                         op.getBaseClass(),
 56   
                         ex), is.getLocation(), ex);
 57   
             }
 58   
         }
 59   
     }
 60   
 
 61  247
     private void performEnhancement(EnhancementOperation op, InjectSpecification is)
 62   
     {
 63  247
         String name = is.getProperty();
 64  247
         String objectReference = is.getObjectReference();
 65   
 
 66  247
         Class propertyType = op.getPropertyType(name);
 67  247
         if (propertyType == null)
 68  2
             propertyType = Object.class;
 69   
 
 70  247
         String fieldName = "_$" + name;
 71   
 
 72  247
         op.claimProperty(name);
 73   
 
 74  247
         Object injectedValue = _provider.obtainValue(objectReference, is.getLocation());
 75   
 
 76  247
         if (injectedValue == null)
 77  1
             throw new ApplicationRuntimeException(EnhanceMessages
 78   
                     .locatedValueIsNull(objectReference));
 79   
 
 80  246
         if (!propertyType.isAssignableFrom(injectedValue.getClass()))
 81  1
             throw new ApplicationRuntimeException(EnhanceMessages.incompatibleInjectType(
 82   
                     objectReference,
 83   
                     injectedValue,
 84   
                     propertyType));
 85   
 
 86  245
         op.addField(fieldName, propertyType, injectedValue);
 87   
 
 88  245
         String methodName = EnhanceUtils.createAccessorMethodName(name);
 89   
 
 90  245
         op.addMethod(
 91   
                 Modifier.PUBLIC,
 92   
                 new MethodSignature(propertyType, methodName, null, null),
 93   
                 "return " + fieldName + ";");
 94   
     }
 95   
 
 96  54
     public void setErrorLog(ErrorLog errorLog)
 97   
     {
 98  54
         _errorLog = errorLog;
 99   
     }
 100   
 
 101  56
     public void setProvider(InjectedValueProvider provider)
 102   
     {
 103  56
         _provider = provider;
 104   
     }
 105   
 }