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.InboundEndpoint;
20 import org.mule.api.processor.MessageProcessor;
21 import org.mule.construct.AbstractFlowConstruct;
22
23 @SuppressWarnings("unchecked")
24 public abstract class AbstractFlowConstructWithSingleInboundEndpointBuilder<T extends AbstractFlowConstructBuilder, F extends AbstractFlowConstruct>
25 extends AbstractFlowConstructBuilder<T, F>
26 {
27 private InboundEndpoint inboundEndpoint;
28 private EndpointBuilder inboundEndpointBuilder;
29 private String inboundAddress;
30
31
32 protected List<MessageProcessor> inboundTransformers;
33 protected List<MessageProcessor> inboundResponseTransformers;
34
35 public T inboundEndpoint(InboundEndpoint inboundEndpoint)
36 {
37 this.inboundEndpoint = inboundEndpoint;
38 return (T) this;
39 }
40
41 public T inboundEndpoint(EndpointBuilder inboundEndpointBuilder)
42 {
43 this.inboundEndpointBuilder = inboundEndpointBuilder;
44 return (T) this;
45 }
46
47 public T inboundAddress(String inboundAddress)
48 {
49 this.inboundAddress = inboundAddress;
50 return (T) this;
51 }
52
53 protected InboundEndpoint getOrBuildInboundEndpoint(MuleContext muleContext) throws MuleException
54 {
55 if (inboundEndpoint != null)
56 {
57 return inboundEndpoint;
58 }
59
60 if (inboundEndpointBuilder == null)
61 {
62 inboundEndpointBuilder = muleContext.getRegistry().lookupEndpointFactory().getEndpointBuilder(
63 inboundAddress);
64 }
65
66 inboundEndpointBuilder.setExchangePattern(getInboundMessageExchangePattern());
67
68 if (inboundTransformers != null)
69 {
70 inboundEndpointBuilder.setMessageProcessors(inboundTransformers);
71 }
72
73 if (inboundResponseTransformers != null)
74 {
75 inboundEndpointBuilder.setResponseMessageProcessors(inboundResponseTransformers);
76 }
77
78 doConfigureInboundEndpointBuilder(muleContext, inboundEndpointBuilder);
79
80 return inboundEndpointBuilder.buildInboundEndpoint();
81 }
82
83 protected abstract MessageExchangePattern getInboundMessageExchangePattern();
84
85 protected void doConfigureInboundEndpointBuilder(MuleContext muleContext, EndpointBuilder endpointBuilder)
86 {
87
88 }
89 }