Clover coverage report - Code Coverage for tapestry-annotations release 4.0-rc-2
Coverage timestamp: Sat Dec 17 2005 09:47:59 PST
file stats: LOC: 173   Methods: 10
NCLOC: 119   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    private SecondaryAnnotationWorker _secondaryAnnotationWorker;
 51   
 52  6 public void setClassWorkers(Map classWorkers)
 53    {
 54  6 _classWorkers = classWorkers;
 55    }
 56   
 57  14 public void performEnhancement(EnhancementOperation op, IComponentSpecification spec)
 58    {
 59  14 Class clazz = op.getBaseClass();
 60   
 61  14 Resource classResource = newClassResource(clazz);
 62   
 63  14 for (Annotation a : clazz.getAnnotations())
 64    {
 65  6 performClassEnhancement(op, spec, clazz, a, classResource);
 66    }
 67   
 68  14 for (Method m : clazz.getMethods())
 69    {
 70  1022 performMethodEnhancement(op, spec, m, classResource);
 71    }
 72    }
 73   
 74  14 private ClasspathResource newClassResource(Class clazz)
 75    {
 76  14 return new ClasspathResource(_classResolver, clazz.getName().replace('.', '/'));
 77    }
 78   
 79  6 void performClassEnhancement(EnhancementOperation op, IComponentSpecification spec,
 80    Class clazz, Annotation annotation, Resource classResource)
 81    {
 82  6 ClassAnnotationEnhancementWorker worker = (ClassAnnotationEnhancementWorker) _classWorkers
 83    .get(annotation.annotationType());
 84   
 85  6 if (worker == null)
 86  2 return;
 87   
 88  4 try
 89    {
 90  4 Location location = new DescribedLocation(classResource, AnnotationMessages
 91    .classAnnotation(annotation, clazz));
 92   
 93  4 worker.performEnhancement(op, spec, clazz, location);
 94    }
 95    catch (Exception ex)
 96    {
 97  2 _errorLog.error(AnnotationMessages.failureProcessingClassAnnotation(
 98    annotation,
 99    clazz,
 100    ex), null, ex);
 101    }
 102   
 103    }
 104   
 105  1026 void performMethodEnhancement(EnhancementOperation op, IComponentSpecification spec,
 106    Method method, Resource classResource)
 107    {
 108  1026 for (Annotation a : method.getAnnotations())
 109    {
 110  300 performMethodEnhancement(op, spec, method, a, classResource);
 111    }
 112   
 113  1026 try
 114    {
 115    // Remember; _secondaryWorker is a chain-of-command, so this returns true
 116    // if any command in the chain returns true.
 117   
 118  1026 if (_secondaryAnnotationWorker.canEnhance(method))
 119  2 _secondaryAnnotationWorker.peformEnhancement(op, spec, method, classResource);
 120    }
 121    catch (Exception ex)
 122    {
 123  2 _errorLog.error(AnnotationMessages.failureEnhancingMethod(method, ex), null, ex);
 124    }
 125    }
 126   
 127  300 void performMethodEnhancement(EnhancementOperation op, IComponentSpecification spec,
 128    Method method, Annotation annotation, Resource classResource)
 129    {
 130  300 MethodAnnotationEnhancementWorker worker = (MethodAnnotationEnhancementWorker) _methodWorkers
 131    .get(annotation.annotationType());
 132   
 133  300 if (worker == null)
 134  294 return;
 135   
 136  6 try
 137    {
 138  6 Location location = AnnotationUtils.buildLocationForAnnotation(
 139    method,
 140    annotation,
 141    classResource);
 142  6 worker.performEnhancement(op, spec, method, location);
 143    }
 144    catch (Exception ex)
 145    {
 146  2 _errorLog.error(
 147    AnnotationMessages.failureProcessingAnnotation(annotation, method, ex),
 148    null,
 149    ex);
 150    }
 151   
 152    }
 153   
 154  12 public void setMethodWorkers(Map methodWorkers)
 155    {
 156  12 _methodWorkers = methodWorkers;
 157    }
 158   
 159  6 public void setErrorLog(ErrorLog errorLog)
 160    {
 161  6 _errorLog = errorLog;
 162    }
 163   
 164  10 public void setClassResolver(ClassResolver classResolver)
 165    {
 166  10 _classResolver = classResolver;
 167    }
 168   
 169  18 public void setSecondaryAnnotationWorker(SecondaryAnnotationWorker secondaryWorker)
 170    {
 171  18 _secondaryAnnotationWorker = secondaryWorker;
 172    }
 173    }