1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.construct.builder; |
12 | |
|
13 | |
import org.mule.api.MuleContext; |
14 | |
import org.mule.api.MuleException; |
15 | |
import org.mule.api.exception.MessagingExceptionHandler; |
16 | |
import org.mule.api.source.MessageSource; |
17 | |
import org.mule.construct.AbstractFlowConstruct; |
18 | |
|
19 | |
@SuppressWarnings("unchecked") |
20 | 0 | public abstract class AbstractFlowConstructBuilder<T extends AbstractFlowConstructBuilder, F extends AbstractFlowConstruct> |
21 | |
{ |
22 | |
protected String name; |
23 | |
protected MessageSource messageSource; |
24 | |
protected MessagingExceptionHandler exceptionListener; |
25 | |
|
26 | |
public T name(String name) |
27 | |
{ |
28 | 0 | this.name = name; |
29 | 0 | return (T) this; |
30 | |
} |
31 | |
|
32 | |
public T messageSource(MessageSource messageSource) |
33 | |
{ |
34 | 0 | this.messageSource = messageSource; |
35 | 0 | return (T) this; |
36 | |
} |
37 | |
|
38 | |
public T exceptionStrategy(MessagingExceptionHandler exceptionListener) |
39 | |
{ |
40 | 0 | this.exceptionListener = exceptionListener; |
41 | 0 | return (T) this; |
42 | |
} |
43 | |
|
44 | |
public F build(MuleContext muleContext) throws MuleException |
45 | |
{ |
46 | 0 | final F flowConstruct = buildFlowConstruct(muleContext); |
47 | 0 | addExceptionListener(flowConstruct); |
48 | 0 | return flowConstruct; |
49 | |
} |
50 | |
|
51 | |
public F buildAndRegister(MuleContext muleContext) throws MuleException |
52 | |
{ |
53 | 0 | final F flowConstruct = build(muleContext); |
54 | 0 | muleContext.getRegistry().registerObject(flowConstruct.getName(), flowConstruct); |
55 | 0 | return flowConstruct; |
56 | |
} |
57 | |
|
58 | |
protected abstract F buildFlowConstruct(MuleContext muleContext) throws MuleException; |
59 | |
|
60 | |
protected void addExceptionListener(AbstractFlowConstruct flowConstruct) |
61 | |
{ |
62 | 0 | if (exceptionListener != null) |
63 | |
{ |
64 | 0 | flowConstruct.setExceptionListener(exceptionListener); |
65 | |
} |
66 | 0 | } |
67 | |
} |