1
2
3
4
5
6
7 package org.mule.construct.builder;
8
9 import java.util.List;
10
11 import org.mule.MessageExchangePattern;
12 import org.mule.api.MuleContext;
13 import org.mule.api.MuleException;
14 import org.mule.api.endpoint.EndpointBuilder;
15 import org.mule.api.endpoint.OutboundEndpoint;
16 import org.mule.api.processor.MessageProcessor;
17 import org.mule.construct.AbstractFlowConstruct;
18
19 @SuppressWarnings("unchecked")
20 public abstract class AbstractFlowConstructWithSingleInboundAndOutboundEndpointBuilder<T extends AbstractFlowConstructBuilder, F extends AbstractFlowConstruct>
21 extends AbstractFlowConstructWithSingleInboundEndpointBuilder<T, F>
22 {
23 private OutboundEndpoint outboundEndpoint;
24 private EndpointBuilder outboundEndpointBuilder;
25 private String outboundAddress;
26
27
28 protected List<MessageProcessor> outboundTransformers;
29 protected List<MessageProcessor> outboundResponseTransformers;
30
31 public T outboundEndpoint(OutboundEndpoint outboundEndpoint)
32 {
33 this.outboundEndpoint = outboundEndpoint;
34 return (T) this;
35 }
36
37 public T outboundEndpoint(EndpointBuilder outboundEndpointBuilder)
38 {
39 this.outboundEndpointBuilder = outboundEndpointBuilder;
40 return (T) this;
41 }
42
43 public T outboundAddress(String outboundAddress)
44 {
45 this.outboundAddress = outboundAddress;
46 return (T) this;
47 }
48
49 protected OutboundEndpoint getOrBuildOutboundEndpoint(MuleContext muleContext) throws MuleException
50 {
51 if (outboundEndpoint != null)
52 {
53 return outboundEndpoint;
54 }
55
56 if (outboundEndpointBuilder == null)
57 {
58 outboundEndpointBuilder = muleContext.getEndpointFactory().getEndpointBuilder(
59 outboundAddress);
60 }
61
62 outboundEndpointBuilder.setExchangePattern(getOutboundMessageExchangePattern());
63
64 if (outboundTransformers != null)
65 {
66 outboundEndpointBuilder.setMessageProcessors(outboundTransformers);
67 }
68
69 if (outboundResponseTransformers != null)
70 {
71 outboundEndpointBuilder.setResponseMessageProcessors(outboundResponseTransformers);
72 }
73
74 doConfigureOutboundEndpointBuilder(muleContext, outboundEndpointBuilder);
75
76 return outboundEndpointBuilder.buildOutboundEndpoint();
77 }
78
79 protected abstract MessageExchangePattern getOutboundMessageExchangePattern();
80
81 protected void doConfigureOutboundEndpointBuilder(MuleContext muleContext, EndpointBuilder endpointBuilder)
82 {
83
84 }
85
86 }