Coverage Report - org.apache.tapestry5.internal.transform.LogWorker
 
Classes in this File Line Coverage Branch Coverage Complexity
LogWorker
100%
10/10
100%
4/4
0
LogWorker$1
100%
3/3
N/A
0
 
 1  
 // Copyright 2008 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.tapestry5.internal.transform;
 16  
 
 17  
 import org.apache.tapestry5.annotations.Log;
 18  
 import org.apache.tapestry5.ioc.MethodAdvice;
 19  
 import org.apache.tapestry5.ioc.internal.services.LoggingAdvice;
 20  
 import org.apache.tapestry5.ioc.services.ExceptionTracker;
 21  
 import org.apache.tapestry5.model.MutableComponentModel;
 22  
 import org.apache.tapestry5.services.*;
 23  
 
 24  
 import java.util.List;
 25  
 
 26  
 /**
 27  
  * Looks for the {@link org.apache.tapestry5.annotations.Log} marker annotation and adds method advice to perform the
 28  
  * logging. This is similar to what the {@link org.apache.tapestry5.ioc.services.LoggingDecorator} does for service
 29  
  * interface methods.
 30  
  */
 31  
 public class LogWorker implements ComponentClassTransformWorker
 32  
 {
 33  
     private final ExceptionTracker exceptionTracker;
 34  
 
 35  
     public LogWorker(ExceptionTracker exceptionTracker)
 36  58
     {
 37  58
         this.exceptionTracker = exceptionTracker;
 38  58
     }
 39  
 
 40  
     public void transform(ClassTransformation transformation, MutableComponentModel model)
 41  
     {
 42  810
         List<TransformMethodSignature> signatures = transformation.findMethodsWithAnnotation(Log.class);
 43  
 
 44  810
         if (signatures.isEmpty()) return;
 45  
 
 46  
         // Re-use the logging advice from LoggingDecorator
 47  24
         final MethodAdvice loggingAdvice = new LoggingAdvice(model.getLogger(), exceptionTracker);
 48  
 
 49  
         // ... but wrap it for use at the component level.
 50  24
         ComponentMethodAdvice advice = new ComponentMethodAdvice()
 51  
         {
 52  24
             public void advise(ComponentMethodInvocation invocation)
 53  
             {
 54  186
                 loggingAdvice.advise(invocation);
 55  184
             }
 56  
         };
 57  
 
 58  24
         for (TransformMethodSignature signature : signatures)
 59  28
             transformation.advise(signature, advice);
 60  24
     }
 61  
 }