Coverage Report - org.mule.endpoint.DynamicURIInboundEndpoint
 
Classes in this File Line Coverage Branch Coverage Complexity
DynamicURIInboundEndpoint
0%
0/78
0%
0/26
0
 
 1  
 /*
 2  
  * $Id: DynamicURIInboundEndpoint.java 20433 2010-12-02 04:48:11Z mike.schilling $
 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  
 
 11  
 package org.mule.endpoint;
 12  
 
 13  
 import org.mule.MessageExchangePattern;
 14  
 import org.mule.api.MuleContext;
 15  
 import org.mule.api.MuleException;
 16  
 import org.mule.api.MuleMessage;
 17  
 import org.mule.api.construct.FlowConstruct;
 18  
 import org.mule.api.endpoint.EndpointMessageProcessorChainFactory;
 19  
 import org.mule.api.endpoint.EndpointURI;
 20  
 import org.mule.api.endpoint.InboundEndpoint;
 21  
 import org.mule.api.lifecycle.LifecycleException;
 22  
 import org.mule.api.processor.MessageProcessor;
 23  
 import org.mule.api.retry.RetryPolicyTemplate;
 24  
 import org.mule.api.routing.filter.Filter;
 25  
 import org.mule.api.security.EndpointSecurityFilter;
 26  
 import org.mule.api.transaction.TransactionConfig;
 27  
 import org.mule.api.transformer.Transformer;
 28  
 import org.mule.api.transport.Connector;
 29  
 import org.mule.config.i18n.CoreMessages;
 30  
 
 31  
 import java.util.List;
 32  
 import java.util.Map;
 33  
 
 34  
 /**
 35  
  * Allow's EndpointURI to be set and changed dynamically by wrapping up an immutable endpoint instance.
 36  
  */
 37  
 public class DynamicURIInboundEndpoint implements InboundEndpoint
 38  
 {
 39  
 
 40  
     private static final long serialVersionUID = -2814979100270307813L;
 41  
 
 42  
     protected InboundEndpoint endpoint;
 43  
     private EndpointURI dynamicEndpointURI;
 44  
     private MessageProcessor listener;
 45  
     private FlowConstruct flowConstruct;
 46  
 
 47  
     public DynamicURIInboundEndpoint(InboundEndpoint endpoint)
 48  
     {
 49  0
         this(endpoint, null);
 50  0
     }
 51  
 
 52  
     public DynamicURIInboundEndpoint(InboundEndpoint endpoint, EndpointURI dynamicEndpointURI)
 53  0
     {
 54  
 //        if (endpoint instanceof DynamicURIInboundEndpoint) 
 55  
 //        {
 56  
 //            throw new IllegalArgumentException("Dynamic endpoints can only wrap immuntable InboundEndpoint instances!");
 57  
 //        }
 58  
 //        
 59  0
         this.endpoint = endpoint;
 60  0
         setEndpointURI(dynamicEndpointURI);
 61  0
     }
 62  
 
 63  
     public EndpointURI getEndpointURI()
 64  
     {
 65  0
         if (dynamicEndpointURI != null)
 66  
         {
 67  0
             return dynamicEndpointURI;
 68  
         }
 69  
         else
 70  
         {
 71  0
             return endpoint.getEndpointURI();
 72  
         }
 73  
     }
 74  
 
 75  
     public String getAddress()
 76  
     {
 77  0
         EndpointURI uri = getEndpointURI();
 78  0
         if (uri != null)
 79  
         {
 80  0
             return uri.getUri().toString();
 81  
         }
 82  
         else
 83  
         {
 84  0
             return null;
 85  
         }
 86  
     }
 87  
 
 88  
     public void setEndpointURI(EndpointURI dynamicEndpointURI)
 89  
     {
 90  0
         this.dynamicEndpointURI = dynamicEndpointURI;
 91  0
     }
 92  
 
 93  
     public RetryPolicyTemplate getRetryPolicyTemplate()
 94  
     {
 95  0
         return endpoint.getRetryPolicyTemplate();
 96  
     }
 97  
 
 98  
     public Connector getConnector()
 99  
     {
 100  0
         return endpoint.getConnector();
 101  
     }
 102  
 
 103  
     public String getEncoding()
 104  
     {
 105  0
         return endpoint.getEncoding();
 106  
     }
 107  
 
 108  
     public String getMimeType()
 109  
     {
 110  0
         return endpoint.getMimeType();
 111  
     }
 112  
 
 113  
     public Filter getFilter()
 114  
     {
 115  0
         return endpoint.getFilter();
 116  
     }
 117  
 
 118  
     public String getInitialState()
 119  
     {
 120  0
         return endpoint.getInitialState();
 121  
     }
 122  
 
 123  
     public MuleContext getMuleContext()
 124  
     {
 125  0
         return endpoint.getMuleContext();
 126  
     }
 127  
 
 128  
     public String getName()
 129  
     {
 130  0
         return endpoint.getName();
 131  
     }
 132  
 
 133  
     public Map getProperties()
 134  
     {
 135  0
         return endpoint.getProperties();
 136  
     }
 137  
 
 138  
     public Object getProperty(Object key)
 139  
     {
 140  0
         return endpoint.getProperty(key);
 141  
     }
 142  
 
 143  
     public String getProtocol()
 144  
     {
 145  0
         return endpoint.getProtocol();
 146  
     }
 147  
 
 148  
     public int getResponseTimeout()
 149  
     {
 150  0
         return endpoint.getResponseTimeout();
 151  
     }
 152  
 
 153  
     public List<Transformer> getResponseTransformers()
 154  
     {
 155  0
         return endpoint.getResponseTransformers();
 156  
     }
 157  
 
 158  
     public EndpointMessageProcessorChainFactory getMessageProcessorsFactory()
 159  
     {
 160  0
         return endpoint.getMessageProcessorsFactory();
 161  
     }
 162  
     
 163  
     public List <MessageProcessor> getMessageProcessors()
 164  
     {
 165  0
         return endpoint.getMessageProcessors();
 166  
     }
 167  
 
 168  
     public List<MessageProcessor> getResponseMessageProcessors()
 169  
     {
 170  0
         return endpoint.getResponseMessageProcessors();
 171  
     }
 172  
 
 173  
     public EndpointSecurityFilter getSecurityFilter()
 174  
     {
 175  0
         return endpoint.getSecurityFilter();
 176  
     }
 177  
 
 178  
     public TransactionConfig getTransactionConfig()
 179  
     {
 180  0
         return endpoint.getTransactionConfig();
 181  
     }
 182  
 
 183  
     public List<Transformer> getTransformers()
 184  
     {
 185  0
         return endpoint.getTransformers();
 186  
     }
 187  
 
 188  
     public boolean isDeleteUnacceptedMessages()
 189  
     {
 190  0
         return endpoint.isDeleteUnacceptedMessages();
 191  
     }
 192  
 
 193  
     public boolean isReadOnly()
 194  
     {
 195  0
         return endpoint.isReadOnly();
 196  
     }
 197  
     
 198  
     public MessageExchangePattern getExchangePattern()
 199  
     {
 200  0
         return endpoint.getExchangePattern();
 201  
     }
 202  
 
 203  
     public MuleMessage request(long timeout) throws Exception
 204  
     {
 205  0
         return getConnector().request(this, timeout);
 206  
     }
 207  
 
 208  
     public String getEndpointBuilderName()
 209  
     {
 210  0
         return endpoint.getEndpointBuilderName();
 211  
     }
 212  
 
 213  
     public boolean isProtocolSupported(String protocol)
 214  
     {
 215  0
         return getConnector().supportsProtocol(protocol);
 216  
     }
 217  
 
 218  
     public boolean isDisableTransportTransformer()
 219  
     {
 220  0
         return endpoint.isDisableTransportTransformer();
 221  
     }
 222  
 
 223  
     @Override
 224  
     public int hashCode()
 225  
     {
 226  0
         final int prime = 31;
 227  0
         int result = 1;
 228  0
         result = prime * result + ((dynamicEndpointURI == null) ? 0 : dynamicEndpointURI.hashCode());
 229  0
         result = prime * result + ((endpoint == null) ? 0 : endpoint.hashCode());
 230  0
         return result;
 231  
     }
 232  
 
 233  
     @Override
 234  
     public boolean equals(Object obj)
 235  
     {
 236  0
         if (this == obj)
 237  
         {
 238  0
             return true;
 239  
         }
 240  0
         if (obj == null)
 241  
         {
 242  0
             return false;
 243  
         }
 244  0
         if (getClass() != obj.getClass())
 245  
         {
 246  0
             return false;
 247  
         }
 248  0
         final DynamicURIInboundEndpoint other = (DynamicURIInboundEndpoint) obj;
 249  0
         if (dynamicEndpointURI == null)
 250  
         {
 251  0
             if (other.dynamicEndpointURI != null)
 252  
             {
 253  0
                 return false;
 254  
             }
 255  
         }
 256  0
         else if (!dynamicEndpointURI.equals(other.dynamicEndpointURI))
 257  
         {
 258  0
             return false;
 259  
         }
 260  0
         if (endpoint == null)
 261  
         {
 262  0
             if (other.endpoint != null)
 263  
             {
 264  0
                 return false;
 265  
             }
 266  
         }
 267  0
         else if (!endpoint.equals(other.endpoint))
 268  
         {
 269  0
             return false;
 270  
         }
 271  0
         return true;
 272  
     }
 273  
 
 274  
     public void start() throws MuleException
 275  
     {
 276  
         try
 277  
         {
 278  0
             getConnector().registerListener(this, listener, flowConstruct);
 279  
         }
 280  0
         catch (Exception e)
 281  
         {
 282  0
             throw new LifecycleException(CoreMessages.failedToStartInboundEndpoint(this), e, this);
 283  0
         }
 284  0
     }
 285  
 
 286  
     public void stop() throws MuleException
 287  
     {
 288  
         try
 289  
         {
 290  0
             getConnector().unregisterListener(this, flowConstruct);
 291  
         }
 292  0
         catch (Exception e)
 293  
         {
 294  0
             throw new LifecycleException(CoreMessages.failedToStartInboundEndpoint(this), e, this);
 295  0
         }
 296  0
     }
 297  
 
 298  
     public void setFlowConstruct(FlowConstruct flowConstruct)
 299  
     {
 300  0
         this.flowConstruct = flowConstruct;
 301  0
     }
 302  
 
 303  
     public void setListener(MessageProcessor listener)
 304  
     {
 305  0
         this.listener = listener;
 306  0
     }
 307  
 }