Coverage Report - org.mule.module.ibeans.config.CallAnnotationParser
 
Classes in this File Line Coverage Branch Coverage Complexity
CallAnnotationParser
0%
0/29
0%
0/20
0
 
 1  
 /*
 2  
  * $Id: CallAnnotationParser.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.module.ibeans.config;
 11  
 
 12  
 import org.mule.MessageExchangePattern;
 13  
 import org.mule.api.MuleException;
 14  
 import org.mule.api.annotations.meta.Channel;
 15  
 import org.mule.api.annotations.meta.ChannelType;
 16  
 import org.mule.api.endpoint.InboundEndpoint;
 17  
 import org.mule.api.endpoint.OutboundEndpoint;
 18  
 import org.mule.config.endpoint.AbstractEndpointAnnotationParser;
 19  
 import org.mule.config.endpoint.AnnotatedEndpointData;
 20  
 import org.mule.module.ibeans.i18n.IBeansMessages;
 21  
 import org.mule.module.ibeans.spi.support.CallOutboundEndpoint;
 22  
 import org.mule.module.ibeans.spi.support.CallRequestEndpoint;
 23  
 
 24  
 import java.beans.ExceptionListener;
 25  
 import java.lang.annotation.Annotation;
 26  
 import java.lang.reflect.Member;
 27  
 import java.lang.reflect.Method;
 28  
 import java.util.Map;
 29  
 
 30  
 import org.ibeans.annotation.Call;
 31  
 import org.ibeans.api.CallException;
 32  
 import org.ibeans.api.ExceptionListenerAware;
 33  
 
 34  
 /**
 35  
  * The parser responsible for parsing {@link org.ibeans.annotation.Call} annotations.
 36  
  */
 37  0
 public class CallAnnotationParser extends AbstractEndpointAnnotationParser
 38  
 {
 39  
     protected AnnotatedEndpointData createEndpointData(Annotation annotation) throws MuleException
 40  
     {
 41  0
         Call call = (Call) annotation;
 42  0
         AnnotatedEndpointData epd = new AnnotatedEndpointData(MessageExchangePattern.REQUEST_RESPONSE, ChannelType.Outbound, call);
 43  0
         epd.setAddress(call.uri());
 44  0
         epd.setProperties(AnnotatedEndpointData.convert(call.properties()));
 45  0
         return epd;
 46  
     }
 47  
 
 48  
     protected String getIdentifier()
 49  
     {
 50  0
         return Call.class.getAnnotation(Channel.class).identifer();
 51  
     }
 52  
 
 53  
     @Override
 54  
     public boolean supports(Annotation annotation, Class clazz, Member member)
 55  
     {
 56  
         //You cannot use the @Call annotation on an implementation class
 57  0
         boolean supports = clazz.isInterface();
 58  0
         if (supports)
 59  
         {
 60  0
             supports = annotation instanceof Call;  
 61  
         }
 62  0
         if (supports)
 63  
         {
 64  
             //Allow services to extend an exception listener that the user can plug in
 65  0
             if (ExceptionListenerAware.class.isAssignableFrom(clazz))
 66  
             {
 67  0
                 supports = true;
 68  
             }
 69  
             else
 70  
             {
 71  0
                 Class[] exceptionTypes = ((Method) member).getExceptionTypes();
 72  0
                 boolean hasValidExceptionType = false;
 73  0
                 for (int i = 0; i < exceptionTypes.length; i++)
 74  
                 {
 75  0
                     Class exceptionType = exceptionTypes[i];
 76  0
                     hasValidExceptionType = exceptionType.equals(Exception.class) || exceptionType.isAssignableFrom(CallException.class) || clazz.isAssignableFrom(ExceptionListener.class);
 77  
                 }
 78  0
                 if (!hasValidExceptionType)
 79  
                 {
 80  0
                     throw new IllegalArgumentException(IBeansMessages.illegalCallMethod((Method)member).getMessage());
 81  
                 }
 82  
             }
 83  
         }
 84  0
         return supports;
 85  
     }
 86  
 
 87  
     public OutboundEndpoint parseOutboundEndpoint(Annotation annotation, Map metaInfo) throws MuleException
 88  
     {
 89  0
         AnnotatedEndpointData data = createEndpointData(annotation);
 90  0
         if (data.getConnectorName() == null)
 91  
         {
 92  0
             data.setConnectorName((String) metaInfo.get("connectorName"));
 93  
         }
 94  0
         return new CallOutboundEndpoint(muleContext, data);
 95  
     }
 96  
 
 97  
     public InboundEndpoint parseInboundEndpoint(Annotation annotation, Map metaInfo) throws MuleException
 98  
     {
 99  0
         AnnotatedEndpointData data = createEndpointData(annotation);
 100  0
         if (data.getConnectorName() == null)
 101  
         {
 102  0
             data.setConnectorName((String) metaInfo.get("connectorName"));
 103  
         }
 104  0
         return new CallRequestEndpoint(muleContext, data);
 105  
     }
 106  
 }