Coverage Report - org.mule.endpoint.AbstractEndpointBuilder
 
Classes in this File Line Coverage Branch Coverage Complexity
AbstractEndpointBuilder
76%
170/223
54%
76/140
2.044
 
 1  
 /*
 2  
  * $Id: AbstractEndpointBuilder.java 12269 2008-07-10 04:19:03Z dfeist $
 3  
  * --------------------------------------------------------------------------------------
 4  
  * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.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.RegistryContext;
 14  
 import org.mule.api.DefaultMuleException;
 15  
 import org.mule.api.MuleContext;
 16  
 import org.mule.api.MuleRuntimeException;
 17  
 import org.mule.api.config.MuleProperties;
 18  
 import org.mule.api.endpoint.EndpointBuilder;
 19  
 import org.mule.api.endpoint.EndpointException;
 20  
 import org.mule.api.endpoint.EndpointURI;
 21  
 import org.mule.api.endpoint.ImmutableEndpoint;
 22  
 import org.mule.api.endpoint.InboundEndpoint;
 23  
 import org.mule.api.endpoint.OutboundEndpoint;
 24  
 import org.mule.api.lifecycle.InitialisationException;
 25  
 import org.mule.api.registry.ServiceDescriptorFactory;
 26  
 import org.mule.api.registry.ServiceException;
 27  
 import org.mule.api.routing.filter.Filter;
 28  
 import org.mule.api.security.EndpointSecurityFilter;
 29  
 import org.mule.api.transaction.TransactionConfig;
 30  
 import org.mule.api.transformer.Transformer;
 31  
 import org.mule.api.transport.ConnectionStrategy;
 32  
 import org.mule.api.transport.Connector;
 33  
 import org.mule.config.i18n.CoreMessages;
 34  
 import org.mule.config.i18n.Message;
 35  
 import org.mule.transaction.MuleTransactionConfig;
 36  
 import org.mule.transformer.TransformerUtils;
 37  
 import org.mule.transport.AbstractConnector;
 38  
 import org.mule.transport.service.TransportFactory;
 39  
 import org.mule.transport.service.TransportFactoryException;
 40  
 import org.mule.transport.service.TransportServiceDescriptor;
 41  
 import org.mule.util.CharSetUtils;
 42  
 import org.mule.util.ClassUtils;
 43  
 import org.mule.util.MapCombiner;
 44  
 import org.mule.util.ObjectNameHelper;
 45  
 
 46  
 import java.util.Collections;
 47  
 import java.util.HashMap;
 48  
 import java.util.LinkedList;
 49  
 import java.util.List;
 50  
 import java.util.Map;
 51  
 import java.util.Properties;
 52  
 
 53  
 /**
 54  
  * Abstract endpoint builder used for externalizing the complex creation logic of
 55  
  * endpoints out of the endpoint instance itself. <br/> The use of a builder allows
 56  
  * i) Endpoints to be configured once and created in a repeatable fashion (global
 57  
  * endpoints), ii) Allow for much more extensibility in endpoint creation for
 58  
  * transport specific endpoints, streaming endpoints etc.<br/>
 59  
  */
 60  486
 public abstract class AbstractEndpointBuilder implements EndpointBuilder
 61  
 {
 62  
 
 63  
     public static final String PROPERTY_REMOTE_SYNC = "remoteSync";
 64  
     public static final String PROPERTY_REMOTE_SYNC_TIMEOUT = "remoteSyncTimeout";
 65  
 
 66  
     protected URIBuilder uriBuilder;
 67  
     protected Connector connector;
 68  
     protected List transformers;
 69  
     protected List responseTransformers;
 70  
     protected String name;
 71  486
     protected Map properties = new HashMap();
 72  
     protected TransactionConfig transactionConfig;
 73  
     protected Filter filter;
 74  
     protected Boolean deleteUnacceptedMessages;
 75  
     protected EndpointSecurityFilter securityFilter;
 76  
     protected Boolean synchronous;
 77  
     protected Boolean remoteSync;
 78  
     protected Integer remoteSyncTimeout;
 79  486
     protected String initialState = ImmutableEndpoint.INITIAL_STATE_STARTED;
 80  
     protected String encoding;
 81  
     protected Integer createConnector;
 82  
     protected ConnectionStrategy connectionStrategy;
 83  
 
 84  
     // not included in equality/hash
 85  486
     protected String registryId = null;
 86  
     protected MuleContext muleContext;
 87  
 
 88  
     public InboundEndpoint buildInboundEndpoint() throws EndpointException, InitialisationException
 89  
     {
 90  68
         return doBuildInboundEndpoint();
 91  
     }
 92  
 
 93  
     public OutboundEndpoint buildOutboundEndpoint() throws EndpointException, InitialisationException
 94  
     {
 95  420
         return doBuildOutboundEndpoint();
 96  
     }
 97  
 
 98  
     protected void setPropertiesFromProperties(Map properties)
 99  
     {
 100  486
         synchronous = getBooleanProperty(properties, MuleProperties.SYNCHRONOUS_PROPERTY, synchronous);
 101  486
         remoteSync = getBooleanProperty(properties, PROPERTY_REMOTE_SYNC, remoteSync);
 102  486
         remoteSyncTimeout = getIntegerProperty(properties, PROPERTY_REMOTE_SYNC_TIMEOUT, remoteSyncTimeout);
 103  486
     }
 104  
 
 105  
     public static Boolean getBooleanProperty(Map properties, String name, Boolean dflt)
 106  
     {
 107  972
         if (properties.containsKey(name))
 108  
         {
 109  0
             return Boolean.valueOf((String) properties.get(name));
 110  
         }
 111  
         else
 112  
         {
 113  972
             return dflt;
 114  
         }
 115  
     }
 116  
 
 117  
     public static Integer getIntegerProperty(Map properties, String name, Integer dflt)
 118  
     {
 119  486
         if (properties.containsKey(name))
 120  
         {
 121  0
             return Integer.decode((String) properties.get(name));
 122  
         }
 123  
         else
 124  
         {
 125  486
             return dflt;
 126  
         }
 127  
     }
 128  
 
 129  
     protected InboundEndpoint doBuildInboundEndpoint() throws InitialisationException, EndpointException
 130  
     {
 131  
         // use an explicit value here to avoid caching
 132  68
         Map properties = getProperties();
 133  
         // this sets values used below, if they appear as properties
 134  68
         setPropertiesFromProperties(properties);
 135  
 
 136  68
         if (uriBuilder == null)
 137  
         {
 138  0
             throw new MuleRuntimeException(CoreMessages.objectIsNull("uriBuilder"));
 139  
         }
 140  
 
 141  68
         EndpointURI endpointURI = uriBuilder.getEndpoint();
 142  68
         endpointURI.initialise();
 143  
 
 144  68
         Connector connector = getConnector();
 145  
 
 146  68
         if (connector != null && endpointURI != null && !connector.supportsProtocol(endpointURI.getFullScheme()))
 147  
         {
 148  0
             throw new IllegalArgumentException(CoreMessages.connectorSchemeIncompatibleWithEndpointScheme(
 149  
                 connector.getProtocol(), endpointURI).getMessage());
 150  
         }
 151  
 
 152  68
         List transformers = getInboundTransformers(connector, endpointURI);
 153  68
         List responseTransformers = getInboundEndpointResponseTransformers(connector, endpointURI);
 154  
 
 155  68
         boolean remoteSync = getRemoteSync(connector);
 156  
         boolean synchronous;
 157  68
         if (remoteSync)
 158  
         {
 159  0
             synchronous = true;
 160  
         }
 161  
         else
 162  
         {
 163  68
             synchronous = getSynchronous(connector, endpointURI);
 164  
         }
 165  
 
 166  68
         return new DefaultInboundEndpoint(connector, endpointURI, transformers, responseTransformers,
 167  
             getName(endpointURI), getProperties(), getTransactionConfig(), getFilter(connector),
 168  
             getDefaultDeleteUnacceptedMessages(connector), getSecurityFilter(), synchronous, remoteSync,
 169  
             getRemoteSyncTimeout(connector), getInitialState(connector), getEndpointEncoding(connector), muleContext,
 170  
             getConnectionStrategy(connector));
 171  
     }
 172  
 
 173  
     protected OutboundEndpoint doBuildOutboundEndpoint() throws InitialisationException, EndpointException
 174  
     {
 175  
         // use an explicit value here to avoid caching
 176  420
         Map properties = getProperties();
 177  
         // this sets values used below, if they appear as properties
 178  418
         setPropertiesFromProperties(properties);
 179  
 
 180  418
         if (uriBuilder == null)
 181  
         {
 182  0
             throw new MuleRuntimeException(CoreMessages.objectIsNull("uriBuilder"));
 183  
         }
 184  
 
 185  418
         EndpointURI endpointURI = uriBuilder.getEndpoint();
 186  418
         endpointURI.initialise();
 187  
 
 188  418
         Connector connector = getConnector();
 189  
 
 190  418
         if (connector != null && endpointURI != null && !connector.supportsProtocol(endpointURI.getFullScheme()))
 191  
         {
 192  0
             throw new IllegalArgumentException(CoreMessages.connectorSchemeIncompatibleWithEndpointScheme(
 193  
                 connector.getProtocol(), endpointURI).getMessage());
 194  
         }
 195  
 
 196  418
         List transformers = getOutboundTransformers(connector, endpointURI);
 197  418
         List responseTransformers = getOutboundEndpointResponseTransformers(connector, endpointURI);
 198  
 
 199  418
         boolean remoteSync = getRemoteSync(connector);
 200  
         boolean synchronous;
 201  418
         if (remoteSync)
 202  
         {
 203  0
             synchronous = true;
 204  
         }
 205  
         else
 206  
         {
 207  418
             synchronous = getSynchronous(connector, endpointURI);
 208  
         }
 209  
 
 210  418
         return new DefaultOutboundEndpoint(connector, endpointURI, transformers, responseTransformers,
 211  
             getName(endpointURI), getProperties(), getTransactionConfig(), getFilter(connector),
 212  
             getDefaultDeleteUnacceptedMessages(connector), getSecurityFilter(), synchronous, remoteSync,
 213  
             getRemoteSyncTimeout(connector), getInitialState(connector), getEndpointEncoding(connector), muleContext,
 214  
             getConnectionStrategy(connector));
 215  
 
 216  
     }
 217  
 
 218  
     protected boolean getSynchronous(Connector connector, EndpointURI endpointURI)
 219  
     {
 220  486
         return synchronous != null ? synchronous.booleanValue() : getDefaultSynchronous(connector,
 221  
             endpointURI.getScheme());
 222  
     }
 223  
 
 224  
     protected boolean getDefaultSynchronous(Connector connector, String protocol)
 225  
     {
 226  480
         if (connector != null && connector.isSyncEnabled(protocol))
 227  
         {
 228  0
             return true;
 229  
         }
 230  
         else
 231  
         {
 232  480
             return muleContext.getConfiguration().isDefaultSynchronousEndpoints();
 233  
         }
 234  
     }
 235  
 
 236  
     protected ConnectionStrategy getConnectionStrategy(Connector connector)
 237  
     {
 238  486
         return connectionStrategy != null ? connectionStrategy : getDefaultConnectionStrategy(connector);
 239  
     }
 240  
 
 241  
     protected ConnectionStrategy getDefaultConnectionStrategy(Connector connector)
 242  
     {
 243  486
         return muleContext.getDefaultConnectionStrategy();
 244  
     }
 245  
 
 246  
     protected TransactionConfig getTransactionConfig()
 247  
     {
 248  486
         return transactionConfig != null ? transactionConfig : getDefaultTransactionConfig();
 249  
     }
 250  
 
 251  
     protected TransactionConfig getDefaultTransactionConfig()
 252  
     {
 253  
         // TODO Do we need a new instance per endpoint, or can a single instance be
 254  
         // shared?
 255  486
         return new MuleTransactionConfig();
 256  
     }
 257  
 
 258  
     protected EndpointSecurityFilter getSecurityFilter()
 259  
     {
 260  486
         return securityFilter != null ? securityFilter : getDefaultSecurityFilter();
 261  
     }
 262  
 
 263  
     protected EndpointSecurityFilter getDefaultSecurityFilter()
 264  
     {
 265  486
         return null;
 266  
     }
 267  
 
 268  
     protected Connector getConnector() throws EndpointException
 269  
     {
 270  486
         return connector != null ? connector : getDefaultConnector();
 271  
     }
 272  
 
 273  
     protected Connector getDefaultConnector() throws EndpointException
 274  
     {
 275  52
         return getConnector(uriBuilder.getEndpoint(), muleContext);
 276  
     }
 277  
 
 278  
     protected String getName(EndpointURI endpointURI)
 279  
     {
 280  486
         return name != null ? name : ObjectNameHelper.getEndpointName(endpointURI);
 281  
     }
 282  
 
 283  
     protected Map getProperties()
 284  
     {
 285  
         // Add properties from builder, endpointURI and then seal (make unmodifiable)
 286  974
         LinkedList maps = new LinkedList();
 287  
         // properties from url come first
 288  974
         if (null != uriBuilder)
 289  
         {
 290  
             // properties from the URI itself
 291  974
             maps.addLast(uriBuilder.getEndpoint().getParams());
 292  
         }
 293  
         // properties on builder may override url
 294  972
         if (properties != null)
 295  
         {
 296  972
             maps.addLast(properties);
 297  
         }
 298  972
         MapCombiner combiner = new MapCombiner();
 299  972
         combiner.setList(maps);
 300  972
         return Collections.unmodifiableMap(combiner);
 301  
     }
 302  
 
 303  
     protected boolean getRemoteSync(Connector connector)
 304  
     {
 305  486
         return remoteSync != null ? remoteSync.booleanValue() : getDefaultRemoteSync(connector);
 306  
     }
 307  
 
 308  
     protected boolean getDefaultRemoteSync(Connector connector)
 309  
     {
 310  486
         return muleContext.getConfiguration().isDefaultRemoteSync();
 311  
     }
 312  
 
 313  
     protected boolean getDeleteUnacceptedMessages(Connector connector)
 314  
     {
 315  0
         return deleteUnacceptedMessages != null
 316  
                                                ? deleteUnacceptedMessages.booleanValue()
 317  
                                                : getDefaultDeleteUnacceptedMessages(connector);
 318  
 
 319  
     }
 320  
 
 321  
     protected boolean getDefaultDeleteUnacceptedMessages(Connector connector)
 322  
     {
 323  486
         return false;
 324  
     }
 325  
 
 326  
     protected String getEndpointEncoding(Connector connector)
 327  
     {
 328  486
         return encoding != null ? encoding : getDefaultEndpointEncoding(connector);
 329  
     }
 330  
 
 331  
     protected String getDefaultEndpointEncoding(Connector connector)
 332  
     {
 333  486
         if (muleContext != null)
 334  
         {
 335  486
             return muleContext.getConfiguration().getDefaultEncoding();
 336  
         }
 337  
         else
 338  
         {
 339  0
             return CharSetUtils.defaultCharsetName();
 340  
         }
 341  
     }
 342  
 
 343  
     protected Filter getFilter(Connector connector)
 344  
     {
 345  486
         return filter != null ? filter : getDefaultFilter(connector);
 346  
 
 347  
     }
 348  
 
 349  
     protected Filter getDefaultFilter(Connector connector)
 350  
     {
 351  480
         return null;
 352  
     }
 353  
 
 354  
     protected String getInitialState(Connector connector)
 355  
     {
 356  486
         return initialState != null ? initialState : getDefaultInitialState(connector);
 357  
 
 358  
     }
 359  
 
 360  
     protected String getDefaultInitialState(Connector connector)
 361  
     {
 362  0
         return ImmutableEndpoint.INITIAL_STATE_STARTED;
 363  
     }
 364  
 
 365  
     protected int getRemoteSyncTimeout(Connector connector)
 366  
     {
 367  486
         return remoteSyncTimeout != null ? remoteSyncTimeout.intValue() : getDefaultRemoteSyncTimeout(connector);
 368  
 
 369  
     }
 370  
 
 371  
     protected int getDefaultRemoteSyncTimeout(Connector connector)
 372  
     {
 373  480
         return muleContext.getConfiguration().getDefaultSynchronousEventTimeout();
 374  
     }
 375  
 
 376  
     protected List getInboundTransformers(Connector connector, EndpointURI endpointURI)
 377  
         throws TransportFactoryException
 378  
     {
 379  
         // #1 Transformers set on builder
 380  68
         if (transformers != null)
 381  
         {
 382  0
             return transformers;
 383  
         }
 384  
 
 385  
         // #2 Transformer specified on uri
 386  68
         List transformers = getTransformersFromString(endpointURI.getTransformers());
 387  68
         if (transformers != null)
 388  
         {
 389  0
             return transformers;
 390  
         }
 391  
 
 392  
         // #3 Default Transformer
 393  68
         return getDefaultInboundTransformers(connector);
 394  
     }
 395  
 
 396  
     protected List getDefaultInboundTransformers(Connector connector) throws TransportFactoryException
 397  
     {
 398  
         try
 399  
         {
 400  68
             return TransformerUtils.getDefaultInboundTransformers(getNonNullServiceDescriptor(uriBuilder.getEndpoint()
 401  
                 .getSchemeMetaInfo(), getOverrides(connector)));
 402  
         }
 403  0
         catch (Exception e)
 404  
         {
 405  0
             throw new TransportFactoryException(e);
 406  
         }
 407  
     }
 408  
 
 409  
     protected List getOutboundTransformers(Connector connector, EndpointURI endpointURI)
 410  
         throws TransportFactoryException
 411  
     {
 412  
         // #1 Transformers set on builder
 413  418
         if (transformers != null)
 414  
         {
 415  4
             return transformers;
 416  
         }
 417  
 
 418  
         // #2 Transformer specified on uri
 419  414
         List transformers = getTransformersFromString(endpointURI.getTransformers());
 420  414
         if (transformers != null)
 421  
         {
 422  0
             return transformers;
 423  
         }
 424  
 
 425  
         // #3 Default Transformer
 426  414
         return getDefaultOutboundTransformers(connector);
 427  
     }
 428  
 
 429  
     protected List getDefaultOutboundTransformers(Connector connector) throws TransportFactoryException
 430  
     {
 431  
         try
 432  
         {
 433  414
             return TransformerUtils.getDefaultOutboundTransformers(getNonNullServiceDescriptor(uriBuilder.getEndpoint()
 434  
                 .getSchemeMetaInfo(), getOverrides(connector)));
 435  
         }
 436  0
         catch (Exception e)
 437  
         {
 438  0
             throw new TransportFactoryException(e);
 439  
         }
 440  
     }
 441  
 
 442  
     protected List getInboundEndpointResponseTransformers(Connector connector, EndpointURI endpointURI)
 443  
         throws TransportFactoryException
 444  
     {
 445  
         // #1 Transformers set on builder
 446  68
         if (responseTransformers != null)
 447  
         {
 448  0
             return responseTransformers;
 449  
         }
 450  
 
 451  
         // #2 Transformer specified on uri
 452  68
         List transformers = getTransformersFromString(endpointURI.getResponseTransformers());
 453  68
         if (transformers != null)
 454  
         {
 455  0
             return transformers;
 456  
         }
 457  
 
 458  
         // #3 Default Connector Response Transformer
 459  68
         return getDefaultResponseTransformers(connector);
 460  
     }
 461  
 
 462  
     protected List getOutboundEndpointResponseTransformers(Connector connector, EndpointURI endpointURI)
 463  
         throws TransportFactoryException
 464  
     {
 465  
         // #1 Transformers set on builder
 466  418
         if (responseTransformers != null)
 467  
         {
 468  0
             return responseTransformers;
 469  
         }
 470  
 
 471  
         // #2 Transformer specified on uri
 472  418
         List transformers = getTransformersFromString(endpointURI.getResponseTransformers());
 473  418
         if (transformers != null)
 474  
         {
 475  0
             return transformers;
 476  
         }
 477  418
         return Collections.EMPTY_LIST;
 478  
     }
 479  
 
 480  
     protected List getDefaultResponseTransformers(Connector connector) throws TransportFactoryException
 481  
     {
 482  
         try
 483  
         {
 484  68
             return TransformerUtils.getDefaultResponseTransformers(getNonNullServiceDescriptor(uriBuilder.getEndpoint()
 485  
                 .getSchemeMetaInfo(), getOverrides(connector)));
 486  
         }
 487  0
         catch (Exception e)
 488  
         {
 489  0
             throw new TransportFactoryException(e);
 490  
         }
 491  
     }
 492  
 
 493  
     private List getTransformersFromString(String transformers) throws TransportFactoryException
 494  
     {
 495  
         try
 496  
         {
 497  968
             return TransformerUtils.getTransformers(transformers);
 498  
         }
 499  0
         catch (DefaultMuleException e)
 500  
         {
 501  0
             throw new TransportFactoryException(e);
 502  
         }
 503  
     }
 504  
 
 505  
     private Properties getOverrides(Connector connector)
 506  
     {
 507  
         // Get connector specific overrides to set on the descriptor
 508  550
         Properties overrides = new Properties();
 509  550
         if (connector instanceof AbstractConnector)
 510  
         {
 511  550
             Map so = ((AbstractConnector) connector).getServiceOverrides();
 512  550
             if (so != null)
 513  
             {
 514  0
                 overrides.putAll(so);
 515  
             }
 516  
         }
 517  550
         return overrides;
 518  
     }
 519  
 
 520  
     private TransportServiceDescriptor getNonNullServiceDescriptor(String scheme, Properties overrides)
 521  
         throws ServiceException
 522  
     {
 523  550
         TransportServiceDescriptor sd = (TransportServiceDescriptor) RegistryContext.getRegistry()
 524  
             .lookupServiceDescriptor(ServiceDescriptorFactory.PROVIDER_SERVICE_TYPE, scheme, overrides);
 525  550
         if (null != sd)
 526  
         {
 527  550
             return sd;
 528  
         }
 529  
         else
 530  
         {
 531  0
             throw new ServiceException(CoreMessages.noServiceTransportDescriptor(scheme));
 532  
         }
 533  
     }
 534  
 
 535  
     private Connector getConnector(EndpointURI endpointURI, MuleContext muleContext) throws EndpointException
 536  
     {
 537  52
         String scheme = uriBuilder.getEndpoint().getFullScheme();
 538  
         Connector connector;
 539  
         try
 540  
         {
 541  52
             if (uriBuilder.getEndpoint().getConnectorName() != null)
 542  
             {
 543  8
                 connector = muleContext.getRegistry().lookupConnector(uriBuilder.getEndpoint().getConnectorName());
 544  8
                 if (connector == null)
 545  
                 {
 546  0
                     throw new TransportFactoryException(CoreMessages.objectNotRegistered("Connector",
 547  
                         uriBuilder.getEndpoint().getConnectorName()));
 548  
                 }
 549  
             }
 550  
             else
 551  
             {
 552  44
                 connector = TransportFactory.getConnectorByProtocol(scheme);
 553  44
                 if (connector == null)
 554  
                 {
 555  34
                     connector = TransportFactory.createConnector(endpointURI, muleContext);
 556  34
                     muleContext.getRegistry().registerConnector(connector);
 557  
                 }
 558  
             }
 559  
         }
 560  0
         catch (Exception e)
 561  
         {
 562  0
             throw new TransportFactoryException(e);
 563  52
         }
 564  
 
 565  52
         if (connector == null)
 566  
         {
 567  0
             Message m = CoreMessages.failedToCreateObjectWith("Endpoint", "endpointURI: " + endpointURI);
 568  0
             m.setNextMessage(CoreMessages.objectIsNull("connector"));
 569  0
             throw new TransportFactoryException(m);
 570  
 
 571  
         }
 572  52
         return connector;
 573  
     }
 574  
 
 575  
     // Builder setters
 576  
 
 577  
     public void setConnector(Connector connector)
 578  
     {
 579  436
         this.connector = connector;
 580  
 
 581  436
     }
 582  
 
 583  
     public void addTransformer(Transformer transformer)
 584  
     {
 585  0
         if (transformers == null)
 586  
         {
 587  0
             transformers = new LinkedList();
 588  
         }
 589  0
         transformers.add(transformer);
 590  0
     }
 591  
 
 592  
     public void setTransformers(List transformers)
 593  
     {
 594  8
         this.transformers = transformers;
 595  8
     }
 596  
 
 597  
     public void setResponseTransformers(List responseTransformers)
 598  
     {
 599  4
         this.responseTransformers = responseTransformers;
 600  4
     }
 601  
 
 602  
     public void setName(String name)
 603  
     {
 604  432
         this.name = name;
 605  432
     }
 606  
 
 607  
     /**
 608  
      * NOTE - this appends properties.
 609  
      */
 610  
     public void setProperties(Map properties)
 611  
     {
 612  4
         if (null == this.properties)
 613  
         {
 614  0
             this.properties = new HashMap();
 615  
         }
 616  4
         this.properties.putAll(properties);
 617  4
     }
 618  
 
 619  
     /**
 620  
      * Sets a property on the endpoint
 621  
      * 
 622  
      * @param key the property key
 623  
      * @param value the value of the property
 624  
      */
 625  
     public void setProperty(Object key, Object value)
 626  
     {
 627  0
         properties.put(key, value);
 628  0
     }
 629  
 
 630  
     public void setTransactionConfig(TransactionConfig transactionConfig)
 631  
     {
 632  4
         this.transactionConfig = transactionConfig;
 633  
 
 634  4
     }
 635  
 
 636  
     public void setFilter(Filter filter)
 637  
     {
 638  432
         this.filter = filter;
 639  
 
 640  432
     }
 641  
 
 642  
     public void setDeleteUnacceptedMessages(boolean deleteUnacceptedMessages)
 643  
     {
 644  0
         this.deleteUnacceptedMessages = Boolean.valueOf(deleteUnacceptedMessages);
 645  
 
 646  0
     }
 647  
 
 648  
     public void setSecurityFilter(EndpointSecurityFilter securityFilter)
 649  
     {
 650  4
         this.securityFilter = securityFilter;
 651  
 
 652  4
     }
 653  
 
 654  
     public void setSynchronous(boolean synchronous)
 655  
     {
 656  4
         this.synchronous = Boolean.valueOf(synchronous);
 657  
 
 658  4
     }
 659  
 
 660  
     public void setRemoteSync(boolean remoteSync)
 661  
     {
 662  0
         this.remoteSync = Boolean.valueOf(remoteSync);
 663  
 
 664  0
     }
 665  
 
 666  
     public void setRemoteSyncTimeout(int remoteSyncTimeout)
 667  
     {
 668  4
         this.remoteSyncTimeout = new Integer(remoteSyncTimeout);
 669  
 
 670  4
     }
 671  
 
 672  
     public void setInitialState(String initialState)
 673  
     {
 674  4
         this.initialState = initialState;
 675  
 
 676  4
     }
 677  
 
 678  
     public void setEncoding(String encoding)
 679  
     {
 680  4
         this.encoding = encoding;
 681  
 
 682  4
     }
 683  
 
 684  
     public void setCreateConnector(int createConnector)
 685  
     {
 686  0
         this.createConnector = new Integer(createConnector);
 687  0
     }
 688  
 
 689  
     public void setRegistryId(String registryId)
 690  
     {
 691  4
         this.registryId = registryId;
 692  
 
 693  4
     }
 694  
 
 695  
     public void setMuleContext(MuleContext muleContext)
 696  
     {
 697  18
         this.muleContext = muleContext;
 698  
 
 699  18
     }
 700  
 
 701  
     public void setConnectionStrategy(ConnectionStrategy connectionStrategy)
 702  
     {
 703  4
         this.connectionStrategy = connectionStrategy;
 704  
 
 705  4
     }
 706  
 
 707  
     public URIBuilder getEndpointBuilder()
 708  
     {
 709  0
         return uriBuilder;
 710  
     }
 711  
 
 712  
     public void setURIBuilder(URIBuilder URIBuilder)
 713  
     {
 714  4
         this.uriBuilder = URIBuilder;
 715  
 
 716  4
     }
 717  
 
 718  
     // TODO Equals() and hashCode() only needed for tests, move to tests
 719  
     public int hashCode()
 720  
     {
 721  32
         return ClassUtils.hash(new Object[]{connectionStrategy, connector, createConnector, deleteUnacceptedMessages,
 722  
             encoding, uriBuilder, filter, initialState, name, properties, remoteSync, remoteSyncTimeout,
 723  
             responseTransformers, securityFilter, synchronous, transactionConfig, transformers});
 724  
     }
 725  
 
 726  
     // TODO Equals() and hashCode() only needed for tests, move to tests
 727  
     public boolean equals(Object obj)
 728  
     {
 729  6
         if (this == obj) return true;
 730  6
         if (obj == null || getClass() != obj.getClass()) return false;
 731  
 
 732  6
         final AbstractEndpointBuilder other = (AbstractEndpointBuilder) obj;
 733  6
         return equal(connectionStrategy, other.connectionStrategy) && equal(connector, other.connector)
 734  
                && equal(createConnector, other.createConnector)
 735  
                && equal(deleteUnacceptedMessages, other.deleteUnacceptedMessages) && equal(encoding, other.encoding)
 736  
                && equal(uriBuilder, other.uriBuilder) && equal(filter, other.filter)
 737  
                && equal(initialState, other.initialState) && equal(name, other.name)
 738  
                && equal(properties, other.properties) && equal(remoteSync, other.remoteSync)
 739  
                && equal(remoteSyncTimeout, other.remoteSyncTimeout)
 740  
                && equal(responseTransformers, other.responseTransformers)
 741  
                && equal(securityFilter, other.securityFilter) && equal(synchronous, other.synchronous)
 742  
                && equal(transactionConfig, other.transactionConfig) && equal(transformers, other.transformers);
 743  
     }
 744  
 
 745  
     protected static boolean equal(Object a, Object b)
 746  
     {
 747  102
         return ClassUtils.equal(a, b);
 748  
     }
 749  
 
 750  
     public Object clone() throws CloneNotSupportedException
 751  
     {
 752  4
         EndpointBuilder builder = (EndpointBuilder) super.clone();
 753  4
         builder.setConnector(connector);
 754  4
         builder.setURIBuilder(uriBuilder);
 755  4
         builder.setTransformers(transformers);
 756  4
         builder.setResponseTransformers(responseTransformers);
 757  4
         builder.setName(name);
 758  4
         builder.setProperties(properties);
 759  4
         builder.setTransactionConfig(transactionConfig);
 760  4
         builder.setFilter(filter);
 761  4
         builder.setSecurityFilter(securityFilter);
 762  4
         builder.setInitialState(initialState);
 763  4
         builder.setEncoding(encoding);
 764  4
         builder.setRegistryId(registryId);
 765  4
         builder.setMuleContext(muleContext);
 766  4
         builder.setConnectionStrategy(connectionStrategy);
 767  
 
 768  4
         if (deleteUnacceptedMessages != null)
 769  
         {
 770  0
             builder.setDeleteUnacceptedMessages(deleteUnacceptedMessages.booleanValue());
 771  
         }
 772  4
         if (synchronous != null)
 773  
         {
 774  0
             builder.setSynchronous(synchronous.booleanValue());
 775  
         }
 776  4
         if (remoteSync != null)
 777  
         {
 778  0
             builder.setRemoteSync(remoteSync.booleanValue());
 779  
         }
 780  4
         if (remoteSyncTimeout != null)
 781  
         {
 782  0
             builder.setRemoteSyncTimeout(remoteSyncTimeout.intValue());
 783  
         }
 784  
 
 785  4
         return builder;
 786  
     }
 787  
 
 788  
 }