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 package org.astrogrid.community.resolver ;
37
38 import org.apache.commons.logging.Log ;
39 import org.apache.commons.logging.LogFactory ;
40
41 import java.net.URL ;
42 import org.astrogrid.store.Ivorn ;
43
44 import org.astrogrid.community.common.policy.data.AccountData ;
45
46 import org.astrogrid.community.common.ivorn.CommunityIvornParser ;
47 import org.astrogrid.community.client.policy.manager.PolicyManagerDelegate ;
48
49 import org.astrogrid.community.resolver.policy.manager.PolicyManagerResolver ;
50
51 import org.astrogrid.registry.RegistryException;
52 import org.astrogrid.community.common.exception.CommunityPolicyException ;
53 import org.astrogrid.community.common.exception.CommunityServiceException ;
54 import org.astrogrid.community.common.exception.CommunityIdentifierException ;
55 import org.astrogrid.community.resolver.exception.CommunityResolverException ;
56
57 /***
58 * A utility to resolve Ivorn identifiers into Community Account data.
59 *
60 */
61 public class CommunityAccountResolver
62 {
63 /***
64 * Our debug logger.
65 *
66 */
67 private static Log log = LogFactory.getLog(CommunityAccountResolver.class);
68
69 /***
70 * Public constructor, using the default Registry service.
71 *
72 */
73 public CommunityAccountResolver()
74 {
75 resolver = new PolicyManagerResolver() ;
76 }
77
78 /***
79 * Public constructor, for a specific Registry service.
80 * @param registry The endpoint address for our RegistryDelegate.
81 *
82 */
83 public CommunityAccountResolver(URL registry)
84 {
85 resolver = new PolicyManagerResolver(registry) ;
86 }
87
88 /***
89 * Our PolicyManager resolver.
90 *
91 */
92 private PolicyManagerResolver resolver ;
93
94 /***
95 * Resolve a Community identifier into an AccountData.
96 * @param ivorn The Community Account identifier.
97 * @return An AccountData for the Account.
98 * @throws CommunityPolicyException If the Community cannot locate the Account.
99 * @throws CommunityServiceException If an error occurs in the Community service.
100 * @throws CommunityIdentifierException If the identifier is not valid.
101 * @throws CommunityResolverException If the Community is unable to resolve the identifier.
102 * @throws RegistryException If the Registry is unable to resolve the identifier.
103 *
104 */
105 public AccountData resolve(Ivorn ivorn)
106 throws CommunityServiceException,
107 CommunityIdentifierException,
108 CommunityPolicyException,
109 CommunityResolverException,
110 RegistryException
111 {
112 log.debug("") ;
113 log.debug("----\"----") ;
114 log.debug("CommunityAccountResolver.resolve()") ;
115 log.debug(" Ivorn : " + ivorn) ;
116
117
118 if (null == ivorn)
119 {
120 throw new CommunityIdentifierException(
121 "Null identifier"
122 ) ;
123 }
124
125
126 return resolve(
127 new CommunityIvornParser(ivorn)
128 ) ;
129 }
130
131 /***
132 * Resolve a Community identifier into an AccountData.
133 * @param parser The Community Account identifier.
134 * @return An AccountData for the Account.
135 * @throws CommunityPolicyException If the Community cannot locate the Account.
136 * @throws CommunityServiceException If an error occurs in the Community service.
137 * @throws CommunityIdentifierException If the identifier is not valid.
138 * @throws CommunityResolverException If the Community is unable to resolve the identifier.
139 * @throws RegistryException If the Registry is unable to resolve the identifier.
140 *
141 */
142 public AccountData resolve(CommunityIvornParser parser)
143 throws CommunityServiceException,
144 CommunityIdentifierException,
145 CommunityPolicyException,
146 CommunityResolverException,
147 RegistryException
148 {
149 log.debug("") ;
150 log.debug("----\"----") ;
151 log.debug("CommunityAccountResolver.resolve()") ;
152 log.debug(" Ivorn : " + ((null != parser) ? parser.getIvorn() : null)) ;
153
154
155 if (null == parser)
156 {
157 throw new CommunityIdentifierException(
158 "Null identifier"
159 ) ;
160 }
161
162
163 PolicyManagerDelegate delegate = resolver.resolve(parser) ;
164
165
166 return delegate.getAccount(
167 parser.getAccountIdent()
168 ) ;
169 }
170 }