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.LinkedHashSet; |
19 | |
import java.util.Set; |
20 | |
import java.util.concurrent.CopyOnWriteArraySet; |
21 | |
|
22 | |
import org.apache.commons.logging.Log; |
23 | |
import org.apache.commons.logging.LogFactory; |
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | 0 | public class DefaultEntryPointResolverSet implements EntryPointResolverSet |
33 | |
{ |
34 | 0 | protected final Log logger = LogFactory.getLog(getClass()); |
35 | |
|
36 | 0 | private final Set<EntryPointResolver> entryPointResolvers = new LinkedHashSet<EntryPointResolver>(4); |
37 | 0 | private final Set<String> exceptions = new CopyOnWriteArraySet<String>(); |
38 | |
|
39 | |
public Object invoke(Object component, MuleEventContext context) throws Exception |
40 | |
{ |
41 | |
try |
42 | |
{ |
43 | 0 | for (EntryPointResolver resolver : entryPointResolvers) |
44 | |
{ |
45 | 0 | InvocationResult result = resolver.invoke(component, context); |
46 | 0 | if (result.getState() == InvocationResult.State.SUCCESSFUL) |
47 | |
{ |
48 | 0 | return result.getResult(); |
49 | |
} |
50 | |
else |
51 | |
{ |
52 | 0 | if (result.hasError()) |
53 | |
{ |
54 | 0 | exceptions.add(result.getErrorMessage()); |
55 | |
} |
56 | |
} |
57 | 0 | } |
58 | 0 | throw new EntryPointNotFoundException(CollectionUtils.toString(exceptions, true)); |
59 | |
} |
60 | |
finally |
61 | |
{ |
62 | 0 | exceptions.clear(); |
63 | |
} |
64 | |
|
65 | |
} |
66 | |
|
67 | |
public Set<EntryPointResolver> getEntryPointResolvers() |
68 | |
{ |
69 | 0 | return entryPointResolvers; |
70 | |
} |
71 | |
|
72 | |
public void setEntryPointResolvers(Set<EntryPointResolver> entryPointResolvers) |
73 | |
{ |
74 | 0 | this.entryPointResolvers.clear(); |
75 | 0 | this.entryPointResolvers.addAll(entryPointResolvers); |
76 | 0 | } |
77 | |
|
78 | |
public void addEntryPointResolver(EntryPointResolver resolver) |
79 | |
{ |
80 | 0 | synchronized (entryPointResolvers) |
81 | |
{ |
82 | 0 | this.entryPointResolvers.add(resolver); |
83 | 0 | } |
84 | 0 | } |
85 | |
|
86 | |
public boolean removeEntryPointResolver(EntryPointResolver resolver) |
87 | |
{ |
88 | 0 | return this.entryPointResolvers.remove(resolver); |
89 | |
} |
90 | |
} |