View Javadoc

1   /*
2    * <cvs:source>$Source: /devel/astrogrid/community/resolver/src/java/org/astrogrid/community/resolver/CommunityAccountSpaceResolver.java,v $</cvs:source>
3    * <cvs:author>$Author: dave $</cvs:author>
4    * <cvs:date>$Date: 2004/09/16 23:18:08 $</cvs:date>
5    * <cvs:version>$Revision: 1.7 $</cvs:version>
6    *
7    * <cvs:log>
8    *   $Log: CommunityAccountSpaceResolver.java,v $
9    *   Revision 1.7  2004/09/16 23:18:08  dave
10   *   Replaced debug logging in Community.
11   *   Added stream close() to FileStore.
12   *
13   *   Revision 1.6.12.1  2004/09/16 09:58:48  dave
14   *   Replaced debug with commons logging ....
15   *
16   *   Revision 1.6  2004/09/02 17:02:02  dave
17   *   Fixed myspace account creation problem.
18   *
19   *   Revision 1.5.70.2  2004/09/02 14:49:20  dave
20   *   Added debug ....
21   *
22   *   Revision 1.5.70.1  2004/09/02 14:21:42  dave
23   *   Added debug ....
24   *
25   *   Revision 1.5  2004/06/18 13:45:20  dave
26   *   Merged development branch, dave-dev-200406081614, into HEAD
27   *
28   *   Revision 1.4.32.1  2004/06/17 13:38:59  dave
29   *   Tidied up old CVS log entries
30   *
31   * </cvs:log>
32   *
33   */
34  package org.astrogrid.community.resolver ;
35  
36  import org.apache.commons.logging.Log ;
37  import org.apache.commons.logging.LogFactory ;
38  
39  import java.net.URL ;
40  import java.net.URISyntaxException ;
41  
42  import org.astrogrid.store.Ivorn ;
43  
44  import org.astrogrid.community.common.policy.data.AccountData ;
45  import org.astrogrid.community.common.ivorn.CommunityIvornParser ;
46  
47  import org.astrogrid.registry.RegistryException;
48  
49  import org.astrogrid.community.common.exception.CommunityPolicyException ;
50  import org.astrogrid.community.common.exception.CommunityServiceException ;
51  import org.astrogrid.community.common.exception.CommunityIdentifierException ;
52  
53  import org.astrogrid.community.resolver.exception.CommunityResolverException ;
54  
55  /***
56   * A utility to resolve an Ivorn identifier for a Community Account into an Ivorn for the Account home space..
57   *
58   */
59  public class CommunityAccountSpaceResolver
60      {
61      /***
62       * Our debug logger.
63       *
64       */
65      private static Log log = LogFactory.getLog(CommunityAccountSpaceResolver.class);
66  
67      /***
68       * Public constructor, using the default Registry service.
69       *
70       */
71      public CommunityAccountSpaceResolver()
72          {
73          //
74          // Initialise our default resolver.
75          resolver = new CommunityAccountResolver() ;
76          }
77  
78      /***
79       * Public constructor, for a specific Registry service.
80       * @param registry The endpoint address for our RegistryDelegate.
81       *
82       */
83      public CommunityAccountSpaceResolver(URL registry)
84          {
85          //
86          // Initialise our resolver with the url.
87          resolver = new CommunityAccountResolver(registry) ;
88          }
89  
90      /***
91       * Our CommunityAccountResolver resolver.
92       *
93       */
94      private CommunityAccountResolver resolver ;
95  
96      /***
97       * Resolve a Community Account identifier into the corresponding VoSpace identifier.
98       * @param ivorn The Community Account identifier.
99       * @return A new Ivorn for the corresponding VoSpace.
100      * @throws CommunityPolicyException If the Community cannot locate the Account.
101      * @throws CommunityServiceException If an error occurs in the Community service.
102      * @throws CommunityIdentifierException If the identifier is not valid.
103      * @throws CommunityResolverException If the Community is unable to resolve the identifier.
104      * @throws RegistryException If the Registry is unable to resolve the identifier.
105      *
106      */
107     public Ivorn resolve(Ivorn ivorn)
108         throws CommunityServiceException,
109             CommunityIdentifierException,
110             CommunityPolicyException,
111             CommunityResolverException,
112             RegistryException
113         {
114         log.debug("") ;
115         log.debug("----\"----") ;
116         log.debug("CommunityAccountSpaceResolver.resolve()") ;
117         log.debug("  Ivorn : " + ivorn) ;
118         //
119         // Check for null ivorn.
120         if (null == ivorn)
121             {
122             throw new CommunityIdentifierException(
123                 "Null identifier"
124                 ) ;
125             }
126         //
127         // Parse the Ivorn and then resolve the result.
128         return resolve(
129             new CommunityIvornParser(ivorn)
130             ) ;
131         }
132 
133     /***
134      * Resolve a Community Account identifier into the corresponding VoSpace identifier.
135      * @param parser The Community Account identifier.
136      * @return A new Ivorn for the corresponding VoSpace.
137      * @throws CommunityPolicyException If the Community cannot locate the Account.
138      * @throws CommunityServiceException If an error occurs in the Community service.
139      * @throws CommunityIdentifierException If the identifier is not valid.
140      * @throws CommunityResolverException If the Community is unable to resolve the identifier.
141      * @throws RegistryException If the Registry is unable to resolve the identifier.
142      *
143      */
144     protected Ivorn resolve(CommunityIvornParser parser)
145         throws CommunityServiceException,
146             CommunityIdentifierException,
147             CommunityPolicyException,
148             CommunityResolverException,
149             RegistryException
150         {
151         log.debug("") ;
152         log.debug("----\"----") ;
153         log.debug("CommunityAccountSpaceResolver.resolve()") ;
154         log.debug("  Ivorn : " + ((null != parser) ? parser.getIvorn() : null)) ;
155         //
156         // Check for null parser.
157         if (null == parser)
158             {
159             throw new CommunityIdentifierException(
160                 "Null identifier"
161                 ) ;
162             }
163         //
164         // Resolve the ivorn into an AccountData.
165         AccountData account = resolver.resolve(parser) ;
166         log.debug("CommunityAccountSpaceResolver.resolve()") ;
167         log.debug("Got Account") ;
168         log.debug("Account : " + account.getIdent()) ;
169         log.debug("Home    : " + account.getHomeSpace()) ;
170         //
171         // Get the Account home space Ivorn.
172         String home = account.getHomeSpace() ;
173         //
174         // If the Account has a home space.
175         if (null != home)
176             {
177             log.debug("PASS : Got Account home.") ;
178             log.debug("Building new Ivorn based on Account home") ;
179             log.debug("  Home : " + home) ;
180             log.debug("  Path : " + parser.getRemainder()) ;
181             //
182             // Create a new Ivorn from the home address.
183             try {
184                 return new Ivorn(
185                     (home + parser.getRemainder())
186                     ) ;
187                 }
188             catch (URISyntaxException ouch)
189                 {
190                 throw new CommunityIdentifierException(
191                     "Unable to parse Account home into an Ivorn",
192                     ouch
193                     ) ;
194                 }
195             }
196         //
197         // If the Account does not have a home space.
198         else {
199             throw new CommunityResolverException(
200                 "Account does not have a home space defined",
201                 parser.getIvorn()
202                 ) ;
203             }
204         }
205     }