1
2
3
4
5
6
7
8
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
70 }
71
72 }