Coverage Report - org.mule.impl.endpoint.MuleEndpoint
 
Classes in this File Line Coverage Branch Coverage Complexity
MuleEndpoint
0%
0/89
0%
0/13
1.654
 
 1  
 /*
 2  
  * $Id: MuleEndpoint.java 7976 2007-08-21 14:26:13Z dirk.olmes $
 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  
     /**
 37  
      * Serial version
 38  
      */
 39  
     private static final long serialVersionUID = 2028442057178326047L;
 40  
 
 41  
     public static final String ALWAYS_CREATE_STRING = "ALWAYS_CREATE";
 42  
     public static final String NEVER_CREATE_STRING = "NEVER_CREATE";
 43  
 
 44  
     /**
 45  
      * Default constructor This is required right now for the Mule digester to set
 46  
      * the properties through the classes mutators
 47  
      */
 48  
     public MuleEndpoint()
 49  
     {
 50  0
         super(null, null, null, null, ENDPOINT_TYPE_SENDER_AND_RECEIVER, 0, null, null);
 51  0
     }
 52  
 
 53  
     public MuleEndpoint(String name,
 54  
                         UMOEndpointURI endpointUri,
 55  
                         UMOConnector connector,
 56  
                         UMOTransformer transformer,
 57  
                         String type,
 58  
                         int createConnector,
 59  
                         String endpointEncoding,
 60  
                         Map props)
 61  
     {
 62  0
         super(name, endpointUri, connector, transformer, type, createConnector, endpointEncoding,
 63  
             props);
 64  0
     }
 65  
 
 66  
     public MuleEndpoint(UMOImmutableEndpoint endpoint)
 67  
     {
 68  0
         super(endpoint);
 69  0
     }
 70  
 
 71  
     public MuleEndpoint(String uri, boolean receiver) throws UMOException
 72  
     {
 73  0
         super(uri, receiver);
 74  0
     }
 75  
 
 76  
     public Object clone()
 77  
     {
 78  0
         UMOEndpoint clone = new MuleEndpoint(name, endpointUri, connector, transformer, type,
 79  
             createConnector, endpointEncoding, properties);
 80  
 
 81  0
         clone.setTransactionConfig(transactionConfig);
 82  0
         clone.setFilter(filter);
 83  0
         clone.setSecurityFilter(securityFilter);
 84  
         try
 85  
         {
 86  0
             if (responseTransformer != null)
 87  
             {
 88  0
                 clone.setResponseTransformer((UMOTransformer)responseTransformer.clone());
 89  
             }
 90  
         }
 91  0
         catch (CloneNotSupportedException e1)
 92  
         {
 93  
             // TODO throw exception instead of suppressing it
 94  0
             logger.error(e1.getMessage(), e1);
 95  0
         }
 96  
 
 97  0
         if (remoteSync != null)
 98  
         {
 99  0
             clone.setRemoteSync(isRemoteSync());
 100  
         }
 101  0
         if (remoteSyncTimeout != null)
 102  
         {
 103  0
             clone.setRemoteSyncTimeout(getRemoteSyncTimeout());
 104  
         }
 105  
 
 106  0
         if (synchronous != null)
 107  
         {
 108  0
             clone.setSynchronous(synchronous.booleanValue());
 109  
         }
 110  
 
 111  0
         clone.setDeleteUnacceptedMessages(deleteUnacceptedMessages);
 112  
 
 113  0
         clone.setInitialState(initialState);
 114  0
         if (initialised.get())
 115  
         {
 116  
             try
 117  
             {
 118  0
                 clone.initialise();
 119  
             }
 120  0
             catch (InitialisationException e)
 121  
             {
 122  
                 // this really should never happen as the endpoint is already
 123  
                 // initialised
 124  
                 // TODO Mule-863: Then die or be quiet!
 125  0
                 logger.error(e.getMessage(), e);
 126  0
             }
 127  
         }
 128  
 
 129  0
         return clone;
 130  
     }
 131  
 
 132  
     public void setEndpointURI(UMOEndpointURI endpointUri) throws EndpointException
 133  
     {
 134  0
         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  0
         this.endpointUri = endpointUri;
 142  0
         if (endpointUri != null)
 143  
         {
 144  0
             properties.putAll(endpointUri.getParams());
 145  
         }
 146  0
     }
 147  
 
 148  
     public void setEncoding(String endpointEncoding)
 149  
     {
 150  0
         this.endpointEncoding = endpointEncoding;
 151  0
     }
 152  
 
 153  
     public void setType(String type)
 154  
     {
 155  0
         this.type = type;
 156  0
     }
 157  
 
 158  
     public void setConnector(UMOConnector connector)
 159  
     {
 160  0
         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  0
         this.connector = connector;
 168  0
     }
 169  
 
 170  
     public void setName(String name)
 171  
     {
 172  0
         this.name = name;
 173  0
     }
 174  
 
 175  
     public void setTransformer(UMOTransformer trans)
 176  
     {
 177  0
         transformer = trans;
 178  0
         if (transformer != null)
 179  
         {
 180  0
             transformer.setEndpoint(this);
 181  
         }
 182  0
     }
 183  
 
 184  
     public void setProperties(Map props)
 185  
     {
 186  0
         properties.clear();
 187  0
         properties.putAll(props);
 188  0
     }
 189  
 
 190  
     public boolean isReadOnly()
 191  
     {
 192  0
         return false;
 193  
     }
 194  
 
 195  
     public void setTransactionConfig(UMOTransactionConfig config)
 196  
     {
 197  0
         transactionConfig = config;
 198  0
     }
 199  
 
 200  
     public void setFilter(UMOFilter filter)
 201  
     {
 202  0
         this.filter = filter;
 203  0
     }
 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  0
         deleteUnacceptedMessages = delete;
 214  0
     }
 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  0
         securityFilter = filter;
 227  0
         if (securityFilter != null)
 228  
         {
 229  0
             securityFilter.setEndpoint(this);
 230  
         }
 231  0
     }
 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  0
         this.synchronous = Boolean.valueOf(synchronous);
 245  0
     }
 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  0
         this.remoteSync = Boolean.valueOf(value);
 279  0
         if (value)
 280  
         {
 281  0
             this.synchronous = Boolean.TRUE;
 282  
         }
 283  0
     }
 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  0
         this.initialState = state;
 304  0
     }
 305  
 
 306  
     public void setResponseTransformer(UMOTransformer trans)
 307  
     {
 308  0
         responseTransformer = trans;
 309  0
     }
 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  
 }