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