Clover coverage report - Code Coverage for tapestry-annotations release 4.0-beta-10
Coverage timestamp: Sat Oct 8 2005 19:14:20 EDT
file stats: LOC: 151   Methods: 9
NCLOC: 103   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
AnnotationEnhancementWorker.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.annotations;
 16   
 17    import java.lang.annotation.Annotation;
 18    import java.lang.reflect.Method;
 19    import java.util.Map;
 20   
 21    import org.apache.hivemind.ClassResolver;
 22    import org.apache.hivemind.ErrorLog;
 23    import org.apache.hivemind.Location;
 24    import org.apache.hivemind.Resource;
 25    import org.apache.hivemind.util.ClasspathResource;
 26    import org.apache.tapestry.enhance.EnhancementOperation;
 27    import org.apache.tapestry.enhance.EnhancementWorker;
 28    import org.apache.tapestry.spec.IComponentSpecification;
 29    import org.apache.tapestry.util.DescribedLocation;
 30   
 31    /**
 32    * Implementation of {@link org.apache.tapestry.enhance.EnhancementWorker} that finds class and
 33    * method annotations and delegates out to specific
 34    * {@link org.apache.tapestry.annotations.ClassAnnotationEnhancementWorker} and
 35    * {@link org.apache.tapestry.annotations.MethodAnnotationEnhancementWorker} instances.
 36    *
 37    * @author Howard M. Lewis Ship
 38    * @since 4.0
 39    */
 40    public class AnnotationEnhancementWorker implements EnhancementWorker
 41    {
 42    private ClassResolver _classResolver;
 43   
 44    private ErrorLog _errorLog;
 45   
 46    private Map _methodWorkers;
 47   
 48    private Map _classWorkers;
 49   
 50  6 public void setClassWorkers(Map classWorkers)
 51    {
 52  6 _classWorkers = classWorkers;
 53    }
 54   
 55  14 public void performEnhancement(EnhancementOperation op, IComponentSpecification spec)
 56    {
 57  14 Class clazz = op.getBaseClass();
 58   
 59  14 Resource classResource = newClassResource(clazz);
 60   
 61  14 for (Annotation a : clazz.getAnnotations())
 62    {
 63  6 performClassEnhancement(op, spec, clazz, a, classResource);
 64    }
 65   
 66  14 for (Method m : clazz.getMethods())
 67    {
 68  1006 performMethodEnhancement(op, spec, m, classResource);
 69    }
 70    }
 71   
 72  14 private ClasspathResource newClassResource(Class clazz)
 73    {
 74  14 return new ClasspathResource(_classResolver, clazz.getName().replace('.', '/'));
 75    }
 76   
 77  6 void performClassEnhancement(EnhancementOperation op, IComponentSpecification spec,
 78    Class clazz, Annotation annotation, Resource classResource)
 79    {
 80  6 ClassAnnotationEnhancementWorker worker = (ClassAnnotationEnhancementWorker) _classWorkers
 81    .get(annotation.annotationType());
 82   
 83  6 if (worker == null)
 84  2 return;
 85   
 86  4 try
 87    {
 88  4 Location location = new DescribedLocation(classResource, AnnotationMessages
 89    .classAnnotation(annotation, clazz));
 90   
 91  4 worker.performEnhancement(op, spec, clazz, location);
 92    }
 93    catch (Exception ex)
 94    {
 95  2 _errorLog.error(AnnotationMessages.failureProcessingClassAnnotation(
 96    annotation,
 97    clazz,
 98    ex), null, ex);
 99    }
 100   
 101    }
 102   
 103  1006 void performMethodEnhancement(EnhancementOperation op, IComponentSpecification spec,
 104    Method method, Resource classResource)
 105    {
 106  1006 for (Annotation a : method.getAnnotations())
 107    {
 108  272 performMethodEnhancement(op, spec, method, a, classResource);
 109    }
 110    }
 111   
 112  272 void performMethodEnhancement(EnhancementOperation op, IComponentSpecification spec,
 113    Method method, Annotation annotation, Resource classResource)
 114    {
 115  272 MethodAnnotationEnhancementWorker worker = (MethodAnnotationEnhancementWorker) _methodWorkers
 116    .get(annotation.annotationType());
 117   
 118  272 if (worker == null)
 119  266 return;
 120   
 121  6 try
 122    {
 123  6 Location location = new DescribedLocation(classResource, AnnotationMessages
 124    .methodAnnotation(annotation, method));
 125  6 worker.performEnhancement(op, spec, method, location);
 126    }
 127    catch (Exception ex)
 128    {
 129  2 _errorLog.error(
 130    AnnotationMessages.failureProcessingAnnotation(annotation, method, ex),
 131    null,
 132    ex);
 133    }
 134   
 135    }
 136   
 137  8 public void setMethodWorkers(Map methodWorkers)
 138    {
 139  8 _methodWorkers = methodWorkers;
 140    }
 141   
 142  4 public void setErrorLog(ErrorLog errorLog)
 143    {
 144  4 _errorLog = errorLog;
 145    }
 146   
 147  10 public void setClassResolver(ClassResolver classResolver)
 148    {
 149  10 _classResolver = classResolver;
 150    }
 151    }