View Javadoc

1   /*
2    * <cvs:source>$Source: /devel/astrogrid/community/client/src/java/org/astrogrid/community/client/policy/service/PolicyServiceCoreDelegate.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.8 $</cvs:version>
6    *
7    * <cvs:log>
8    *   $Log: PolicyServiceCoreDelegate.java,v $
9    *   Revision 1.8  2004/09/16 23:18:08  dave
10   *   Replaced debug logging in Community.
11   *   Added stream close() to FileStore.
12   *
13   *   Revision 1.7.82.1  2004/09/16 09:58:48  dave
14   *   Replaced debug with commons logging ....
15   *
16   *   Revision 1.7  2004/06/18 13:45:19  dave
17   *   Merged development branch, dave-dev-200406081614, into HEAD
18   *
19   *   Revision 1.6.32.3  2004/06/17 15:10:03  dave
20   *   Removed unused imports (PMD report).
21   *
22   *   Revision 1.6.32.2  2004/06/17 13:38:58  dave
23   *   Tidied up old CVS log entries
24   *
25   * </cvs:log>
26   *
27   */
28  package org.astrogrid.community.client.policy.service ;
29  
30  import org.apache.commons.logging.Log ;
31  import org.apache.commons.logging.LogFactory ;
32  
33  import java.rmi.RemoteException ;
34  
35  import org.astrogrid.community.common.policy.data.PolicyPermission ;
36  import org.astrogrid.community.common.policy.data.PolicyCredentials ;
37  
38  import org.astrogrid.community.common.policy.service.PolicyService ;
39  
40  import org.astrogrid.community.common.exception.CommunityPolicyException     ;
41  import org.astrogrid.community.common.exception.CommunityServiceException    ;
42  import org.astrogrid.community.common.exception.CommunityIdentifierException ;
43  
44  import org.astrogrid.community.client.service.CommunityServiceCoreDelegate ;
45  
46  /***
47   * The core delegate for our PolicyService service.
48   * This acts as a wrapper for a PolicyService service, and converts RemoteExceptions into CommunityServiceException.
49   *
50   */
51  public class PolicyServiceCoreDelegate
52      extends CommunityServiceCoreDelegate
53      implements PolicyService, PolicyServiceDelegate
54      {
55      /***
56       * Our debug logger.
57       *
58       */
59      private static Log log = LogFactory.getLog(PolicyServiceCoreDelegate.class);
60  
61      /***
62       * Public constructor.
63       *
64       */
65      public PolicyServiceCoreDelegate()
66          {
67          }
68  
69      /***
70       * Our PolicyService service.
71       *
72       */
73      private PolicyService service = null ;
74  
75      /***
76       * Get a reference to our PolicyService service.
77       *
78       */
79      protected PolicyService getPolicyService()
80          {
81          return this.service ;
82          }
83  
84      /***
85       * Set our our PolicyService service.
86       *
87       */
88      protected void setPolicyService(PolicyService service)
89          {
90          this.setCommunityService(service) ;
91          this.service = service ;
92          }
93  
94      /***
95       * Confirm permissions.
96       * @param credentials The credentials, containing the account and group identifiers.
97       * @param resource The resource identifier.
98       * @param action The action you want to perform.
99       * @return A PolicyPermission object confirming the permission.
100      * @throws CommunityIdentifierException If one of the identifiers is invalid.
101      * @throws CommunityPolicyException If there is no matching permission.
102      * @throws CommunityServiceException If there is an internal error in the service.
103      *
104      */
105     public PolicyPermission checkPermissions(PolicyCredentials credentials, String resource, String action)
106         throws CommunityServiceException, CommunityPolicyException, CommunityIdentifierException
107         {
108         //
109         // If we have a valid service reference.
110         if (null != this.service)
111             {
112             //
113             // Try calling the service method.
114             try {
115                 return this.service.checkPermissions(credentials, resource, action) ;
116                 }
117             //
118             // Catch anything that went BANG.
119             catch (RemoteException ouch)
120                 {
121                 //
122                 // Try converting the Exception.
123                 policyException(ouch) ;
124                 serviceException(ouch) ;
125                 identifierException(ouch) ;
126                 //
127                 // If we get this far, then we don't know what it is.
128                 throw new CommunityServiceException(
129                     "WebService call failed - " + ouch,
130                     ouch
131                     ) ;
132                 }
133             }
134         //
135         // If we don't have a valid service.
136         else {
137             throw new CommunityServiceException(
138                 "Service not initialised"
139                 ) ;
140             }
141         }
142 
143     /***
144      * Confirm membership.
145      * @param credentials The credentials, containing the account and group identifiers.
146      * @return A PolicyCredentials object confirming the membership.
147      * @throws CommunityIdentifierException If one of the identifiers is invalid.
148      * @throws CommunityPolicyException If there is no matching permission.
149      * @throws CommunityServiceException If there is an internal error in the service.
150      *
151      */
152     public PolicyCredentials checkMembership(PolicyCredentials credentials)
153         throws CommunityServiceException, CommunityPolicyException, CommunityIdentifierException
154         {
155         //
156         // If we have a valid service reference.
157         if (null != this.service)
158             {
159             //
160             // Try calling the service method.
161             try {
162                 return this.service.checkMembership(credentials) ;
163                 }
164             //
165             // Catch anything that went BANG.
166             catch (RemoteException ouch)
167                 {
168                 //
169                 // Try converting the Exception.
170                 policyException(ouch) ;
171                 serviceException(ouch) ;
172                 identifierException(ouch) ;
173                 //
174                 // If we get this far, then we don't know what it is.
175                 throw new CommunityServiceException(
176                     "WebService call failed - " + ouch,
177                     ouch
178                     ) ;
179                 }
180             }
181         //
182         // If we don't have a valid service.
183         else {
184             throw new CommunityServiceException(
185                 "Service not initialised"
186                 ) ;
187             }
188         }
189     }