Coverage Report - org.mule.config.endpoint.AnnotatedEndpointData
 
Classes in this File Line Coverage Branch Coverage Complexity
AnnotatedEndpointData
0%
0/60
0%
0/18
1.44
 
 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.endpoint;
 8  
 
 9  
 import org.mule.MessageExchangePattern;
 10  
 import org.mule.api.annotations.meta.ChannelType;
 11  
 import org.mule.api.transport.Connector;
 12  
 import org.mule.util.StringUtils;
 13  
 
 14  
 import java.lang.annotation.Annotation;
 15  
 import java.lang.reflect.Method;
 16  
 import java.util.HashMap;
 17  
 import java.util.Map;
 18  
 import java.util.Properties;
 19  
 
 20  
 /**
 21  
  * Provides a generic endpoint data wrapper so that we can just use a single method for processing
 22  
  * endpoints and reduce a load of duplication
 23  
  */
 24  
 public class AnnotatedEndpointData
 25  
 {
 26  
     private String encoding;
 27  0
     private Map properties = new HashMap();
 28  
     private String connectorName;
 29  
     private String transformers;
 30  
     private String address;
 31  
     private String name;
 32  
     private String filter;
 33  
     private String correlationExpression;
 34  
     private Connector connector;
 35  
     private MessageExchangePattern mep;
 36  
     private ChannelType type;
 37  
     private Annotation annotation;
 38  
 
 39  
     public AnnotatedEndpointData(MessageExchangePattern mep, ChannelType type, Annotation annotation)
 40  0
     {
 41  0
         this.mep = mep;
 42  0
         this.annotation = annotation;
 43  0
         this.type = type;
 44  0
     }
 45  
 
 46  
     protected String emptyToNull(String value)
 47  
     {
 48  0
         return (StringUtils.EMPTY.equals(value) ? null : value);
 49  
     }
 50  
 
 51  
 
 52  
     public String getConnectorName()
 53  
     {
 54  0
         return connectorName;
 55  
     }
 56  
 
 57  
     public String getEncoding()
 58  
     {
 59  0
         return encoding;
 60  
     }
 61  
 
 62  
     public String getAddress()
 63  
     {
 64  0
         return address;
 65  
     }
 66  
 
 67  
     public Map getProperties()
 68  
     {
 69  0
         return properties;
 70  
     }
 71  
 
 72  
     public ChannelType getType()
 73  
     {
 74  0
         return type;
 75  
     }
 76  
 
 77  
     public String getFilter()
 78  
     {
 79  0
         return filter;
 80  
     }
 81  
 
 82  
     public String getCorrelationExpression()
 83  
     {
 84  0
         return correlationExpression;
 85  
     }
 86  
 
 87  
     public Connector getConnector()
 88  
     {
 89  0
         return connector;
 90  
     }
 91  
 
 92  
     public void setConnector(Connector connector)
 93  
     {
 94  0
         this.connector = connector;
 95  0
     }
 96  
 
 97  
     public String getTransformers()
 98  
     {
 99  0
         return transformers;
 100  
     }
 101  
 
 102  
     public String getName()
 103  
     {
 104  0
         return name;
 105  
     }
 106  
 
 107  
     public void setName(String name)
 108  
     {
 109  0
         this.name = emptyToNull(name);
 110  0
     }
 111  
 
 112  
     public void setEncoding(String encoding)
 113  
     {
 114  0
         this.encoding = emptyToNull(encoding);
 115  0
     }
 116  
 
 117  
     public Annotation getAnnotation()
 118  
     {
 119  0
         return annotation;
 120  
     }
 121  
 
 122  
     public void setProperties(Map properties)
 123  
     {
 124  0
         if (properties == null)
 125  
         {
 126  0
             return;
 127  
         }
 128  
 
 129  0
         this.properties = properties;
 130  
         //Special handling of "Mule" endpoint properties
 131  0
         if (properties != null)
 132  
         {
 133  0
             if (properties.containsKey("connectorName"))
 134  
             {
 135  0
                 setConnectorName((String) properties.remove("connectorName"));
 136  
             }
 137  
         }
 138  0
     }
 139  
 
 140  
     public void setConnectorName(String connectorName)
 141  
     {
 142  0
         this.connectorName = emptyToNull(connectorName);
 143  0
     }
 144  
 
 145  
     public void setTransformers(String transformers)
 146  
     {
 147  0
         this.transformers = emptyToNull(transformers);
 148  0
     }
 149  
 
 150  
     public void setAddress(String address)
 151  
     {
 152  0
         this.address = emptyToNull(address);
 153  0
     }
 154  
 
 155  
     public void setFilter(String filter)
 156  
     {
 157  0
         this.filter = emptyToNull(filter);
 158  0
     }
 159  
 
 160  
     public void setCorrelationExpression(String correlationExpression)
 161  
     {
 162  0
         this.correlationExpression = emptyToNull(correlationExpression);
 163  0
     }
 164  
 
 165  
     public MessageExchangePattern getMep()
 166  
     {
 167  0
         return mep;
 168  
     }
 169  
 
 170  
 
 171  
 
 172  
     public void setMEPUsingMethod(Method method)
 173  
     {
 174  0
         if (method.getReturnType().equals(Void.TYPE))
 175  
         {
 176  0
             mep = MessageExchangePattern.ONE_WAY;
 177  
         }
 178  
         else
 179  
         {
 180  0
             mep = MessageExchangePattern.REQUEST_RESPONSE;
 181  
         }
 182  
 
 183  0
     }
 184  
 
 185  
     public static Map convert(String[] properties)
 186  
     {
 187  0
         if (properties.length > 0)
 188  
         {
 189  0
             Properties props = new Properties();
 190  0
             for (int i = 0; i < properties.length; i++)
 191  
             {
 192  0
                 String property = properties[i];
 193  0
                 if (property.length() == 0)
 194  
                 {
 195  0
                     continue;
 196  
                 }
 197  0
                 int x = property.indexOf("=");
 198  0
                 if (x < 1)
 199  
                 {
 200  0
                     throw new IllegalArgumentException("Property string is malformed: " + property);
 201  
                 }
 202  0
                 String value = property.substring(x + 1);
 203  0
                 property = property.substring(0, x);
 204  0
                 props.setProperty(property, value);
 205  
 
 206  
             }
 207  0
             return props;
 208  
         }
 209  0
         return null;
 210  
     }
 211  
 }