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 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
102 if (null != this.service)
103 {
104
105
106 try {
107 return this.service.getServiceStatus() ;
108 }
109
110
111 catch (RemoteException ouch)
112 {
113 throw new CommunityServiceException(
114 "WebService call failed",
115 ouch
116 ) ;
117 }
118 }
119
120
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
138 if (ouch.getCause() != null)
139 {
140
141
142 if (ouch.getCause() instanceof CommunityServiceException)
143 {
144
145
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
161 if (ouch.getCause() != null)
162 {
163
164
165 if (ouch.getCause() instanceof CommunityIdentifierException)
166 {
167
168
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
184 if (ouch.getCause() != null)
185 {
186
187
188 if (ouch.getCause() instanceof CommunitySecurityException)
189 {
190
191
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
207 if (ouch.getCause() != null)
208 {
209
210
211 if (ouch.getCause() instanceof CommunityResourceException)
212 {
213
214
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
230 if (ouch.getCause() != null)
231 {
232
233
234 if (ouch.getCause() instanceof CommunityPolicyException)
235 {
236
237
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 }