Clover coverage report - Code Coverage for tapestry-annotations release 4.0.1
Coverage timestamp: Fri Mar 31 2006 09:15:58 EST
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  12 public void setClassWorkers(Map classWorkers)
 53    {
 54  12 _classWorkers = classWorkers;
 55    }
 56   
 57  28 public void performEnhancement(EnhancementOperation op, IComponentSpecification spec)
 58    {
 59  28 Class clazz = op.getBaseClass();
 60   
 61  28 Resource classResource = newClassResource(clazz);
 62   
 63  28 for (Annotation a : clazz.getAnnotations())
 64    {
 65  12 performClassEnhancement(op, spec, clazz, a, classResource);
 66    }
 67   
 68  28 for (Method m : clazz.getMethods())
 69    {
 70  2060 performMethodEnhancement(op, spec, m, classResource);
 71    }
 72    }
 73   
 74  28 private ClasspathResource newClassResource(Class clazz)
 75    {
 76  28 return new ClasspathResource(_classResolver, clazz.getName().replace('.', '/'));
 77    }
 78   
 79  12 void performClassEnhancement(EnhancementOperation op, IComponentSpecification spec,
 80    Class clazz, Annotation annotation, Resource classResource)
 81    {
 82  12 ClassAnnotationEnhancementWorker worker = (ClassAnnotationEnhancementWorker) _classWorkers
 83    .get(annotation.annotationType());
 84   
 85  12 if (worker == null)
 86  4 return;
 87   
 88  8 try
 89    {
 90  8 Location location = new DescribedLocation(classResource, AnnotationMessages
 91    .classAnnotation(annotation, clazz));
 92   
 93  8 worker.performEnhancement(op, spec, clazz, location);
 94    }
 95    catch (Exception ex)
 96    {
 97  4 _errorLog.error(AnnotationMessages.failureProcessingClassAnnotation(
 98    annotation,
 99    clazz,
 100    ex), null, ex);
 101    }
 102   
 103    }
 104   
 105  2068 void performMethodEnhancement(EnhancementOperation op, IComponentSpecification spec,
 106    Method method, Resource classResource)
 107    {
 108  2068 for (Annotation a : method.getAnnotations())
 109    {
 110  600 performMethodEnhancement(op, spec, method, a, classResource);
 111    }
 112   
 113  2068 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  2068 if (_secondaryAnnotationWorker.canEnhance(method))
 119  4 _secondaryAnnotationWorker.peformEnhancement(op, spec, method, classResource);
 120    }
 121    catch (Exception ex)
 122    {
 123  4 _errorLog.error(AnnotationMessages.failureEnhancingMethod(method, ex), null, ex);
 124    }
 125    }
 126   
 127  600 void performMethodEnhancement(EnhancementOperation op, IComponentSpecification spec,
 128    Method method, Annotation annotation, Resource classResource)
 129    {
 130  600 MethodAnnotationEnhancementWorker worker = (MethodAnnotationEnhancementWorker) _methodWorkers
 131    .get(annotation.annotationType());
 132   
 133  600 if (worker == null)
 134  588 return;
 135   
 136  12 try
 137    {
 138  12 Location location = AnnotationUtils.buildLocationForAnnotation(
 139    method,
 140    annotation,
 141    classResource);
 142  12 worker.performEnhancement(op, spec, method, location);
 143    }
 144    catch (Exception ex)
 145    {
 146  4 _errorLog.error(
 147    AnnotationMessages.failureProcessingAnnotation(annotation, method, ex),
 148    null,
 149    ex);
 150    }
 151   
 152    }
 153   
 154  24 public void setMethodWorkers(Map methodWorkers)
 155    {
 156  24 _methodWorkers = methodWorkers;
 157    }
 158   
 159  12 public void setErrorLog(ErrorLog errorLog)
 160    {
 161  12 _errorLog = errorLog;
 162    }
 163   
 164  20 public void setClassResolver(ClassResolver classResolver)
 165    {
 166  20 _classResolver = classResolver;
 167    }
 168   
 169  36 public void setSecondaryAnnotationWorker(SecondaryAnnotationWorker secondaryWorker)
 170    {
 171  36 _secondaryAnnotationWorker = secondaryWorker;
 172    }
 173    }