Clover coverage report - Code Coverage for tapestry-annotations release 4.0-beta-1
Coverage timestamp: Fri Jun 24 2005 14:37:32 EDT
file stats: LOC: 127   Methods: 7
NCLOC: 84   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.ErrorLog;
 22    import org.apache.tapestry.enhance.EnhancementOperation;
 23    import org.apache.tapestry.enhance.EnhancementWorker;
 24    import org.apache.tapestry.spec.IComponentSpecification;
 25   
 26    /**
 27    * Implementation of {@link org.apache.tapestry.enhance.EnhancementWorker} that finds class and
 28    * method annotations and delegates out to specific
 29    * {@link org.apache.tapestry.annotations.ClassAnnotationEnhancementWorker} and
 30    * {@link org.apache.tapestry.annotations.MethodAnnotationEnhancementWorker} instances.
 31    *
 32    * @author Howard M. Lewis Ship
 33    * @since 4.0
 34    */
 35    public class AnnotationEnhancementWorker implements EnhancementWorker
 36    {
 37    private ErrorLog _errorLog;
 38   
 39    private Map _methodWorkers;
 40   
 41    private Map _classWorkers;
 42   
 43  6 public void setClassWorkers(Map classWorkers)
 44    {
 45  6 _classWorkers = classWorkers;
 46    }
 47   
 48  14 public void performEnhancement(EnhancementOperation op, IComponentSpecification spec)
 49    {
 50  14 Class clazz = op.getBaseClass();
 51   
 52  14 for (Annotation a : clazz.getAnnotations())
 53    {
 54  6 performClassEnhancement(op, spec, clazz, a);
 55    }
 56   
 57  14 for (Method m : clazz.getMethods())
 58    {
 59  942 performMethodEnhancement(op, spec, m);
 60    }
 61    }
 62   
 63  6 void performClassEnhancement(EnhancementOperation op, IComponentSpecification spec,
 64    Class clazz, Annotation annotation)
 65    {
 66  6 ClassAnnotationEnhancementWorker worker = (ClassAnnotationEnhancementWorker) _classWorkers
 67    .get(annotation.annotationType());
 68   
 69  6 if (worker == null)
 70  2 return;
 71   
 72  4 try
 73    {
 74  4 worker.performEnhancement(op, spec, clazz);
 75    }
 76    catch (Exception ex)
 77    {
 78  2 _errorLog.error(AnnotationMessages.failureProcessingClassAnnotation(
 79    annotation,
 80    clazz,
 81    ex), null, ex);
 82    }
 83   
 84    }
 85   
 86  942 void performMethodEnhancement(EnhancementOperation op, IComponentSpecification spec,
 87    Method method)
 88    {
 89  942 for (Annotation a : method.getAnnotations())
 90    {
 91  264 performMethodEnhancement(op, spec, method, a);
 92    }
 93    }
 94   
 95  264 void performMethodEnhancement(EnhancementOperation op, IComponentSpecification spec,
 96    Method method, Annotation annotation)
 97    {
 98  264 MethodAnnotationEnhancementWorker worker = (MethodAnnotationEnhancementWorker) _methodWorkers
 99    .get(annotation.annotationType());
 100   
 101  264 if (worker == null)
 102  258 return;
 103   
 104  6 try
 105    {
 106  6 worker.performEnhancement(op, spec, method);
 107    }
 108    catch (Exception ex)
 109    {
 110  2 _errorLog.error(
 111    AnnotationMessages.failureProcessingAnnotation(annotation, method, ex),
 112    null,
 113    ex);
 114    }
 115   
 116    }
 117   
 118  8 public void setMethodWorkers(Map methodWorkers)
 119    {
 120  8 _methodWorkers = methodWorkers;
 121    }
 122   
 123  4 public void setErrorLog(ErrorLog errorLog)
 124    {
 125  4 _errorLog = errorLog;
 126    }
 127    }