1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.tools.visualizer.components; |
12 | |
|
13 | |
import org.mule.tools.visualizer.config.GraphEnvironment; |
14 | |
|
15 | |
import com.oy.shared.lm.graph.GraphNode; |
16 | |
|
17 | |
import java.util.ArrayList; |
18 | |
import java.util.HashMap; |
19 | |
import java.util.Iterator; |
20 | |
import java.util.List; |
21 | |
import java.util.Map; |
22 | |
import java.util.StringTokenizer; |
23 | |
|
24 | |
public class EndpointRegistry |
25 | |
{ |
26 | |
|
27 | 8 | private Map endpoints = null; |
28 | |
private GraphEnvironment env; |
29 | |
|
30 | |
public EndpointRegistry(GraphEnvironment env) |
31 | 8 | { |
32 | 8 | this.env = env; |
33 | 8 | endpoints = new HashMap(); |
34 | 8 | } |
35 | |
|
36 | |
public GraphNode[] getVirtualEndpoint(String componentName) |
37 | |
{ |
38 | |
|
39 | 24 | List nodesList = new ArrayList(); |
40 | 24 | String mappedUri = env.getConfig().getMappings().getProperty(componentName); |
41 | 24 | if (mappedUri != null) |
42 | |
{ |
43 | 0 | StringTokenizer stringTokenizer = new StringTokenizer(mappedUri, ","); |
44 | 0 | while (stringTokenizer.hasMoreTokens()) |
45 | |
{ |
46 | 0 | String s = stringTokenizer.nextToken(); |
47 | 0 | env.log("Mapping virtual endpoint '" + s + "' for component '" + componentName + "'"); |
48 | 0 | GraphNode n = getEndpoint(s, componentName); |
49 | 0 | if (n != null) |
50 | |
{ |
51 | 0 | nodesList.add(n); |
52 | |
} |
53 | 0 | } |
54 | |
} |
55 | |
|
56 | |
GraphNode[] nodes; |
57 | 24 | if (nodesList.size() > 0) |
58 | |
{ |
59 | 0 | nodes = new GraphNode[nodesList.size()]; |
60 | 0 | nodes = (GraphNode[]) nodesList.toArray(nodes); |
61 | |
} |
62 | |
else |
63 | |
{ |
64 | 24 | nodes = new GraphNode[]{}; |
65 | |
} |
66 | 24 | return nodes; |
67 | |
} |
68 | |
|
69 | |
public GraphNode getEndpoint(String uri, String componentName) |
70 | |
{ |
71 | 16 | env.log("retrieving endpoint for " + uri + " / " + componentName); |
72 | 16 | GraphNode n = getEqualsMapping(uri, componentName); |
73 | 16 | if (n != null) |
74 | |
{ |
75 | 0 | env.log("found equals mapping: " + n.getId()); |
76 | |
} |
77 | |
else |
78 | |
{ |
79 | 16 | n = (GraphNode) endpoints.get(uri); |
80 | 16 | if (null != n) |
81 | |
{ |
82 | 4 | env.log("found direct match: " + n.getId()); |
83 | |
} |
84 | |
else |
85 | |
{ |
86 | 12 | for (Iterator iterator = endpoints.keySet().iterator(); iterator.hasNext();) |
87 | |
{ |
88 | 2 | String s = (String) iterator.next(); |
89 | 2 | if (s.startsWith(uri + "/" + componentName)) |
90 | |
{ |
91 | 0 | n = (GraphNode) endpoints.get(s); |
92 | 0 | env.log("found prefix: " + n.getId() +"; " + s); |
93 | |
} |
94 | 2 | } |
95 | |
} |
96 | |
} |
97 | |
|
98 | 16 | return n; |
99 | |
} |
100 | |
|
101 | |
private GraphNode getEqualsMapping(String uri, String componentName) |
102 | |
{ |
103 | 16 | String equalsMapping = env.getConfig().getMappings().getProperty(uri + ".equals"); |
104 | 16 | if (equalsMapping != null) |
105 | |
{ |
106 | 0 | env.log("Mapping equivalent endpoint '" + equalsMapping + "' to '" + uri + "'"); |
107 | 0 | return getEndpoint(equalsMapping, componentName); |
108 | |
} |
109 | 16 | return null; |
110 | |
} |
111 | |
|
112 | |
public void addEndpoint(String url, GraphNode out) |
113 | |
{ |
114 | 6 | env.log("adding endpoint: " + out.getId() + "; " + url); |
115 | 6 | endpoints.put(url, out); |
116 | 6 | } |
117 | |
} |