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