View Javadoc

1   /*
2    * <cvs:source>$Source: /devel/astrogrid/community/resolver/src/java/org/astrogrid/community/resolver/policy/manager/PolicyManagerResolver.java,v $</cvs:source>
3    * <cvs:author>$Author: jdt $</cvs:author>
4    * <cvs:date>$Date: 2005/01/07 14:14:25 $</cvs:date>
5    * <cvs:version>$Revision: 1.11 $</cvs:version>
6    *
7    * <cvs:log>
8    *   $Log: PolicyManagerResolver.java,v $
9    *   Revision 1.11  2005/01/07 14:14:25  jdt
10   *   merged from Reg_KMB_787
11   *
12   *   Revision 1.10.12.1  2004/12/11 11:53:16  KevinBenson
13   *   modifications to the jsps, also merged in several pieces of the validtion stuff
14   *
15   *   Revision 1.10  2004/11/04 18:00:02  jdt
16   *   Restored following fixes to auto-integration
17   *   Merged in Reg_KMB_546 and Reg_KMB_603 and Comm_KMB_583
18   *
19   *   Revision 1.8  2004/11/02 21:47:39  jdt
20   *   Merge of Comm_KMB_583
21   *
22   *   Revision 1.7.20.1  2004/10/26 06:10:39  KevinBenson
23   *   sprucing up admin interface and getting it where it grabs communities and accounts from external communities
24   *
25   *   Revision 1.7  2004/09/16 23:18:08  dave
26   *   Replaced debug logging in Community.
27   *   Added stream close() to FileStore.
28   *
29   *   Revision 1.6.82.1  2004/09/16 09:58:48  dave
30   *   Replaced debug with commons logging ....
31   *
32   *   Revision 1.6  2004/06/18 13:45:20  dave
33   *   Merged development branch, dave-dev-200406081614, into HEAD
34   *
35   *   Revision 1.5.36.2  2004/06/17 15:17:30  dave
36   *   Removed unused imports (PMD report).
37   *
38   *   Revision 1.5.36.1  2004/06/17 13:38:59  dave
39   *   Tidied up old CVS log entries
40   *
41   * </cvs:log>
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          // Initialise a default resolver.
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         // Initialise a resolver with the url.
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         // Check for null ivorn.
130         if (null == ivorn)
131             {
132             throw new CommunityIdentifierException(
133                 "Null identifier"
134                 ) ;
135             }
136         //
137         // Parse the ivorn and resolve it.
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     public URL[] resolve()
149        throws RegistryException, CommunityIdentifierException, CommunityResolverException {
150         log.debug("") ;
151         log.debug("----\"----") ;
152         log.debug("PolicyManagerResolverImpl.resolve()") ;
153         
154         log.debug("Resolving endpoint URLs.") ;
155         //
156         // Lookup the endpoint in the registry.
157         URL endpoints[] = resolver.resolve() ;
158         PolicyManagerD
159         elegate []pmd = new PolicyManagerDelegate[endpoints.length];
160         
161         log.debug("PASS : Got endpoint urls number = " + endpoints.length) ;
162         for(int i = 0;i < endpoints.length; i++) {
163             log.debug("  URL : " + endpoints[i]) ;
164             log.debug("Creating SOAP delegate.") ;
165             pmd[i] = this.resolve(endpoints[i]);            
166         }
167         //
168         // Return the delegates
169         return pmd;
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      // Lookup the endpoint in the registry.
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         // Check for null parser.
205         if (null == parser)
206             {
207             throw new CommunityIdentifierException(
208                 "Null identifier"
209                 ) ;
210             }
211         //
212         // Check for a mock ivorn.
213         if (parser.isMock())
214             {
215             log.debug("Ivorn is mock.") ;
216             log.debug("Creating mock delegate.") ;
217             //
218             // Return a mock delegate.
219             return new PolicyManagerMockDelegate() ;
220             }
221         //
222         // If the ident is real.
223         else {
224             log.debug("Ivorn is real.") ;
225             log.debug("Resolving endpoint URL.") ;
226             //
227             // Lookup the endpoint in the registry.
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             // Return a new delegate
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     }