1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.construct.builder; |
12 | |
|
13 | |
import java.util.Arrays; |
14 | |
|
15 | |
import org.mule.MessageExchangePattern; |
16 | |
import org.mule.api.MuleContext; |
17 | |
import org.mule.api.MuleException; |
18 | |
import org.mule.api.component.Component; |
19 | |
import org.mule.api.component.JavaComponent; |
20 | |
import org.mule.api.lifecycle.Callable; |
21 | |
import org.mule.api.model.EntryPointResolverSet; |
22 | |
import org.mule.api.object.ObjectFactory; |
23 | |
import org.mule.api.processor.MessageProcessor; |
24 | |
import org.mule.api.transformer.Transformer; |
25 | |
import org.mule.component.DefaultJavaComponent; |
26 | |
import org.mule.component.SimpleCallableJavaComponent; |
27 | |
import org.mule.construct.SimpleService; |
28 | |
import org.mule.construct.SimpleService.Type; |
29 | |
import org.mule.model.resolvers.LegacyEntryPointResolverSet; |
30 | |
import org.mule.object.PrototypeObjectFactory; |
31 | |
import org.mule.object.SingletonObjectFactory; |
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | 0 | public class SimpleServiceBuilder extends |
37 | |
AbstractFlowConstructWithSingleInboundEndpointBuilder<SimpleServiceBuilder, SimpleService> |
38 | |
{ |
39 | 0 | protected Type type = SimpleService.Type.DIRECT; |
40 | |
protected Component component; |
41 | |
|
42 | |
@Override |
43 | |
protected MessageExchangePattern getInboundMessageExchangePattern() |
44 | |
{ |
45 | 0 | return MessageExchangePattern.REQUEST_RESPONSE; |
46 | |
} |
47 | |
|
48 | |
public SimpleServiceBuilder inboundTransformers(Transformer... transformers) |
49 | |
{ |
50 | 0 | this.inboundTransformers = Arrays.asList((MessageProcessor[]) transformers); |
51 | 0 | return this; |
52 | |
} |
53 | |
|
54 | |
public SimpleServiceBuilder inboundResponseTransformers(Transformer... responseTransformers) |
55 | |
{ |
56 | 0 | this.inboundResponseTransformers = Arrays.asList((MessageProcessor[]) responseTransformers); |
57 | 0 | return this; |
58 | |
} |
59 | |
|
60 | |
public SimpleServiceBuilder component(Class<?> componentClass) |
61 | |
{ |
62 | 0 | return component(new PrototypeObjectFactory(componentClass)); |
63 | |
} |
64 | |
|
65 | |
public SimpleServiceBuilder component(ObjectFactory objectFactory) |
66 | |
{ |
67 | 0 | return component(new DefaultJavaComponent(objectFactory)); |
68 | |
} |
69 | |
|
70 | |
public SimpleServiceBuilder component(Callable callable) |
71 | |
{ |
72 | 0 | return component(new SimpleCallableJavaComponent(callable)); |
73 | |
} |
74 | |
|
75 | |
public SimpleServiceBuilder component(Object o) |
76 | |
{ |
77 | 0 | return component(new SingletonObjectFactory(o)); |
78 | |
} |
79 | |
|
80 | |
public SimpleServiceBuilder type(Type type) |
81 | |
{ |
82 | 0 | this.type = type; |
83 | 0 | return this; |
84 | |
} |
85 | |
|
86 | |
public SimpleServiceBuilder component(Component component) |
87 | |
{ |
88 | 0 | if (component instanceof JavaComponent) |
89 | |
{ |
90 | 0 | final JavaComponent javaComponent = (JavaComponent) component; |
91 | |
|
92 | 0 | if (javaComponent.getEntryPointResolverSet() == null) |
93 | |
{ |
94 | 0 | javaComponent.setEntryPointResolverSet(createEntryPointResolverSet()); |
95 | |
} |
96 | |
} |
97 | |
|
98 | 0 | this.component = component; |
99 | 0 | return this; |
100 | |
} |
101 | |
|
102 | |
@Override |
103 | |
protected SimpleService buildFlowConstruct(MuleContext muleContext) throws MuleException |
104 | |
{ |
105 | 0 | return new SimpleService(name, muleContext, getOrBuildInboundEndpoint(muleContext), component, type); |
106 | |
} |
107 | |
|
108 | |
protected EntryPointResolverSet createEntryPointResolverSet() |
109 | |
{ |
110 | 0 | return new LegacyEntryPointResolverSet(); |
111 | |
} |
112 | |
} |