Coverage Report - org.mule.impl.endpoint.MuleEndpoint
 
Classes in this File Line Coverage Branch Coverage Complexity
MuleEndpoint
69%
63/91
53%
19/36
1.692
 
 1  
 /*
 2  
  * $Id: MuleEndpoint.java 9554 2007-11-02 09:23:03Z marie.rizzo $
 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.impl.endpoint;
 12  
 
 13  
 import org.mule.config.i18n.CoreMessages;
 14  
 import org.mule.impl.ImmutableMuleEndpoint;
 15  
 import org.mule.providers.service.TransportFactory;
 16  
 import org.mule.umo.UMOException;
 17  
 import org.mule.umo.UMOFilter;
 18  
 import org.mule.umo.UMOTransactionConfig;
 19  
 import org.mule.umo.endpoint.EndpointException;
 20  
 import org.mule.umo.endpoint.UMOEndpoint;
 21  
 import org.mule.umo.endpoint.UMOEndpointURI;
 22  
 import org.mule.umo.endpoint.UMOImmutableEndpoint;
 23  
 import org.mule.umo.lifecycle.InitialisationException;
 24  
 import org.mule.umo.provider.UMOConnector;
 25  
 import org.mule.umo.security.UMOEndpointSecurityFilter;
 26  
 import org.mule.umo.transformer.UMOTransformer;
 27  
 
 28  
 import java.util.Map;
 29  
 
 30  
 /**
 31  
  * <code>MuleEndpoint</code> describes a Provider in the Mule Server. A endpoint is
 32  
  * a grouping of an endpoint, an endpointUri and a transformer.
 33  
  */
 34  
 public class MuleEndpoint extends ImmutableMuleEndpoint implements UMOEndpoint
 35  
 {
 36  
     public static final String ALWAYS_CREATE_STRING = "ALWAYS_CREATE";
 37  
     public static final String NEVER_CREATE_STRING = "NEVER_CREATE";
 38  
 
 39  
     /**
 40  
      * Default constructor This is required right now for the Mule digester to set
 41  
      * the properties through the classes mutators
 42  
      */
 43  
     public MuleEndpoint()
 44  
     {
 45  812
         super(null, null, null, null, ENDPOINT_TYPE_SENDER_AND_RECEIVER, 0, null, null);
 46  812
     }
 47  
 
 48  
     public MuleEndpoint(String name,
 49  
                         UMOEndpointURI endpointUri,
 50  
                         UMOConnector connector,
 51  
                         UMOTransformer transformer,
 52  
                         String type,
 53  
                         int createConnector,
 54  
                         String endpointEncoding,
 55  
                         Map props)
 56  
     {
 57  14
         super(name, endpointUri, connector, transformer, type, createConnector, endpointEncoding,
 58  
             props);
 59  14
     }
 60  
 
 61  
     public MuleEndpoint(UMOImmutableEndpoint endpoint)
 62  
     {
 63  2
         super(endpoint);
 64  2
     }
 65  
 
 66  
     public MuleEndpoint(String uri, boolean receiver) throws UMOException
 67  
     {
 68  38
         super(uri, receiver);
 69  38
     }
 70  
 
 71  
     public Object clone()
 72  
     {
 73  12
         UMOEndpoint clone = new MuleEndpoint(name, endpointUri, connector, transformer, type,
 74  
             createConnector, endpointEncoding, properties);
 75  
 
 76  12
         clone.setTransactionConfig(transactionConfig);
 77  12
         clone.setFilter(filter);
 78  12
         clone.setSecurityFilter(securityFilter);
 79  
         try
 80  
         {
 81  12
             if (responseTransformer != null)
 82  
             {
 83  2
                 clone.setResponseTransformer((UMOTransformer)responseTransformer.clone());
 84  
             }
 85  
         }
 86  0
         catch (CloneNotSupportedException e1)
 87  
         {
 88  
             // TODO throw exception instead of suppressing it
 89  0
             logger.error(e1.getMessage(), e1);
 90  12
         }
 91  
 
 92  12
         if (remoteSync != null)
 93  
         {
 94  8
             clone.setRemoteSync(isRemoteSync());
 95  
         }
 96  12
         if (remoteSyncTimeout != null)
 97  
         {
 98  0
             clone.setRemoteSyncTimeout(getRemoteSyncTimeout());
 99  
         }
 100  
 
 101  12
         if (synchronous != null)
 102  
         {
 103  8
             clone.setSynchronous(synchronous.booleanValue());
 104  
         }
 105  
 
 106  12
         clone.setDeleteUnacceptedMessages(deleteUnacceptedMessages);
 107  
 
 108  12
         clone.setInitialState(initialState);
 109  12
         if (initialised.get())
 110  
         {
 111  
             try
 112  
             {
 113  0
                 clone.initialise();
 114  
             }
 115  0
             catch (InitialisationException e)
 116  
             {
 117  
                 // this really should never happen as the endpoint is already
 118  
                 // initialised
 119  
                 // TODO Mule-863: Then die or be quiet!
 120  0
                 logger.error(e.getMessage(), e);
 121  0
             }
 122  
         }
 123  
         
 124  12
         if (streaming)
 125  
         {
 126  0
             clone.setStreaming(streaming);
 127  
         }
 128  
 
 129  12
         return clone;
 130  
     }
 131  
 
 132  
     public void setEndpointURI(UMOEndpointURI endpointUri) throws EndpointException
 133  
     {
 134  846
         if (connector != null && endpointUri != null
 135  
             && !connector.supportsProtocol(endpointUri.getFullScheme()))
 136  
         {
 137  0
             throw new IllegalArgumentException(
 138  
                 CoreMessages.connectorSchemeIncompatibleWithEndpointScheme(connector.getProtocol(),
 139  
                     endpointUri).getMessage());
 140  
         }
 141  846
         this.endpointUri = endpointUri;
 142  846
         if (endpointUri != null)
 143  
         {
 144  846
             properties.putAll(endpointUri.getParams());
 145  
         }
 146  846
     }
 147  
 
 148  
     public void setEncoding(String endpointEncoding)
 149  
     {
 150  0
         this.endpointEncoding = endpointEncoding;
 151  0
     }
 152  
 
 153  
     public void setType(String type)
 154  
     {
 155  1702
         this.type = type;
 156  1702
     }
 157  
 
 158  
     public void setConnector(UMOConnector connector)
 159  
     {
 160  806
         if (connector != null && endpointUri != null
 161  
             && !connector.supportsProtocol(endpointUri.getFullScheme()))
 162  
         {
 163  0
             throw new IllegalArgumentException(
 164  
                 CoreMessages.connectorSchemeIncompatibleWithEndpointScheme(connector.getProtocol(),
 165  
                     endpointUri).getMessage());
 166  
         }
 167  806
         this.connector = connector;
 168  806
     }
 169  
 
 170  
     public void setName(String name)
 171  
     {
 172  834
         this.name = name;
 173  834
     }
 174  
 
 175  
     public void setTransformer(UMOTransformer trans)
 176  
     {
 177  108
         transformer = trans;
 178  108
         if (transformer != null)
 179  
         {
 180  24
             transformer.setEndpoint(this);
 181  
         }
 182  108
     }
 183  
 
 184  
     public void setProperties(Map props)
 185  
     {
 186  4
         properties.clear();
 187  4
         properties.putAll(props);
 188  4
     }
 189  
 
 190  
     public boolean isReadOnly()
 191  
     {
 192  0
         return false;
 193  
     }
 194  
 
 195  
     public void setTransactionConfig(UMOTransactionConfig config)
 196  
     {
 197  12
         transactionConfig = config;
 198  12
     }
 199  
 
 200  
     public void setFilter(UMOFilter filter)
 201  
     {
 202  42
         this.filter = filter;
 203  42
     }
 204  
 
 205  
     /**
 206  
      * If a filter is configured on this endpoint, this property will determine if
 207  
      * message that are not excepted by the filter are deleted
 208  
      * 
 209  
      * @param delete if message should be deleted, false otherwise
 210  
      */
 211  
     public void setDeleteUnacceptedMessages(boolean delete)
 212  
     {
 213  12
         deleteUnacceptedMessages = delete;
 214  12
     }
 215  
 
 216  
     /**
 217  
      * Sets an UMOEndpointSecurityFilter for this endpoint. If a filter is set all
 218  
      * traffice via this endpoint with be subject to authentication.
 219  
      * 
 220  
      * @param filter the UMOSecurityFilter responsible for authenticating message
 221  
      *            flow via this endpoint.
 222  
      * @see org.mule.umo.security.UMOEndpointSecurityFilter
 223  
      */
 224  
     public void setSecurityFilter(UMOEndpointSecurityFilter filter)
 225  
     {
 226  12
         securityFilter = filter;
 227  12
         if (securityFilter != null)
 228  
         {
 229  0
             securityFilter.setEndpoint(this);
 230  
         }
 231  12
     }
 232  
 
 233  
     /**
 234  
      * Determines if requests originating from this endpoint should be synchronous
 235  
      * i.e. execute in a single thread and possibly return an result. This property
 236  
      * is only used when the endpoint is of type 'receiver'.
 237  
      * 
 238  
      * @param synchronous whether requests on this endpoint should execute in a
 239  
      *            single thread. This property is only used when the endpoint is of
 240  
      *            type 'receiver'
 241  
      */
 242  
     public void setSynchronous(boolean synchronous)
 243  
     {
 244  8
         this.synchronous = Boolean.valueOf(synchronous);
 245  8
     }
 246  
 
 247  
     public void setCreateConnector(int action)
 248  
     {
 249  0
         createConnector = action;
 250  0
     }
 251  
 
 252  
     public void setCreateConnectorAsString(String action)
 253  
     {
 254  0
         if (ALWAYS_CREATE_STRING.equals(action))
 255  
         {
 256  0
             createConnector = TransportFactory.ALWAYS_CREATE_CONNECTOR;
 257  
         }
 258  0
         else if (NEVER_CREATE_STRING.equals(action))
 259  
         {
 260  0
             createConnector = TransportFactory.NEVER_CREATE_CONNECTOR;
 261  
         }
 262  
         else
 263  
         {
 264  0
             createConnector = TransportFactory.GET_OR_CREATE_CONNECTOR;
 265  
         }
 266  0
     }
 267  
 
 268  
     /**
 269  
      * For certain providers that support the notion of a backchannel such as sockets
 270  
      * (outputStream) or Jms (ReplyTo) Mule can automatically wait for a response
 271  
      * from a backchannel when dispatching over these protocols. This is different
 272  
      * for synchronous as synchronous behavior only applies to in
 273  
      * 
 274  
      * @param value whether the endpoint should perfrom sync receives
 275  
      */
 276  
     public void setRemoteSync(boolean value)
 277  
     {
 278  48
         this.remoteSync = Boolean.valueOf(value);
 279  48
         if (value)
 280  
         {
 281  48
             this.synchronous = Boolean.TRUE;
 282  
         }
 283  48
     }
 284  
 
 285  
     /**
 286  
      * The timeout value for remoteSync invocations
 287  
      * 
 288  
      * @param timeout the timeout in milliseconds
 289  
      */
 290  
     public void setRemoteSyncTimeout(int timeout)
 291  
     {
 292  0
         this.remoteSyncTimeout = new Integer(timeout);
 293  0
     }
 294  
 
 295  
     /**
 296  
      * Sets the state the endpoint will be loaded in. The States are 'stopped' and
 297  
      * 'started' (default)
 298  
      * 
 299  
      * @param state
 300  
      */
 301  
     public void setInitialState(String state)
 302  
     {
 303  12
         this.initialState = state;
 304  12
     }
 305  
 
 306  
     public void setResponseTransformer(UMOTransformer trans)
 307  
     {
 308  54
         responseTransformer = trans;
 309  54
     }
 310  
 
 311  
     /**
 312  
      * Determines whether the endpoint should deal with requests as streams
 313  
      * 
 314  
      * @param stream true if the request should be streamed
 315  
      */
 316  
     public void setStreaming(boolean stream)
 317  
     {
 318  0
         this.streaming = stream;
 319  0
     }
 320  
 
 321  
     /**
 322  
      * Sets a property on the endpoint
 323  
      * 
 324  
      * @param key the property key
 325  
      * @param value the value of the property
 326  
      */
 327  
     public void setProperty(String key, Object value)
 328  
     {
 329  0
         properties.put(key, value);
 330  0
     }
 331  
 }