View Javadoc

1   /*
2    * $Id: AbstractFlowConstructWithSingleInboundAndOutboundEndpointBuilder.java 21683 2011-04-14 22:07:56Z ddossot $
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.construct.builder;
12  
13  import org.mule.MessageExchangePattern;
14  import org.mule.api.MuleContext;
15  import org.mule.api.MuleException;
16  import org.mule.api.endpoint.EndpointBuilder;
17  import org.mule.api.endpoint.OutboundEndpoint;
18  import org.mule.construct.AbstractFlowConstruct;
19  
20  @SuppressWarnings("unchecked")
21  public abstract class AbstractFlowConstructWithSingleInboundAndOutboundEndpointBuilder<T extends AbstractFlowConstructBuilder<?, ?>, F extends AbstractFlowConstruct>
22      extends AbstractFlowConstructWithSingleInboundEndpointBuilder<T, F>
23  {
24      private OutboundEndpoint outboundEndpoint;
25      private EndpointBuilder outboundEndpointBuilder;
26      private String outboundAddress;
27  
28      public T outboundEndpoint(OutboundEndpoint outboundEndpoint)
29      {
30          this.outboundEndpoint = outboundEndpoint;
31          return (T) this;
32      }
33  
34      public T outboundEndpoint(EndpointBuilder outboundEndpointBuilder)
35      {
36          this.outboundEndpointBuilder = outboundEndpointBuilder;
37          return (T) this;
38      }
39  
40      public T outboundAddress(String outboundAddress)
41      {
42          this.outboundAddress = outboundAddress;
43          return (T) this;
44      }
45  
46      protected OutboundEndpoint getOrBuildOutboundEndpoint(MuleContext muleContext) throws MuleException
47      {
48          if (outboundEndpoint != null)
49          {
50              return outboundEndpoint;
51          }
52  
53          if (outboundEndpointBuilder == null)
54          {
55              outboundEndpointBuilder = muleContext.getEndpointFactory().getEndpointBuilder(outboundAddress);
56          }
57  
58          outboundEndpointBuilder.setExchangePattern(getOutboundMessageExchangePattern());
59  
60          doConfigureOutboundEndpointBuilder(muleContext, outboundEndpointBuilder);
61  
62          return outboundEndpointBuilder.buildOutboundEndpoint();
63      }
64  
65      protected abstract MessageExchangePattern getOutboundMessageExchangePattern();
66  
67      protected void doConfigureOutboundEndpointBuilder(MuleContext muleContext, EndpointBuilder endpointBuilder)
68      {
69          // template method
70      }
71  
72  }