1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
package org.mule.model.resolvers; |
11 | |
|
12 | |
import org.mule.api.MuleEventContext; |
13 | |
import org.mule.api.model.EntryPointResolver; |
14 | |
import org.mule.api.model.EntryPointResolverSet; |
15 | |
import org.mule.api.model.InvocationResult; |
16 | |
import org.mule.util.CollectionUtils; |
17 | |
|
18 | |
import java.util.HashSet; |
19 | |
import java.util.LinkedHashSet; |
20 | |
import java.util.Set; |
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | 0 | public class DefaultEntryPointResolverSet implements EntryPointResolverSet |
30 | |
{ |
31 | 0 | private final Set<EntryPointResolver> entryPointResolvers = new LinkedHashSet<EntryPointResolver>(4); |
32 | |
|
33 | |
public Object invoke(Object component, MuleEventContext context) throws Exception |
34 | |
{ |
35 | 0 | Set<String> exceptions = new HashSet<String>(); |
36 | |
|
37 | 0 | for (EntryPointResolver resolver : entryPointResolvers) |
38 | |
{ |
39 | 0 | InvocationResult result = resolver.invoke(component, context); |
40 | 0 | if (result.getState() == InvocationResult.State.SUCCESSFUL) |
41 | |
{ |
42 | 0 | return result.getResult(); |
43 | |
} |
44 | |
else |
45 | |
{ |
46 | 0 | if (result.hasError()) |
47 | |
{ |
48 | 0 | exceptions.add(result.getErrorMessage()); |
49 | |
} |
50 | |
} |
51 | 0 | } |
52 | 0 | throw new EntryPointNotFoundException(CollectionUtils.toString(exceptions, true)); |
53 | |
} |
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
|
59 | |
public Set<EntryPointResolver> getEntryPointResolvers() |
60 | |
{ |
61 | 0 | return entryPointResolvers; |
62 | |
} |
63 | |
|
64 | |
public void setEntryPointResolvers(Set<EntryPointResolver> entryPointResolvers) |
65 | |
{ |
66 | 0 | synchronized (this.entryPointResolvers) |
67 | |
{ |
68 | 0 | this.entryPointResolvers.clear(); |
69 | 0 | this.entryPointResolvers.addAll(entryPointResolvers); |
70 | 0 | } |
71 | 0 | } |
72 | |
|
73 | |
public void addEntryPointResolver(EntryPointResolver resolver) |
74 | |
{ |
75 | 0 | synchronized (entryPointResolvers) |
76 | |
{ |
77 | 0 | this.entryPointResolvers.add(resolver); |
78 | 0 | } |
79 | 0 | } |
80 | |
|
81 | |
public boolean removeEntryPointResolver(EntryPointResolver resolver) |
82 | |
{ |
83 | 0 | synchronized (entryPointResolvers) |
84 | |
{ |
85 | 0 | return this.entryPointResolvers.remove(resolver); |
86 | 0 | } |
87 | |
} |
88 | |
} |