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