Coverage Report - org.apache.tapestry5.internal.transform.InjectWorker
 
Classes in this File Line Coverage Branch Coverage Complexity
InjectWorker
100%
15/15
100%
4/4
0
 
 1  
 // Copyright 2006, 2007 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.tapestry5.internal.transform;
 16  
 
 17  
 import org.apache.tapestry5.ioc.ObjectLocator;
 18  
 import org.apache.tapestry5.ioc.annotations.Inject;
 19  
 import org.apache.tapestry5.model.MutableComponentModel;
 20  
 import org.apache.tapestry5.services.ClassTransformation;
 21  
 import org.apache.tapestry5.services.ComponentClassTransformWorker;
 22  
 import org.apache.tapestry5.services.InjectionProvider;
 23  
 
 24  
 /**
 25  
  * Performs injection triggered by any field annotated with the {@link org.apache.tapestry5.ioc.annotations.Inject}
 26  
  * annotation.
 27  
  * <p/>
 28  
  * The implementation of this worker mostly delegates to a chain of command of {@link
 29  
  * org.apache.tapestry5.services.InjectionProvider}s.
 30  
  */
 31  
 public class InjectWorker implements ComponentClassTransformWorker
 32  
 {
 33  
     private final ObjectLocator locator;
 34  
 
 35  
     // Really, a chain of command
 36  
 
 37  
     private final InjectionProvider injectionProvider;
 38  
 
 39  
     public InjectWorker(ObjectLocator locator, InjectionProvider injectionProvider)
 40  64
     {
 41  64
         this.locator = locator;
 42  64
         this.injectionProvider = injectionProvider;
 43  64
     }
 44  
 
 45  
     public final void transform(ClassTransformation transformation, MutableComponentModel model)
 46  
     {
 47  822
         for (String fieldName : transformation.findFieldsWithAnnotation(Inject.class))
 48  
         {
 49  838
             Inject annotation = transformation.getFieldAnnotation(fieldName, Inject.class);
 50  
 
 51  
             try
 52  
             {
 53  838
                 String fieldType = transformation.getFieldType(fieldName);
 54  
 
 55  838
                 Class type = transformation.toClass(fieldType);
 56  
 
 57  838
                 boolean success = injectionProvider.provideInjection(
 58  
                         fieldName,
 59  
                         type,
 60  
                         locator,
 61  
                         transformation,
 62  
                         model);
 63  
 
 64  834
                 if (success) transformation.claimField(fieldName, annotation);
 65  
             }
 66  4
             catch (RuntimeException ex)
 67  
             {
 68  4
                 throw new RuntimeException(TransformMessages.fieldInjectionError(transformation
 69  
                         .getClassName(), fieldName, ex), ex);
 70  834
             }
 71  
 
 72  834
         }
 73  818
     }
 74  
 }