Coverage Report - org.mule.config.endpoint.AbstractEndpointAnnotationParser
 
Classes in this File Line Coverage Branch Coverage Complexity
AbstractEndpointAnnotationParser
0%
0/29
0%
0/22
0
 
 1  
 /*
 2  
  * $Id: AbstractEndpointAnnotationParser.java 17843 2010-07-03 22:08:57Z rossmason $
 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.endpoint;
 11  
 
 12  
 import org.mule.api.EndpointAnnotationParser;
 13  
 import org.mule.api.MuleContext;
 14  
 import org.mule.api.MuleException;
 15  
 import org.mule.api.annotations.meta.Channel;
 16  
 import org.mule.api.config.ConfigurationException;
 17  
 import org.mule.api.context.MuleContextAware;
 18  
 import org.mule.api.endpoint.InboundEndpoint;
 19  
 import org.mule.api.endpoint.OutboundEndpoint;
 20  
 import org.mule.config.i18n.CoreMessages;
 21  
 import org.mule.util.StringUtils;
 22  
 
 23  
 import java.lang.annotation.Annotation;
 24  
 import java.lang.reflect.Member;
 25  
 import java.util.Map;
 26  
 import java.util.Properties;
 27  
 import java.util.StringTokenizer;
 28  
 
 29  
 /**
 30  
  * TODO
 31  
  */
 32  0
 public abstract class AbstractEndpointAnnotationParser implements EndpointAnnotationParser, MuleContextAware
 33  
 {
 34  
     public static final String ENDPOINT_BUILDER_POSTFIX = ".builder";
 35  
 
 36  
     protected MuleContext muleContext;
 37  
 
 38  
     public void setMuleContext(MuleContext context)
 39  
     {
 40  0
         this.muleContext = context;
 41  0
     }
 42  
 
 43  
     protected AnnotatedEndpointHelper getEndpointHelper() throws MuleException
 44  
     {
 45  0
         AnnotatedEndpointHelper helper = muleContext.getRegistry().lookupObject(AnnotatedEndpointHelper.class);
 46  0
         if (helper == null)
 47  
         {
 48  0
             helper = new AnnotatedEndpointHelper(muleContext);
 49  
         }
 50  0
         return helper;
 51  
     }
 52  
 
 53  
     public OutboundEndpoint parseOutboundEndpoint(Annotation annotation, Map metaInfo) throws MuleException
 54  
     {
 55  0
         return (OutboundEndpoint) getEndpointHelper().processEndpoint(createEndpointData(annotation));
 56  
     }
 57  
 
 58  
     public InboundEndpoint parseInboundEndpoint(Annotation annotation, Map metaInfo) throws MuleException
 59  
     {
 60  0
         return (InboundEndpoint) getEndpointHelper().processEndpoint(createEndpointData(annotation));
 61  
     }
 62  
 
 63  
     public boolean supports(Annotation annotation, Class clazz, Member member)
 64  
     {
 65  0
         Channel channel = annotation.annotationType().getAnnotation(Channel.class);
 66  0
         return channel != null && channel.identifer().equals(getIdentifier());
 67  
     }
 68  
 
 69  
     protected Properties convertProperties(String[] properties)
 70  
     {
 71  0
         if(properties==null || properties.length==0)
 72  
         {
 73  0
             return null;
 74  
         }
 75  
         
 76  0
         Properties props = new Properties();
 77  0
         for (String property : properties)
 78  
         {
 79  0
             StringTokenizer st = new StringTokenizer(property, "=");
 80  0
             if(st.hasMoreTokens())
 81  
             {
 82  0
                 props.setProperty(st.nextToken().trim(), st.nextToken().trim());
 83  
             }
 84  
         }
 85  0
         return props;
 86  
     }
 87  
 
 88  
     protected <T> T lookupConfig(String location, Class<T> type) throws ConfigurationException
 89  
     {
 90  0
         if (StringUtils.isEmpty(location))
 91  
         {
 92  0
             return null;
 93  
         }
 94  0
         Object o = muleContext.getRegistry().lookupObject(location + ENDPOINT_BUILDER_POSTFIX);
 95  0
         if (o == null)
 96  
         {
 97  0
             o = muleContext.getRegistry().lookupObject(location);
 98  0
             if (o == null)
 99  
             {
 100  0
                 return null;
 101  
                 //throw new ConfigurationException(CoreMessages.objectNotFound(location));
 102  
             }
 103  
         }
 104  0
         if (type.isInstance(o))
 105  
         {
 106  0
             return (T) o;
 107  
         }
 108  
         else
 109  
         {
 110  0
             throw new ConfigurationException(CoreMessages.objectNotOfCorrectType(o.getClass(), type));
 111  
         }
 112  
     }
 113  
 
 114  
     protected abstract String getIdentifier();
 115  
 
 116  
     protected abstract AnnotatedEndpointData createEndpointData(Annotation annotation) throws MuleException;
 117  
 }