View Javadoc

1   /*
2    * <cvs:source>$Source: /devel/astrogrid/filestore/client/src/java/org/astrogrid/filestore/client/FileStoreCoreDelegate.java,v $</cvs:source>
3    * <cvs:author>$Author: jdt $</cvs:author>
4    * <cvs:date>$Date: 2004/11/25 00:19:20 $</cvs:date>
5    * <cvs:version>$Revision: 1.8 $</cvs:version>
6    * <cvs:log>
7    *   $Log: FileStoreCoreDelegate.java,v $
8    *   Revision 1.8  2004/11/25 00:19:20  jdt
9    *   Merge from dave-dev-200410061224-200411221626
10   *
11   *   Revision 1.7.14.2  2004/10/29 20:57:11  dave
12   *   Updated delegate API to match exportInit.
13   *
14   *   Revision 1.7.14.1  2004/10/21 21:00:13  dave
15   *   Added mock://xyz URL handler to enable testing of transfer.
16   *   Implemented importInit to the mock service and created transfer tests.
17   *
18   *   Revision 1.7  2004/09/17 06:57:10  dave
19   *   Added commons logging to FileStore.
20   *   Updated logging properties in Community.
21   *   Fixed bug in AGINAB deployment.
22   *   Removed MySpace tests with hard coded grendel address.
23   *
24   *   Revision 1.6.20.1  2004/09/17 01:08:36  dave
25   *   Updated debug to use commons logging API ....
26   *
27   *   Revision 1.6  2004/08/27 22:43:15  dave
28   *   Updated filestore and myspace to report file size correctly.
29   *
30   *   Revision 1.5.38.1  2004/08/26 22:40:05  dave
31   *   Updated client to handle file size.
32   *
33   *   Revision 1.5  2004/07/23 09:11:16  dave
34   *   Merged development branch, dave-dev-200407221513, into HEAD
35   *
36   *   Revision 1.4.6.1  2004/07/23 02:10:58  dave
37   *   Added IvornFactory and IvornParser
38   *
39   *   Revision 1.4  2004/07/21 18:11:55  dave
40   *   Merged development branch, dave-dev-200407201059, into HEAD
41   *
42   *   Revision 1.3.2.1  2004/07/21 12:25:59  dave
43   *   Updated client to inport from URL
44   *
45   *   Revision 1.3  2004/07/19 23:42:07  dave
46   *   Merged development branch, dave-dev-200407151443, into HEAD
47   *
48   *   Revision 1.2.4.6  2004/07/19 19:40:28  dave
49   *   Debugged and worked around Axis Exception handling
50   *
51   *   Revision 1.2.4.5  2004/07/16 18:02:28  dave
52   *   Added debug to tests
53   *
54   *   Revision 1.2.4.4  2004/07/16 16:43:19  dave
55   *   Added debug
56   *
57   *   Revision 1.2.4.3  2004/07/16 16:40:21  dave
58   *   Added debug
59   *
60   *   Revision 1.2.4.2  2004/07/16 16:39:09  dave
61   *   Added debug
62   *
63   *   Revision 1.2.4.1  2004/07/16 16:37:45  dave
64   *   Added debug
65   *
66   *   Revision 1.2  2004/07/14 13:50:29  dave
67   *   Merged development branch, dave-dev-200406301228, into HEAD
68   *
69   *   Revision 1.1.2.7  2004/07/13 16:37:29  dave
70   *   Refactored common and client to use an array of FileProperties (more SOAP friendly)
71   *
72   *   Revision 1.1.2.6  2004/07/12 14:39:03  dave
73   *   Added server repository classes
74   *
75   *   Revision 1.1.2.5  2004/07/08 07:31:30  dave
76   *   Added container impl and tests
77   *
78   *   Revision 1.1.2.4  2004/07/07 14:54:35  dave
79   *   Changed DataInfo to File Info (leaves room to use DataInfo for the more abstract VoStore interface).
80   *
81   *   Revision 1.1.2.3  2004/07/07 11:55:54  dave
82   *   Fixed byte array compare in tests
83   *
84   *   Revision 1.1.2.2  2004/07/06 10:49:45  dave
85   *   Added SOAP delegate
86   *
87   *   Revision 1.1.2.1  2004/07/06 09:16:12  dave
88   *   Added delegate interface and mock implementation
89   *
90   * </cvs:log>
91   *
92   */
93  package org.astrogrid.filestore.client ;
94  
95  import org.apache.commons.logging.Log ;
96  import org.apache.commons.logging.LogFactory ;
97  
98  import java.rmi.RemoteException ;
99  
100 import org.astrogrid.filestore.common.FileStore ;
101 import org.astrogrid.filestore.common.file.FileProperty ;
102 import org.astrogrid.filestore.common.transfer.TransferProperties ;
103 import org.astrogrid.filestore.common.exception.FileStoreException ;
104 import org.astrogrid.filestore.common.exception.FileStoreNotFoundException ;
105 import org.astrogrid.filestore.common.exception.FileStoreIdentifierException ;
106 import org.astrogrid.filestore.common.exception.FileStoreServiceException ;
107 import org.astrogrid.filestore.common.exception.FileStoreTransferException ;
108 
109 /***
110  * Core implementation of the delegate interface.
111  * Handles unwrapping remote Exceptions from a service call.
112  *
113  */
114 public class FileStoreCoreDelegate
115 	implements FileStore, FileStoreDelegate
116 	{
117     /***
118      * Our debug logger.
119      *
120      */
121     private static Log log = LogFactory.getLog(FileStoreCoreDelegate.class);
122 
123 	/***
124 	 * Reference to our FileStore service.
125 	 *
126 	 */
127 	protected FileStore service ;
128 
129 	/***
130 	 * Public constructor.
131 	 *
132 	 */
133 	public FileStoreCoreDelegate()
134 		{
135         log.debug("") ;
136         log.debug("----\"----") ;
137         log.debug("FileStoreCoreDelegate()") ;
138 		}
139 
140 	/***
141 	 * Get the service identifier - used for testing.
142 	 * @return The ivo identifier for this service.
143 	 * @throws FileStoreServiceException if unable handle the request.
144 	 *
145 	 */
146 	public String identifier()
147 		throws FileStoreServiceException
148 		{
149 		if (null != service)
150 			{
151 			try {
152 				return service.identifier() ;
153 				}
154 			catch (RemoteException ouch)
155 				{
156 				//
157 				// Unpack the expected Exception(s).
158 				serviceException(ouch) ;
159 				//
160 				// If we get this far, then we don't know what it is.
161 				throw new FileStoreServiceException(
162 					"WebService call failed - " + ouch,
163 					ouch
164 					) ;
165 				}
166 			}
167 		else {
168 			throw new FileStoreServiceException(
169 				"Service not initialised"
170 				) ;
171 			}
172 		}
173 
174 	/***
175 	 * Import (store) a string of data.
176 	 * @param properties An array of FileProperties describing the imported data.
177 	 * @param data The string of data to store.
178 	 * @return An array of FileProperties describing the imported data.
179 	 * @throws FileStoreException if the data string is null.
180 	 * @throws FileStoreServiceException if unable handle the request.
181 	 *
182 	 */
183 	public FileProperty[] importString(FileProperty[] properties, String data)
184 		throws FileStoreServiceException, FileStoreException
185 		{
186         log.debug("") ;
187         log.debug("----\"----") ;
188         log.debug("FileStoreCoreDelegate.importString()") ;
189         log.debug("  Data : " + data) ;
190 		if (null != service)
191 			{
192 			try {
193 				return service.importString(properties, data) ;
194 				}
195 			catch (RemoteException ouch)
196 				{
197 
198 				log.debug("  >>>>") ;
199 				log.debug("  Exception : " + ouch) ;
200 				log.debug("  Type      : " + ouch.getClass()) ;
201 				log.debug("  Cause     : " + ouch.getCause()) ;
202 				log.debug("  >>>>") ;
203 
204 				//
205 				// Unpack the expected Exception(s).
206 				serviceException(ouch) ;
207 				filestoreException(ouch) ;
208 				//
209 				// If we get this far, then we don't know what it is.
210 				throw new FileStoreServiceException(
211 					"WebService call failed - " + ouch,
212 					ouch
213 					) ;
214 				}
215 			}
216 		else {
217 			throw new FileStoreServiceException(
218 				"Service not initialised"
219 				) ;
220 			}
221 		}
222 
223 	/***
224 	 * Import (store) a byte array of data.
225 	 * @param properties An array of FileProperties describing the imported data.
226 	 * @param data The byte array of data to store.
227 	 * @return An array of FileProperties describing the imported data.
228 	 * @throws FileStoreException if the data string is null.
229 	 * @throws FileStoreServiceException if unable handle the request.
230 	 *
231 	 */
232 	public FileProperty[] importBytes(FileProperty[] properties, byte[] data)
233 		throws FileStoreServiceException, FileStoreException
234 		{
235 		if (null != service)
236 			{
237 			try {
238 				return service.importBytes(properties, data) ;
239 				}
240 			catch (RemoteException ouch)
241 				{
242 				//
243 				// Unpack the expected Exception(s).
244 				serviceException(ouch) ;
245 				filestoreException(ouch) ;
246 				//
247 				// If we get this far, then we don't know what it is.
248 				throw new FileStoreServiceException(
249 					"WebService call failed - " + ouch,
250 					ouch
251 					) ;
252 				}
253 			}
254 		else {
255 			throw new FileStoreServiceException(
256 				"Service not initialised"
257 				) ;
258 			}
259 		}
260 
261 	/***
262 	 * Append a string to existing data.
263 	 * @param ident The internal identifier of the target.
264 	 * @param data The string to append.
265 	 * @return An array of FileProperties describing the imported data.
266 	 * @throws FileStoreIdentifierException if the identifier is null or not valid.
267 	 * @throws FileStoreNotFoundException if unable to locate the file.
268 	 * @throws FileStoreException if the string is null.
269 	 * @throws FileStoreServiceException if unable handle the request.
270 	 *
271 	 */
272 	public FileProperty[] appendString(String ident, String data)
273 		throws FileStoreServiceException, FileStoreIdentifierException, FileStoreNotFoundException, FileStoreException
274 		{
275 		if (null != service)
276 			{
277 			try {
278 				return service.appendString(ident, data) ;
279 				}
280 			catch (RemoteException ouch)
281 				{
282 				//
283 				// Unpack the expected Exception(s).
284 				serviceException(ouch) ;
285 				notfoundException(ouch) ;
286 				filestoreException(ouch) ;
287 				identifierException(ouch) ;
288 				//
289 				// If we get this far, then we don't know what it is.
290 				throw new FileStoreServiceException(
291 					"WebService call failed - " + ouch,
292 					ouch
293 					) ;
294 				}
295 			}
296 		else {
297 			throw new FileStoreServiceException(
298 				"Service not initialised"
299 				) ;
300 			}
301 		}
302 
303 	/***
304 	 * Append an array of bytes to existing data.
305 	 * @param ident The internal identifier of the target.
306 	 * @param data The bytes to append.
307 	 * @return An array of FileProperties describing the imported data.
308 	 * @throws FileStoreIdentifierException if the identifier is null or not valid.
309 	 * @throws FileStoreNotFoundException if unable to locate the file.
310 	 * @throws FileStoreException if the array is null.
311 	 * @throws FileStoreServiceException if unable handle the request.
312 	 *
313 	 */
314 	public FileProperty[] appendBytes(String ident, byte[] data)
315 		throws FileStoreServiceException, FileStoreIdentifierException, FileStoreNotFoundException, FileStoreException
316 		{
317 		if (null != service)
318 			{
319 			try {
320 				return service.appendBytes(ident, data) ;
321 				}
322 			catch (RemoteException ouch)
323 				{
324 				//
325 				// Unpack the expected Exception(s).
326 				serviceException(ouch) ;
327 				notfoundException(ouch) ;
328 				filestoreException(ouch) ;
329 				identifierException(ouch) ;
330 				//
331 				// If we get this far, then we don't know what it is.
332 				throw new FileStoreServiceException(
333 					"WebService call failed - " + ouch,
334 					ouch
335 					) ;
336 				}
337 			}
338 		else {
339 			throw new FileStoreServiceException(
340 				"Service not initialised"
341 				) ;
342 			}
343 		}
344 
345 	/***
346 	 * Export (read) the contents of a file as a string.
347 	 * @param ident The internal identifier of the target file.
348 	 * @return The contents of a data object as a string.
349 	 * @throws FileStoreIdentifierException if the identifier is null or not valid.
350 	 * @throws FileStoreNotFoundException if unable to locate the file.
351 	 * @throws FileStoreServiceException if unable handle the request.
352 	 *
353 	 */
354 	public String exportString(String ident)
355 		throws FileStoreServiceException, FileStoreIdentifierException, FileStoreNotFoundException
356 		{
357         log.debug("") ;
358         log.debug("----\"----") ;
359         log.debug("FileStoreCoreDelegate.exportString()") ;
360         log.debug("  Ident : " + ident) ;
361 		if (null != service)
362 			{
363 			try {
364 				return service.exportString(ident) ;
365 				}
366 			catch (RemoteException ouch)
367 				{
368 				log.debug("  ---- catch ----") ;
369 				log.debug("  Exception : " + ouch.getClass()) ;
370 				//
371 				// Unpack the expected Exception(s).
372 				serviceException(ouch) ;
373 				notfoundException(ouch) ;
374 				identifierException(ouch) ;
375 				//
376 				// If we get this far, then we don't know what it is.
377 				throw new FileStoreServiceException(
378 					"WebService call failed - " + ouch,
379 					ouch
380 					) ;
381 				}
382 			}
383 		else {
384 			throw new FileStoreServiceException(
385 				"Service not initialised"
386 				) ;
387 			}
388 		}
389 
390 	/***
391 	 * Export (read) the contents of a file as an array of bytes.
392 	 * @param ident The internal identifier of the target file.
393 	 * @return The contents of a data object as a string.
394 	 * @throws FileStoreIdentifierException if the identifier is null or not valid.
395 	 * @throws FileStoreNotFoundException if unable to locate the file.
396 	 * @throws FileStoreServiceException if unable handle the request.
397 	 *
398 	 */
399 	public byte[] exportBytes(String ident)
400 		throws FileStoreServiceException, FileStoreIdentifierException, FileStoreNotFoundException
401 		{
402 		if (null != service)
403 			{
404 			try {
405 				return service.exportBytes(ident) ;
406 				}
407 			catch (RemoteException ouch)
408 				{
409 				//
410 				// Unpack the expected Exception(s).
411 				serviceException(ouch) ;
412 				notfoundException(ouch) ;
413 				identifierException(ouch) ;
414 				//
415 				// If we get this far, then we don't know what it is.
416 				throw new FileStoreServiceException(
417 					"WebService call failed - " + ouch,
418 					ouch
419 					) ;
420 				}
421 			}
422 		else {
423 			throw new FileStoreServiceException(
424 				"Service not initialised"
425 				) ;
426 			}
427 		}
428 
429 	/***
430 	 * Create a local duplicate (copy) of a file.
431 	 * @param ident The internal identifier of the target file.
432 	 * @param properties An optional array of FileProperties describing the copy.
433 	 * @return An array of FileProperties describing the copied data.
434      * @throws FileStoreTransferException if unable to transfer the data.
435 	 * @throws FileStoreIdentifierException if the identifier is null or not valid.
436 	 * @throws FileStoreNotFoundException if unable to locate the file.
437 	 * @throws FileStoreServiceException if unable handle the request.
438 	 *
439 	 */
440 	public FileProperty[] duplicate(String ident, FileProperty[] properties)
441 		throws FileStoreServiceException, FileStoreIdentifierException, FileStoreNotFoundException, FileStoreTransferException
442 		{
443 		if (null != service)
444 			{
445 			try {
446 				return service.duplicate(ident, properties) ;
447 				}
448 			catch (RemoteException ouch)
449 				{
450 				//
451 				// Unpack the expected Exception(s).
452 				serviceException(ouch) ;
453 				notfoundException(ouch) ;
454 				transferException(ouch) ;
455 				identifierException(ouch) ;
456 				//
457 				// If we get this far, then we don't know what it is.
458 				throw new FileStoreServiceException(
459 					"WebService call failed - " + ouch,
460 					ouch
461 					) ;
462 				}
463 			}
464 		else {
465 			throw new FileStoreServiceException(
466 				"Service not initialised"
467 				) ;
468 			}
469 		}
470 
471 	/***
472 	 * Delete a file.
473 	 * @param ident The internal identifier of the target file.
474 	 * @return An array of FileProperties describing the deleted data.
475 	 * @throws FileStoreIdentifierException if the identifier is null or not valid.
476 	 * @throws FileStoreNotFoundException if unable to locate the file.
477 	 * @throws FileStoreServiceException if unable handle the request.
478 	 *
479 	 */
480 	public FileProperty[] delete(String ident)
481 		throws FileStoreServiceException, FileStoreIdentifierException, FileStoreNotFoundException
482 		{
483 		if (null != service)
484 			{
485 			try {
486 				return service.delete(ident) ;
487 				}
488 			catch (RemoteException ouch)
489 				{
490 				//
491 				// Unpack the expected Exception(s).
492 				serviceException(ouch) ;
493 				notfoundException(ouch) ;
494 				identifierException(ouch) ;
495 				//
496 				// If we get this far, then we don't know what it is.
497 				throw new FileStoreServiceException(
498 					"WebService call failed - " + ouch,
499 					ouch
500 					) ;
501 				}
502 			}
503 		else {
504 			throw new FileStoreServiceException(
505 				"Service not initialised"
506 				) ;
507 			}
508 		}
509 
510 	/***
511 	 * Get the local meta data information for a file.
512 	 * @param ident The internal identifier of the target file.
513 	 * @return An array of FileProperties describing the data.
514 	 * @throws FileStoreIdentifierException if the identifier is null or not valid.
515 	 * @throws FileStoreNotFoundException if unable to locate the file.
516 	 * @throws FileStoreServiceException if unable handle the request.
517 	 *
518 	 */
519 	public FileProperty[] properties(String ident)
520 		throws FileStoreServiceException, FileStoreIdentifierException, FileStoreNotFoundException
521 		{
522 		if (null != service)
523 			{
524 			try {
525 				return service.properties(ident) ;
526 				}
527 			catch (RemoteException ouch)
528 				{
529 				//
530 				// Unpack the expected Exception(s).
531 				serviceException(ouch) ;
532 				notfoundException(ouch) ;
533 				identifierException(ouch) ;
534 				//
535 				// If we get this far, then we don't know what it is.
536 				throw new FileStoreServiceException(
537 					"WebService call failed - " + ouch,
538 					ouch
539 					) ;
540 				}
541 			}
542 		else {
543 			throw new FileStoreServiceException(
544 				"Service not initialised"
545 				) ;
546 			}
547 		}
548 
549 	/***
550 	 * Prepare to receive a file from a remote source.
551 	 * @param transfer A TransferProperties object describing the transfer.
552 	 * @return A new TransferProperties describing the transfer.
553 	 * @throws FileStoreTransferException If the transfer properties are not valid.
554 	 * @throws FileStoreServiceException if unable handle the request.
555 	 *
556 	 */
557 	public TransferProperties importInit(TransferProperties transfer)
558 		throws FileStoreServiceException, FileStoreTransferException
559 		{
560 		if (null != service)
561 			{
562 			try {
563 				return service.importInit(transfer) ;
564 				}
565 			catch (RemoteException ouch)
566 				{
567 				//
568 				// Unpack the expected Exception(s).
569 				serviceException(ouch);
570 				transferException(ouch);
571 				//
572 				// If we get this far, then we don't know what it is.
573 				throw new FileStoreServiceException(
574 					"WebService call failed - " + ouch,
575 					ouch
576 					) ;
577 				}
578 			}
579 		else {
580 			throw new FileStoreServiceException(
581 				"Service not initialised"
582 				) ;
583 			}
584 		}
585 
586 	/***
587 	 * Import a file from a remote source.
588 	 * @param transfer A TransferProperties object describing the transfer.
589 	 * @return A new TransferProperties describing the transfer.
590 	 * @throws FileStoreServiceException if unable handle the request.
591 	 * @throws FileStoreTransferException if the transfer properties are null.
592 	 *
593 	 */
594 	public TransferProperties importData(TransferProperties transfer)
595 		throws FileStoreTransferException, FileStoreServiceException
596 		{
597 		if (null != service)
598 			{
599 			try {
600 				return service.importData(transfer) ;
601 				}
602 			catch (RemoteException ouch)
603 				{
604 				//
605 				// Unpack the expected Exception(s).
606 				serviceException(ouch) ;
607 				transferException(ouch) ;
608 				//
609 				// If we get this far, then we don't know what it is.
610 				throw new FileStoreServiceException(
611 					"WebService call failed - " + ouch,
612 					ouch
613 					) ;
614 				}
615 			}
616 		else {
617 			throw new FileStoreServiceException(
618 				"Service not initialised"
619 				) ;
620 			}
621 		}
622 
623 	/***
624 	 * Prepare to send a file to a remote destination.
625 	 * @param transfer A TransferProperties object describing the transfer.
626 	 * @return A new TransferProperties describing the transfer.
627 	 * @throws FileStoreTransferException if the transfer properties are null.
628 	 * @throws FileStoreNotFoundException If unable to locate the target object.
629 	 * @throws FileStoreServiceException if unable handle the request.
630 	 *
631 	 */
632 	public TransferProperties exportInit(TransferProperties transfer)
633 		throws FileStoreNotFoundException, FileStoreTransferException, FileStoreServiceException
634 		{
635 		if (null != service)
636 			{
637 			try {
638 				return service.exportInit(transfer) ;
639 				}
640 			catch (RemoteException ouch)
641 				{
642 				//
643 				// Unpack the expected Exception(s).
644 				serviceException(ouch) ;
645 				transferException(ouch) ;
646 				notfoundException(ouch) ;
647 				//
648 				// If we get this far, then we don't know what it is.
649 				throw new FileStoreServiceException(
650 					"WebService call failed - " + ouch,
651 					ouch
652 					) ;
653 				}
654 			}
655 		else {
656 			throw new FileStoreServiceException(
657 				"Service not initialised"
658 				) ;
659 			}
660 		}
661 
662 	/***
663 	 * Export a file to a remote destination.
664 	 * @param transfer A TransferProperties object describing the transfer.
665 	 * @return A new TransferProperties describing the transfer.
666 	 * @throws FileStoreServiceException if unable handle the request.
667 	 *
668 	 */
669 	public TransferProperties exportData(TransferProperties transfer)
670 		throws FileStoreServiceException
671 		{
672 		if (null != service)
673 			{
674 			try {
675 				return service.exportData(transfer) ;
676 				}
677 			catch (RemoteException ouch)
678 				{
679 				//
680 				// Unpack the expected Exception(s).
681 				serviceException(ouch) ;
682 				//
683 				// If we get this far, then we don't know what it is.
684 				throw new FileStoreServiceException(
685 					"WebService call failed - " + ouch,
686 					ouch
687 					) ;
688 				}
689 			}
690 		else {
691 			throw new FileStoreServiceException(
692 				"Service not initialised"
693 				) ;
694 			}
695 		}
696 
697 	/***
698 	 * A converter utility to unpack a FileStoreException from a RemoteException.
699 	 * @throws FileStoreException If the RemoteException cause was a FileStoreException.
700 	 *
701 	 */
702 	public void filestoreException(RemoteException ouch)
703 		throws FileStoreException
704 		{
705 		log.debug("----") ;
706 		log.debug("FileStoreCoreDelegate.filestoreException") ;
707 		log.debug("  Exception : " + ouch) ;
708 		log.debug("  Type      : " + ouch.getClass()) ;
709 		log.debug("  Cause     : " + ouch.getCause()) ;
710 		//
711 		// If we have the original Exception.
712 		if (ouch.getCause() != null)
713 			{
714 			log.debug("  Got cause") ;
715 			if (ouch.getCause() instanceof FileStoreException)
716 				{
717 				throw (FileStoreException) ouch.getCause() ;
718 				}
719 			}
720 		//
721 		// If we don't have the original Exception.
722 		else {
723 			log.debug("  Null cause") ;
724 			//
725 			// If the message starts with our class name.
726 			String message  = ouch.getMessage() ;
727 			String template = FileStoreException.class.getName() + ": " ;
728 			log.debug("  Message  : '" + message  + "'") ;
729 			log.debug("  Template : '" + template + "'") ;
730 			if (null != message)
731 				{
732 				if (message.startsWith(template))
733 					{
734 					log.debug("  Matches template") ;
735 					throw new FileStoreException(
736 						message.substring(
737 							template.length()
738 							)
739 						) ;
740 					}
741 				}
742 			}
743 		log.debug("  Not handled") ;
744 		}
745 
746 	/***
747 	 * A converter utility to unpack a FileStoreNotFoundException from a RemoteException.
748 	 * @throws FileStoreNotFoundException If the RemoteException cause was a FileStoreNotFoundException.
749 	 *
750 	 */
751 	public void notfoundException(RemoteException ouch)
752 		throws FileStoreNotFoundException
753 		{
754 		log.debug("----") ;
755 		log.debug("FileStoreCoreDelegate.notfoundException") ;
756 		log.debug("  Exception : " + ouch) ;
757 		log.debug("  Type      : " + ouch.getClass()) ;
758 		log.debug("  Cause     : " + ouch.getCause()) ;
759 		//
760 		// If we have the original Exception.
761 		if (ouch.getCause() != null)
762 			{
763 			log.debug("  Got cause") ;
764 			if (ouch.getCause() instanceof FileStoreNotFoundException)
765 				{
766 				throw (FileStoreNotFoundException) ouch.getCause() ;
767 				}
768 			}
769 		//
770 		// If we don't have the original Exception.
771 		else {
772 			log.debug("  Null cause") ;
773 			//
774 			// If the message starts with our class name.
775 			String message  = ouch.getMessage() ;
776 			String template = FileStoreNotFoundException.class.getName() + ": " ;
777 			log.debug("  Message  : '" + message  + "'") ;
778 			log.debug("  Template : '" + template + "'") ;
779 			if (null != message)
780 				{
781 				if (message.startsWith(template))
782 					{
783 					log.debug("  Matches template") ;
784 					throw new FileStoreNotFoundException(
785 						message.substring(
786 							template.length()
787 							)
788 						) ;
789 					}
790 				}
791 			}
792 		log.debug("  Not handled") ;
793 		}
794 
795 	/***
796 	 * A converter utility to unpack a FileStoreIdentifierException from a RemoteException.
797 	 * @throws FileStoreIdentifierException If the RemoteException cause was a FileStoreIdentifierException.
798 	 *
799 	 */
800 	public void identifierException(RemoteException ouch)
801 		throws FileStoreIdentifierException
802 		{
803 		log.debug("----") ;
804 		log.debug("FileStoreCoreDelegate.identifierException") ;
805 		log.debug("  Exception : " + ouch) ;
806 		log.debug("  Type      : " + ouch.getClass()) ;
807 		log.debug("  Cause     : " + ouch.getCause()) ;
808 		//
809 		// If we have the original Exception.
810 		if (ouch.getCause() != null)
811 			{
812 			log.debug("  Got cause") ;
813 			if (ouch.getCause() instanceof FileStoreIdentifierException)
814 				{
815 				throw (FileStoreIdentifierException) ouch.getCause() ;
816 				}
817 			}
818 		//
819 		// If we don't have the original Exception.
820 		else {
821 			log.debug("  Null cause") ;
822 			//
823 			// If the message starts with our class name.
824 			String message  = ouch.getMessage() ;
825 			String template = FileStoreIdentifierException.class.getName() + ": " ;
826 			log.debug("  Message  : '" + message  + "'") ;
827 			log.debug("  Template : '" + template + "'") ;
828 			if (null != message)
829 				{
830 				if (message.startsWith(template))
831 					{
832 					log.debug("  Matches template") ;
833 					throw new FileStoreIdentifierException(
834 						message.substring(
835 							template.length()
836 							)
837 						) ;
838 					}
839 				}
840 			}
841 		log.debug("  Not handled") ;
842 		}
843 
844 	/***
845 	 * A converter utility to unpack a FileStoreServiceException from a RemoteException.
846 	 * @throws FileStoreServiceException If the RemoteException cause was a FileStoreServiceException.
847 	 *
848 	 */
849 	public void serviceException(RemoteException ouch)
850 		throws FileStoreServiceException
851 		{
852 		log.debug("----") ;
853 		log.debug("FileStoreCoreDelegate.serviceException") ;
854 		log.debug("  Exception : " + ouch) ;
855 		log.debug("  Type      : " + ouch.getClass()) ;
856 		log.debug("  Cause     : " + ouch.getCause()) ;
857 		//
858 		// If we have the original Exception.
859 		if (ouch.getCause() != null)
860 			{
861 			log.debug("  Got cause") ;
862 			if (ouch.getCause() instanceof FileStoreServiceException)
863 				{
864 				throw (FileStoreServiceException) ouch.getCause() ;
865 				}
866 			}
867 		//
868 		// If we don't have the original Exception.
869 		else {
870 			log.debug("  Null cause") ;
871 			//
872 			// If the message starts with our class name.
873 			String message  = ouch.getMessage() ;
874 			String template = FileStoreServiceException.class.getName() + ": " ;
875 			log.debug("  Message  : '" + message  + "'") ;
876 			log.debug("  Template : '" + template + "'") ;
877 			if (null != message)
878 				{
879 				if (message.startsWith(template))
880 					{
881 					log.debug("  Matches template") ;
882 					throw new FileStoreServiceException(
883 						message.substring(
884 							template.length()
885 							)
886 						) ;
887 					}
888 				}
889 			}
890 		log.debug("  Not handled") ;
891 		}
892 
893 	/***
894 	 * Throw a FileStoreIdentifierException, useful for debugging the transfer of Exceptions via SOAP.
895 	 * @throws FileStoreIdentifierException unpacking it from the RemoteException when invoked via a SOAP call.
896 	 * @throws FileStoreServiceException if the service was unable to handle the request.
897 	 *
898 	 */
899 	public void throwIdentifierException()
900 		throws FileStoreIdentifierException, FileStoreServiceException
901 		{
902 		if (null != service)
903 			{
904 			try {
905 				service.throwIdentifierException() ;
906 				}
907 			catch (RemoteException ouch)
908 				{
909 				//
910 				// Unpack the expected Exception(s).
911 				identifierException(ouch) ;
912 				//
913 				// If we get this far, then we don't know what it is.
914 				throw new FileStoreServiceException(
915 					"WebService call failed - " + ouch,
916 					ouch
917 					) ;
918 				}
919 			}
920 		else {
921 			throw new FileStoreServiceException(
922 				"Service not initialised"
923 				) ;
924 			}
925 		}
926 
927 	/***
928 	 * A converter utility to unpack a FileStoreTransferException from a RemoteException.
929 	 * @throws FileStoreTransferException If the RemoteException cause was a FileStoreTransferException.
930 	 *
931 	 */
932 	public void transferException(RemoteException ouch)
933 		throws FileStoreTransferException
934 		{
935 		log.debug("----") ;
936 		log.debug("FileStoreCoreDelegate.transferException") ;
937 		log.debug("  Exception : " + ouch) ;
938 		log.debug("  Type      : " + ouch.getClass()) ;
939 		log.debug("  Cause     : " + ouch.getCause()) ;
940 		//
941 		// If we have the original Exception.
942 		if (ouch.getCause() != null)
943 			{
944 			log.debug("  Got cause") ;
945 			if (ouch.getCause() instanceof FileStoreTransferException)
946 				{
947 				throw (FileStoreTransferException) ouch.getCause() ;
948 				}
949 			}
950 		//
951 		// If we don't have the original Exception.
952 		else {
953 			log.debug("  Null cause") ;
954 			//
955 			// If the message starts with our class name.
956 			String message  = ouch.getMessage() ;
957 			String template = FileStoreTransferException.class.getName() + ": " ;
958 			log.debug("  Message  : '" + message  + "'") ;
959 			log.debug("  Template : '" + template + "'") ;
960 			if (null != message)
961 				{
962 				if (message.startsWith(template))
963 					{
964 					log.debug("  Matches template") ;
965 					throw new FileStoreTransferException(
966 						message.substring(
967 							template.length()
968 							)
969 						) ;
970 					}
971 				}
972 			}
973 		log.debug("  Not handled") ;
974 		}
975 
976 	}
977