View Javadoc

1   /*
2    * $Id: OutboundEndpointFactoryBean.java 22826 2011-09-02 07:30:19Z 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.config.spring.factories;
12  
13  import org.mule.api.endpoint.EndpointBuilder;
14  import org.mule.api.endpoint.EndpointException;
15  import org.mule.api.endpoint.OutboundEndpoint;
16  import org.mule.api.registry.ServiceType;
17  import org.mule.endpoint.AbstractEndpoint;
18  import org.mule.endpoint.EndpointURIEndpointBuilder;
19  import org.mule.processor.AbstractRedeliveryPolicy;
20  import org.mule.transport.service.TransportServiceDescriptor;
21  
22  /**
23   * Spring FactoryBean used to create concrete instances of outbound endpoints
24   */
25  public class OutboundEndpointFactoryBean extends AbstractEndpointFactoryBean
26  {
27  
28      public OutboundEndpointFactoryBean(EndpointURIEndpointBuilder global) throws EndpointException
29      {
30          super(global);
31      }
32  
33      public OutboundEndpointFactoryBean()
34      {
35          super();
36      }
37      
38      public Class getObjectType()
39      {
40          return OutboundEndpoint.class;
41      }
42  
43      public Object doGetObject() throws Exception
44      {
45          // If this is a meta endpoint, then we can wrap it using the meta endpoint builder from the TransportServiceDescriptor
46          String scheme = getEndpointBuilder().getEndpoint().getFullScheme();
47          TransportServiceDescriptor tsd = (TransportServiceDescriptor) muleContext.getRegistry().lookupServiceDescriptor(ServiceType.TRANSPORT, scheme, null);
48          EndpointBuilder endpointBuilder = tsd.createEndpointBuilder(this);
49  
50          OutboundEndpoint outboundEndpoint = muleContext.getEndpointFactory().getOutboundEndpoint(endpointBuilder);
51          if (outboundEndpoint instanceof AbstractEndpoint)
52          {
53              AbstractEndpoint.class.cast(outboundEndpoint).setAnnotations(getAnnotations());
54          }
55          return outboundEndpoint;
56      }
57  
58      @Override
59      public void setRedeliveryPolicy(AbstractRedeliveryPolicy redeliveryPolicy)
60      {
61          throw new IllegalStateException("A redelivery policy cannot be specified for an outbound endpoint.");
62      }
63  }