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