View Javadoc

1   /*
2    * <cvs:source>$Source: /devel/astrogrid/community/client/src/java/org/astrogrid/community/client/service/CommunityServiceCoreDelegate.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.6 $</cvs:version>
6    *
7    * <cvs:log>
8    *   $Log: CommunityServiceCoreDelegate.java,v $
9    *   Revision 1.6  2004/09/16 23:18:08  dave
10   *   Replaced debug logging in Community.
11   *   Added stream close() to FileStore.
12   *
13   *   Revision 1.5.82.1  2004/09/16 09:58:48  dave
14   *   Replaced debug with commons logging ....
15   *
16   *   Revision 1.5  2004/06/18 13:45:19  dave
17   *   Merged development branch, dave-dev-200406081614, into HEAD
18   *
19   *   Revision 1.4.32.3  2004/06/17 15:10:03  dave
20   *   Removed unused imports (PMD report).
21   *
22   *   Revision 1.4.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.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.service.CommunityService ;
36  import org.astrogrid.community.common.service.data.ServiceStatusData ;
37  
38  import org.astrogrid.community.common.exception.CommunityPolicyException     ;
39  import org.astrogrid.community.common.exception.CommunityServiceException    ;
40  import org.astrogrid.community.common.exception.CommunitySecurityException   ;
41  import org.astrogrid.community.common.exception.CommunityResourceException   ;
42  import org.astrogrid.community.common.exception.CommunityIdentifierException ;
43  
44  /***
45   * The core delegate for our service delegates.
46   * This acts as a wrapper for a CommunityService, and converts RemoteExceptions into CommunityServiceException.
47   * @see CommunityService
48   *
49   */
50  public class CommunityServiceCoreDelegate
51      implements CommunityService, CommunityServiceDelegate
52      {
53      /***
54       * Our debug logger.
55       *
56       */
57      private static Log log = LogFactory.getLog(CommunityServiceCoreDelegate.class);
58  
59      /***
60       * Public constructor.
61       *
62       */
63      public CommunityServiceCoreDelegate()
64          {
65          }
66  
67      /***
68       * Our CommunityService.
69       *
70       */
71      private CommunityService service = null ;
72  
73      /***
74       * Get a reference to our CommunityService.
75       *
76       */
77      protected CommunityService getCommunityService()
78          {
79          return this.service ;
80          }
81  
82      /***
83       * Set our our CommunityService.
84       *
85       */
86      protected void setCommunityService(CommunityService service)
87          {
88          this.service = service ;
89          }
90  
91      /***
92       * Service health check.
93       * @return ServiceStatusData with details of the Service status.
94       * @throws CommunityServiceException If there is an server error.
95       *
96       */
97      public ServiceStatusData getServiceStatus()
98          throws CommunityServiceException
99          {
100         //
101         // If we have a valid service reference.
102         if (null != this.service)
103             {
104             //
105             // Try calling the service method.
106             try {
107                 return this.service.getServiceStatus() ;
108                 }
109             //
110             // Catch anything that went BANG.
111             catch (RemoteException ouch)
112                 {
113                 throw new CommunityServiceException(
114                     "WebService call failed",
115                     ouch
116                     ) ;
117                 }
118             }
119         //
120         // If we don't have a valid service.
121         else {
122             throw new CommunityServiceException(
123                 "Service not initialised"
124                 ) ;
125             }
126         }
127 
128     /***
129      * A converter utility to unpack a CommunityServiceException from a RemoteException.
130      * @throws CommunityServiceException If the RemoteException cause was a CommunityServiceException.
131      *
132      */
133     public void serviceException(RemoteException ouch)
134         throws CommunityServiceException
135         {
136         //
137         // If the remote Exception has a cause.
138         if (ouch.getCause() != null)
139             {
140             //
141             // If the cause is a CommunityServiceException.
142             if (ouch.getCause() instanceof CommunityServiceException)
143                 {
144                 //
145                 // Re-throw the CommunityServiceException.
146                 throw (CommunityServiceException) ouch.getCause() ;
147                 }
148             }
149         }
150 
151     /***
152      * A converter utility to unpack a CommunityIdentifierException from a RemoteException.
153      * @throws CommunityIdentifierException If the RemoteException cause was a CommunityIdentifierException.
154      *
155      */
156     public void identifierException(RemoteException ouch)
157         throws CommunityIdentifierException
158         {
159         //
160         // If the remote Exception has a cause.
161         if (ouch.getCause() != null)
162             {
163             //
164             // If the cause is a CommunityIdentifierException.
165             if (ouch.getCause() instanceof CommunityIdentifierException)
166                 {
167                 //
168                 // Re-throw the CommunityIdentifierException.
169                 throw (CommunityIdentifierException) ouch.getCause() ;
170                 }
171             }
172         }
173 
174     /***
175      * A converter utility to unpack a CommunitySecurityException from a RemoteException.
176      * @throws CommunitySecurityException If the RemoteException cause was a CommunitySecurityException.
177      *
178      */
179     public void securityException(RemoteException ouch)
180         throws CommunitySecurityException
181         {
182         //
183         // If the remote Exception has a cause.
184         if (ouch.getCause() != null)
185             {
186             //
187             // If the cause is a CommunitySecurityException.
188             if (ouch.getCause() instanceof CommunitySecurityException)
189                 {
190                 //
191                 // Re-throw the CommunitySecurityException.
192                 throw (CommunitySecurityException) ouch.getCause() ;
193                 }
194             }
195         }
196 
197     /***
198      * A converter utility to unpack a CommunityResourceException from a RemoteException.
199      * @throws CommunityResourceException If the RemoteException cause was a CommunitySecurityException.
200      *
201      */
202     public void resourceException(RemoteException ouch)
203         throws CommunityResourceException
204         {
205         //
206         // If the remote Exception has a cause.
207         if (ouch.getCause() != null)
208             {
209             //
210             // If the cause is a CommunityResourceException.
211             if (ouch.getCause() instanceof CommunityResourceException)
212                 {
213                 //
214                 // Re-throw the CommunityResourceException.
215                 throw (CommunityResourceException) ouch.getCause() ;
216                 }
217             }
218         }
219 
220     /***
221      * A converter utility to unpack a CommunityPolicyException from a RemoteException.
222      * @throws CommunityPolicyException If the RemoteException cause was a CommunityPolicyException.
223      *
224      */
225     public void policyException(RemoteException ouch)
226         throws CommunityPolicyException
227         {
228         //
229         // If the remote Exception has a cause.
230         if (ouch.getCause() != null)
231             {
232             //
233             // If the cause is a CommunityPolicyException.
234             if (ouch.getCause() instanceof CommunityPolicyException)
235                 {
236                 //
237                 // Re-throw the CommunityResourceException.
238                 throw (CommunityPolicyException) ouch.getCause() ;
239                 }
240             }
241         }
242 
243     /***
244      * A converter utility to unpack one of the CommunityExceptions from a RemoteException.
245      * @throws CommunityPolicyException If the RemoteException cause was a CommunityPolicyException.
246      * @throws CommunityServiceException If the RemoteException cause was a CommunityServiceException.
247      * @throws CommunityIdentifierException If the RemoteException cause was a CommunityIdentifierException.
248      * @throws CommunityResourceException If the RemoteException cause was a CommunityResourceException.
249      * @todo Need to handle java.net.ConnectException
250      * @todo Need to handle org.astrogrid.config.PropertyNotFoundException
251      *
252     public void convertCommunityException(RemoteException ouch)
253         throws CommunityServiceException, CommunityIdentifierException, CommunityResourceException, CommunityPolicyException
254         {
255         //
256         // If the remote Exception has a cause.
257         if (ouch.getCause() != null)
258             {
259             //
260             // If the cause is a CommunityServiceException.
261             if (ouch.getCause() instanceof CommunityServiceException)
262                 {
263                 //
264                 // Re-throw the CommunityServiceException.
265                 throw (CommunityServiceException) ouch.getCause() ;
266                 }
267             //
268             // If the cause is a CommunityIdentifierException.
269             if (ouch.getCause() instanceof CommunityIdentifierException)
270                 {
271                 //
272                 // Re-throw the CommunityIdentifierException.
273                 throw (CommunityIdentifierException) ouch.getCause() ;
274                 }
275             //
276             // If the cause is a CommunityResourceException.
277             if (ouch.getCause() instanceof CommunityResourceException)
278                 {
279                 //
280                 // Re-throw the CommunityIdentifierException.
281                 throw (CommunityResourceException) ouch.getCause() ;
282                 }
283             //
284             // If the cause is a CommunityPolicyException.
285             if (ouch.getCause() instanceof CommunityPolicyException)
286                 {
287                 //
288                 // Re-throw the CommunityPolicyException.
289                 throw (CommunityPolicyException) ouch.getCause() ;
290                 }
291             }
292         }
293      */
294     }