1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44 package org.astrogrid.community.resolver.policy.manager ;
45
46 import org.apache.commons.logging.Log ;
47 import org.apache.commons.logging.LogFactory ;
48
49 import java.net.URL ;
50
51 import org.astrogrid.store.Ivorn ;
52
53 import org.astrogrid.community.common.ivorn.CommunityIvornParser ;
54
55 import org.astrogrid.community.common.policy.manager.PolicyManager ;
56
57 import org.astrogrid.community.client.policy.manager.PolicyManagerDelegate ;
58 import org.astrogrid.community.client.policy.manager.PolicyManagerMockDelegate ;
59 import org.astrogrid.community.client.policy.manager.PolicyManagerSoapDelegate ;
60 import org.astrogrid.registry.client.query.ServiceData ;
61
62 import org.astrogrid.community.resolver.CommunityEndpointResolver ;
63
64 import org.astrogrid.community.common.exception.CommunityIdentifierException ;
65 import org.astrogrid.community.resolver.exception.CommunityResolverException ;
66
67 import org.astrogrid.registry.RegistryException;
68
69 /***
70 * A toolkit to resolve an Ivorn identifier into a PolicyManagerResolver delegate.
71 *
72 */
73 public class PolicyManagerResolver
74 {
75 /***
76 * Our debug logger.
77 *
78 */
79 private static Log log = LogFactory.getLog(PolicyManagerResolver.class);
80
81 /***
82 * Public constructor, using the default Registry service.
83 *
84 */
85 public PolicyManagerResolver()
86 {
87
88
89 resolver = new CommunityEndpointResolver() ;
90 }
91
92 /***
93 * Public constructor, for a specific Registry service.
94 * @param registry The endpoint address for our RegistryDelegate.
95 *
96 */
97 public PolicyManagerResolver(URL registry)
98 {
99
100
101 resolver = new CommunityEndpointResolver(registry) ;
102 }
103
104 /***
105 * Our endpoint resolver.
106 *
107 */
108 private CommunityEndpointResolver resolver ;
109
110 /***
111 * Resolve an Ivorn identifier into a PolicyManagerDelegate.
112 * If the Ivorn matches the MOCK_IVORN, this will return a PolicyManagerMockDelegate.
113 * If the Ivorn is a valid identifier, then this will lookup the identifier in the registry.
114 * @param ident The service identifier.
115 * @return A new PolicyManagerDelegate.
116 * @throws CommunityIdentifierException If the identifier is not valid.
117 * @throws CommunityResolverException If the Community is unable to resolve the identifier.
118 * @throws RegistryException If the Registry is unable to resolve the identifier.
119 *
120 */
121 public PolicyManagerDelegate resolve(Ivorn ivorn)
122 throws RegistryException, CommunityIdentifierException, CommunityResolverException
123 {
124 log.debug("") ;
125 log.debug("----\"----") ;
126 log.debug("PolicyManagerResolverImpl.resolve()") ;
127 log.debug(" Ivorn : " + ((null != ivorn) ? ivorn : null)) ;
128
129
130 if (null == ivorn)
131 {
132 throw new CommunityIdentifierException(
133 "Null identifier"
134 ) ;
135 }
136
137
138 return this.resolve(
139 new CommunityIvornParser(ivorn)
140 ) ;
141 }
142
143 public Ivorn getIvornForService(Ivorn ivorn) throws CommunityIdentifierException {
144 return resolver.getIvornForService(ivorn,PolicyManager.class);
145 }
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174 public ServiceData[] resolve()
175 throws RegistryException, CommunityIdentifierException, CommunityResolverException {
176 log.debug("") ;
177 log.debug("----\"----") ;
178 log.debug("PolicyManagerResolverImpl.resolve()") ;
179
180
181 return resolver.resolve() ;
182 }
183
184
185 /***
186 * Resolve data from a CommunityIvornParser into a PolicyManagerDelegate.
187 * If the Ivorn matches the MOCK_IVORN, this will return a PolicyManagerMockDelegate.
188 * If the Ivorn is a valid identifier, then this will lookup the identifier in the registry.
189 * @param parser The service identifier.
190 * @return A new PolicyManagerDelegate.
191 * @throws CommunityIdentifierException If the identifier is not valid.
192 * @throws CommunityResolverException If the Community is unable to resolve the identifier.
193 * @throws RegistryException If the Registry is unable to resolve the identifier.
194 *
195 */
196 public PolicyManagerDelegate resolve(CommunityIvornParser parser)
197 throws RegistryException, CommunityIdentifierException, CommunityResolverException
198 {
199 log.debug("") ;
200 log.debug("----\"----") ;
201 log.debug("PolicyManagerResolverImpl.resolve(parser)") ;
202 log.debug(" Ivorn : " + ((null != parser) ? parser.getIvorn() : null)) ;
203
204
205 if (null == parser)
206 {
207 throw new CommunityIdentifierException(
208 "Null identifier"
209 ) ;
210 }
211
212
213 if (parser.isMock())
214 {
215 log.debug("Ivorn is mock.") ;
216 log.debug("Creating mock delegate.") ;
217
218
219 return new PolicyManagerMockDelegate() ;
220 }
221
222
223 else {
224 log.debug("Ivorn is real.") ;
225 log.debug("Resolving endpoint URL.") ;
226
227
228 URL endpoint = resolver.resolve(parser, PolicyManager.class) ;
229 log.debug("PASS : Got endpoint url") ;
230 log.debug(" URL : " + endpoint) ;
231 log.debug("Creating SOAP delegate.") ;
232
233
234 return this.resolve(endpoint) ;
235 }
236 }
237
238 /***
239 * Resolve a WebService endpoint into a PolicyManagerDelegate.
240 * @param url The PolicyManager endpoint URL.
241 * @return A new PolicyManagerDelegate.
242 *
243 */
244 protected PolicyManagerDelegate resolve(URL url)
245 {
246 return new PolicyManagerSoapDelegate(url) ;
247 }
248 }