1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.util; |
12 | |
|
13 | |
import org.mule.MuleException; |
14 | |
import org.mule.MuleManager; |
15 | |
import org.mule.config.i18n.CoreMessages; |
16 | |
import org.mule.impl.endpoint.MuleEndpoint; |
17 | |
import org.mule.routing.filters.EqualsFilter; |
18 | |
import org.mule.routing.filters.ObjectFilter; |
19 | |
import org.mule.routing.filters.WildcardFilter; |
20 | |
import org.mule.umo.endpoint.UMOEndpoint; |
21 | |
import org.mule.umo.endpoint.UMOImmutableEndpoint; |
22 | |
import org.mule.umo.manager.UMOManager; |
23 | |
import org.mule.umo.transformer.UMOTransformer; |
24 | |
|
25 | |
import java.util.Iterator; |
26 | |
import java.util.Map; |
27 | |
import java.util.StringTokenizer; |
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
public final class MuleObjectHelper |
35 | |
{ |
36 | |
|
37 | |
|
38 | |
private MuleObjectHelper () |
39 | 0 | { |
40 | |
|
41 | 0 | } |
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
public static UMOTransformer getTransformer(String list, String delim) throws MuleException |
53 | |
{ |
54 | 0 | StringTokenizer st = new StringTokenizer(list, delim); |
55 | 0 | UMOManager manager = MuleManager.getInstance(); |
56 | 0 | UMOTransformer currentTrans = null; |
57 | 0 | UMOTransformer returnTrans = null; |
58 | |
|
59 | 0 | while (st.hasMoreTokens()) |
60 | |
{ |
61 | 0 | String key = st.nextToken().trim(); |
62 | 0 | UMOTransformer tempTrans = manager.lookupTransformer(key); |
63 | |
|
64 | 0 | if (tempTrans == null) |
65 | |
{ |
66 | 0 | throw new MuleException( |
67 | |
CoreMessages.objectNotRegisteredWithManager("Transformer: " + key)); |
68 | |
} |
69 | |
|
70 | 0 | if (currentTrans == null) |
71 | |
{ |
72 | 0 | currentTrans = tempTrans; |
73 | 0 | returnTrans = tempTrans; |
74 | |
} |
75 | |
else |
76 | |
{ |
77 | 0 | currentTrans.setNextTransformer(tempTrans); |
78 | 0 | currentTrans = tempTrans; |
79 | |
} |
80 | |
} |
81 | |
|
82 | 0 | return returnTrans; |
83 | |
} |
84 | |
|
85 | |
public static UMOEndpoint getEndpointByProtocol(String protocol) |
86 | |
{ |
87 | |
UMOImmutableEndpoint iprovider; |
88 | 0 | Map endpoints = MuleManager.getInstance().getEndpoints(); |
89 | 0 | for (Iterator iterator = endpoints.values().iterator(); iterator.hasNext();) |
90 | |
{ |
91 | 0 | iprovider = (UMOImmutableEndpoint) iterator.next(); |
92 | 0 | if (iprovider.getProtocol().equals(protocol)) |
93 | |
{ |
94 | 0 | return new MuleEndpoint(iprovider); |
95 | |
} |
96 | |
} |
97 | 0 | return null; |
98 | |
} |
99 | |
|
100 | |
public static UMOEndpoint getEndpointByEndpointUri(String endpointUri, boolean wildcardMatch) |
101 | |
{ |
102 | |
ObjectFilter filter; |
103 | |
|
104 | 0 | if (wildcardMatch) |
105 | |
{ |
106 | 0 | filter = new WildcardFilter(endpointUri); |
107 | |
} |
108 | |
else |
109 | |
{ |
110 | 0 | filter = new EqualsFilter(endpointUri); |
111 | |
} |
112 | |
|
113 | |
UMOImmutableEndpoint iprovider; |
114 | 0 | Map endpoints = MuleManager.getInstance().getEndpoints(); |
115 | |
|
116 | 0 | for (Iterator iterator = endpoints.values().iterator(); iterator.hasNext();) |
117 | |
{ |
118 | 0 | iprovider = (UMOImmutableEndpoint) iterator.next(); |
119 | 0 | if (filter.accept(iprovider.getEndpointURI())) |
120 | |
{ |
121 | 0 | return new MuleEndpoint(iprovider); |
122 | |
} |
123 | |
} |
124 | |
|
125 | 0 | return null; |
126 | |
} |
127 | |
|
128 | |
} |