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