Coverage Report - org.mule.config.expression.ExpressionAnnotationsHelper
 
Classes in this File Line Coverage Branch Coverage Complexity
ExpressionAnnotationsHelper
0%
0/24
0%
0/10
0
 
 1  
 /*
 2  
  * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
 3  
  * The software in this package is published under the terms of the CPAL v1.0
 4  
  * license, a copy of which has been included with this distribution in the
 5  
  * LICENSE.txt file.
 6  
  */
 7  
 package org.mule.config.expression;
 8  
 
 9  
 import org.apache.commons.logging.Log;
 10  
 import org.apache.commons.logging.LogFactory;
 11  
 import org.mule.api.MuleContext;
 12  
 import org.mule.api.expression.ExpressionAnnotationParser;
 13  
 import org.mule.api.lifecycle.InitialisationException;
 14  
 import org.mule.api.registry.RegistrationException;
 15  
 import org.mule.api.transformer.TransformerException;
 16  
 import org.mule.config.AnnotationsParserFactory;
 17  
 import org.mule.config.i18n.AnnotationsMessages;
 18  
 import org.mule.expression.transformers.ExpressionArgument;
 19  
 import org.mule.expression.transformers.ExpressionTransformer;
 20  
 
 21  
 import java.lang.annotation.Annotation;
 22  
 import java.lang.reflect.Method;
 23  
 
 24  
 /**
 25  
  * TODO
 26  
  */
 27  0
 public class ExpressionAnnotationsHelper
 28  
 {
 29  0
     protected static Log logger = LogFactory.getLog(ExpressionAnnotationsHelper.class);
 30  
 
 31  
     public static ExpressionTransformer getTransformerForMethodWithAnnotations(Method method, MuleContext context) throws TransformerException, InitialisationException
 32  
     {
 33  0
         ExpressionTransformer trans = new ExpressionTransformer();
 34  0
         trans.setMuleContext(context);
 35  
 
 36  0
         Annotation[][] annotations = method.getParameterAnnotations();
 37  
 
 38  0
         for (int i = 0; i < annotations.length; i++)
 39  
         {
 40  0
             Annotation[] annotation = annotations[i];
 41  0
             for (int j = 0; j < annotation.length; j++)
 42  
             {
 43  0
                 Annotation ann = annotation[j];
 44  0
                 ExpressionArgument arg = parseAnnotation(ann, method.getParameterTypes()[i], context);
 45  
 
 46  0
                 if (arg != null)
 47  
                 {
 48  0
                     trans.addArgument(arg);
 49  
                 }
 50  
             }
 51  
         }
 52  0
         trans.initialise();
 53  0
         return trans;
 54  
     }
 55  
 
 56  
     static synchronized ExpressionArgument parseAnnotation(Annotation annotation, 
 57  
         Class<?> paramType, MuleContext muleContext)
 58  
     {
 59  
         AnnotationsParserFactory factory;
 60  
         try
 61  
         {
 62  0
             factory = muleContext.getRegistry().lookupObject(AnnotationsParserFactory.class);
 63  
         }
 64  0
         catch (RegistrationException e)
 65  
         {
 66  
             //TODO better exception message
 67  0
             throw new IllegalArgumentException(AnnotationsMessages.noParserFoundForAnnotation(annotation).getMessage());
 68  0
         }
 69  
         
 70  0
         ExpressionAnnotationParser parser = factory.getExpressionParser(annotation);
 71  0
         if (parser == null)
 72  
         {
 73  0
             if (logger.isDebugEnabled())
 74  
             {
 75  0
                 logger.debug(AnnotationsMessages.noParserFoundForAnnotation(annotation).getMessage());
 76  
             }
 77  0
             return null;
 78  
         }
 79  0
         return parser.parse(annotation, paramType);
 80  
     }
 81  
 }