View Javadoc

1   /*
2    * <cvs:source>$Source: /devel/astrogrid/filemanager/client/src/java/org/astrogrid/filemanager/client/delegate/FileManagerCoreDelegate.java,v $</cvs:source>
3    * <cvs:author>$Author: clq2 $</cvs:author>
4    * <cvs:date>$Date: 2005/01/28 10:43:58 $</cvs:date>
5    * <cvs:version>$Revision: 1.2 $</cvs:version>
6    * <cvs:log>
7    *   $Log: FileManagerCoreDelegate.java,v $
8    *   Revision 1.2  2005/01/28 10:43:58  clq2
9    *   dave_dev_200501141257 (filemanager)
10   *
11   *   Revision 1.1.2.1  2005/01/22 07:54:16  dave
12   *   Refactored delegate into a separate package ....
13   *
14   *   Revision 1.4  2005/01/13 17:23:15  jdt
15   *   merges from dave-dev-200412201250
16   *
17   *   Revision 1.3.4.3  2005/01/12 14:20:57  dave
18   *   Replaced tabs with spaces ....
19   *
20   *   Revision 1.3.4.2  2005/01/07 12:17:59  dave
21   *   Added StoreClientWrapperTest
22   *   Added StoreFileWrapper
23   *
24   *   Revision 1.3.4.1  2004/12/22 07:38:36  dave
25   *   Started to move towards StoreClient API ...
26   *
27   *   Revision 1.3  2004/12/16 17:25:49  jdt
28   *   merge from dave-dev-200410061224-200412161312
29   *
30   *   Revision 1.1.2.13  2004/12/13 10:07:15  dave
31   *   Fixed copy tests for delegate ...
32   *
33   *   Revision 1.1.2.12  2004/12/10 05:21:25  dave
34   *   Added node and iterator to client API ...
35   *
36   *   Revision 1.1.2.11  2004/12/08 17:54:54  dave
37   *   Added update to FileManager client and server side ...
38   *
39   *   Revision 1.1.2.10  2004/12/03 13:27:52  dave
40   *   Core of internal move is in place ....
41   *
42   *   Revision 1.1.2.9  2004/12/02 19:11:54  dave
43   *   Added move name and parent to manager ...
44   *
45   *   Revision 1.1.2.8  2004/11/29 18:05:07  dave
46   *   Refactored methods names ....
47   *   Added stubs for delete, copy and move.
48   *
49   *   Revision 1.1.2.7  2004/11/24 16:15:08  dave
50   *   Added node functions to client ...
51   *
52   *   Revision 1.1.2.6  2004/11/18 14:39:32  dave
53   *   Added SOAP delegate, RemoteException decoding and test case.
54   *
55   *   Revision 1.1.2.5  2004/11/17 07:56:33  dave
56   *   Added server mock and webapp build scripts ...
57   *
58   *   Revision 1.1.2.4  2004/11/16 07:56:08  dave
59   *   Added last set of tests for delegate ....
60   *
61   *   Revision 1.1.2.3  2004/11/16 06:22:20  dave
62   *   Added tests for child nodes and paths ...
63   *
64   *   Revision 1.1.2.2  2004/11/16 03:26:14  dave
65   *   Added initial tests for adding accounts, containers and files ...
66   *
67   *   Revision 1.1.2.1  2004/11/13 01:41:26  dave
68   *   Created initial client API ....
69   *
70   * </cvs:log>
71   *
72   */
73  package org.astrogrid.filemanager.client.delegate ;
74  
75  import java.util.List ;
76  import java.util.Arrays ;
77  import java.util.ArrayList ;
78  import java.util.Iterator ;
79  import java.util.Collections ;
80  
81  import java.rmi.RemoteException ;
82  import java.net.URISyntaxException;
83  
84  import org.apache.commons.logging.Log ;
85  import org.apache.commons.logging.LogFactory ;
86  
87  import org.astrogrid.store.Ivorn ;
88  
89  import org.astrogrid.filestore.common.file.FileProperty;
90  import org.astrogrid.filestore.common.transfer.TransferProperties;
91  
92  import org.astrogrid.filemanager.common.FileManager;
93  import org.astrogrid.filemanager.common.FileManagerProperties;
94  
95  import org.astrogrid.filemanager.common.exception.NodeNotFoundException ;
96  import org.astrogrid.filemanager.common.exception.DuplicateNodeException;
97  import org.astrogrid.filemanager.common.exception.FileManagerIdentifierException;
98  import org.astrogrid.filemanager.common.exception.FileManagerServiceException;
99  import org.astrogrid.filemanager.common.exception.FileManagerPropertiesException;
100 
101 import org.astrogrid.filemanager.client.FileManagerNode;
102 
103 /***
104  * The core implementation for the FileManager delegate.
105  *
106  */
107 public class FileManagerCoreDelegate
108     implements FileManagerDelegate
109     {
110 
111     /***
112      * Our debug logger.
113      *
114      */
115     protected static Log log = LogFactory.getLog(FileManagerCoreDelegate.class);
116 
117     /***
118      * Reference to our FileManager service.
119      *
120      */
121     protected FileManager manager ;
122 
123     /***
124      * Protected constructor, for a FileManager service.
125      *
126      */
127     protected FileManagerCoreDelegate(FileManager manager)
128         {
129         if (null == manager)
130             {
131             throw new IllegalArgumentException(
132                 "Null manager reference"
133                 );
134             }
135         this.manager = manager ;
136         }
137 
138     /***
139      * Get the manager identifier.
140      * @return The manager ivorn identifier.
141      * @throws FileManagerServiceException If a problem occurs when handling the request. 
142      *
143      */
144     public Ivorn getServiceIvorn()
145         throws FileManagerServiceException
146         {
147         log.debug("");
148         log.debug("FileManagerCoreDelegate.getServiceIvorn()");
149         try {
150             Ivorn ivorn = new Ivorn(
151                 manager.getIdentifier()
152                 ) ;
153             log.debug("  Ivorn : " + ivorn.toString());
154             return ivorn ;
155             }
156         catch (URISyntaxException ouch)
157             {
158             throw new FileManagerServiceException(
159                 "Unable to parse service ivorn"
160                 ) ;
161             }
162         catch (RemoteException ouch)
163             {
164             //
165             // Look for the expected exceptions.
166             serviceException(ouch);
167             //
168             // Throw a generic service exception.
169             throw new FileManagerServiceException(
170                 "Error occurred in WebService call",
171                 ouch
172                 ) ;
173             }
174         }
175 
176     /***
177      * Create a node from an array of properties.
178      * @param properties The node properties.
179      * @return A new FileManagerNode constructed from the properties.
180      * @todo Distinguish between the node types ....
181      *
182      */
183     protected FileManagerNode node(FileProperty[] properties)
184         {
185         return new FileManagerDelegateNode(
186             this,
187             properties
188             );
189         }
190 
191     /***
192      * Create a node for a new account.
193      * @param ivorn The ivorn identifier for the account.
194      * @return A node representing the account home.
195      * @throws DuplicateNodeException If the the account already exists.
196      * @throws FileManagerServiceException If a problem occurs when handling the request. 
197      *
198      */
199     public FileManagerNode addAccount(Ivorn ivorn)
200         throws FileManagerServiceException, DuplicateNodeException
201         {
202         if (null == ivorn)
203             {
204             throw new IllegalArgumentException(
205                 "Null account identifier"
206                 );
207             }
208         try {
209             return this.node(
210                 manager.addAccount(
211                     ivorn.toString()
212                     )
213                 );
214             }
215         catch (RemoteException ouch)
216             {
217             //
218             // Look for the expected exceptions.
219             serviceException(ouch);
220             duplicateNodeException(ouch);
221             //
222             // Throw a generic service exception.
223             throw new FileManagerServiceException(
224                 "Error occurred in WebService call",
225                 ouch
226                 ) ;
227             }
228         }
229 
230     /***
231      * Get the root node for an account
232      * @param ivorn The identifier of the account.
233      * @return An new node for the account home.
234      * @throws NodeNotFoundException If the account does not exist.
235      * @throws FileManagerServiceException If a problem occurs when handling the request. 
236      *
237      */
238     public FileManagerNode getAccount(Ivorn ivorn)
239         throws FileManagerServiceException, NodeNotFoundException
240         {
241         if (null == ivorn)
242             {
243             throw new IllegalArgumentException(
244                 "Null account identifier"
245                 );
246             }
247         try {
248             return this.node(
249                 manager.getAccount(
250                     ivorn.toString()
251                     )
252                 );
253             }
254         catch (RemoteException ouch)
255             {
256             //
257             // Look for the expected exceptions.
258             serviceException(ouch);
259             nodeNotFoundException(ouch);
260             //
261             // Throw a generic service exception.
262             throw new FileManagerServiceException(
263                 "Error occurred in WebService call",
264                 ouch
265                 ) ;
266             }
267         }
268 
269     /***
270      * Add a new child node.
271      * @param name The node name.
272      * @param type The node type (either FILE_NODE or CONTAINER_NODE).
273      * @return A new node for the container.
274      * @throws UnsupportedOperationException If this node represents a file.
275      * @throws DuplicateNodeException If a node with the same name already exists.
276      * @throws NodeNotFoundException If the current node is no longer in the database.
277      * @throws FileManagerServiceException If a problem occurs when handling the request.
278      * @see FILE_NODE
279      * @see CONTAINER_NODE
280      *
281      */
282     protected FileManagerNode add(FileManagerNode parent, String name, String type)
283         throws UnsupportedOperationException, DuplicateNodeException, NodeNotFoundException, FileManagerServiceException, FileManagerIdentifierException 
284         {
285         if (null == parent)
286             {
287             throw new IllegalArgumentException(
288                 "Null parent node"
289                 );
290             }
291         if (null == parent.ivorn())
292             {
293             throw new IllegalArgumentException(
294                 "Null parent identifier"
295                 );
296             }
297         if (null == name)
298             {
299             throw new IllegalArgumentException(
300                 "Null node name"
301                 );
302             }
303         if (null == type)
304             {
305             throw new IllegalArgumentException(
306                 "Null node type"
307                 );
308             }
309         //
310         // Check the parent is a container.
311         if (parent.isContainer())
312             {
313             //
314             // Try to create the node.
315             try {
316                 return this.node(
317                     manager.addNode(
318                         parent.ivorn().toString(),
319                         name,
320                         type
321                         )
322                     ) ;
323                 }
324             catch (RemoteException ouch)
325                 {
326                 //
327                 // Look for the expected exceptions.
328                 serviceException(ouch);
329                 identifierException(ouch);
330                 duplicateNodeException(ouch);
331                 nodeNotFoundException(ouch);
332                 //
333                 // Throw a generic service exception.
334                 throw new FileManagerServiceException(
335                     "Error occurred in WebService call",
336                     ouch
337                     ) ;
338                 }
339             }
340         //
341         // If the parent is not a container.
342         else {
343             throw new UnsupportedOperationException(
344                 "Parent node is not a container"
345                 );
346             }
347         }
348 
349     /***
350      * Get a specific node, indexed by ident.
351      * @param ivorn The node identifier.
352      * @return The node specified by the identifier.
353      * @throws FileManagerIdentifierException If the node identifier is invalid.
354      * @throws NodeNotFoundException If the node does not exist.
355      * @throws FileManagerServiceException If a problem occurs when handling the request. 
356      *
357      */
358     public FileManagerNode getNode(Ivorn ivorn)
359         throws FileManagerServiceException, FileManagerIdentifierException, NodeNotFoundException
360         {
361         return this.node(
362             this.getProperties(
363                 ivorn
364                 )
365             ) ;
366         }
367 
368     /***
369      * Get the properties for a specific node, indexed by ident.
370      * @param ivorn The node identifier.
371      * @return The array of properties for the node.
372      * @throws FileManagerIdentifierException If the node identifier is invalid.
373      * @throws NodeNotFoundException If the node does not exist.
374      * @throws FileManagerServiceException If a problem occurs when handling the request. 
375      *
376      */
377     public FileProperty[] getProperties(Ivorn ivorn)
378         throws FileManagerServiceException, FileManagerIdentifierException, NodeNotFoundException
379         {
380         if (null == ivorn)
381             {
382             throw new IllegalArgumentException(
383                 "Null identifier"
384                 );
385             }
386         try {
387             return manager.getNode(
388                 ivorn.toString()
389                 );
390             }
391         catch (RemoteException ouch)
392             {
393             //
394             // Look for the expected exceptions.
395             serviceException(ouch);
396             identifierException(ouch);
397             nodeNotFoundException(ouch);
398             //
399             // Throw a generic service exception.
400             throw new FileManagerServiceException(
401                 "Error occurred in WebService call",
402                 ouch
403                 ) ;
404             }
405         }
406 
407     /***
408      * Get a specific child node, indexed by path.
409      * @param node The parent node.
410      * @param path  The target node path.
411      * @return The node specified by the path.
412      * @throws FileManagerIdentifierException If the node identifier is invalid.
413      * @throws NodeNotFoundException If the node does not exist.
414      * @throws FileManagerServiceException If a problem occurs when handling the request. 
415      *
416      */
417     protected FileManagerNode getChild(FileManagerNode node, String path)
418         throws FileManagerServiceException, FileManagerIdentifierException, NodeNotFoundException
419         {
420         if (null == node)
421             {
422             throw new IllegalArgumentException(
423                 "Null parent node"
424                 );
425             }
426         return getChild(
427             node.ivorn(),
428             path
429             );
430         }
431 
432     /***
433      * Get a specific child node, indexed by path.
434      * @param ivorn The identifier of the parent node.
435      * @param path  The target node path.
436      * @return The node specified by the path.
437      * @throws FileManagerIdentifierException If the node identifier is invalid.
438      * @throws NodeNotFoundException If the node does not exist.
439      * @throws FileManagerServiceException If a problem occurs when handling the request. 
440      *
441      */
442     protected FileManagerNode getChild(Ivorn ivorn, String path)
443         throws FileManagerServiceException, FileManagerIdentifierException, NodeNotFoundException
444         {
445         if (null == ivorn)
446             {
447             throw new IllegalArgumentException(
448                 "Null parent identifier"
449                 );
450             }
451         if (null == path)
452             {
453             throw new IllegalArgumentException(
454                 "Null path"
455                 );
456             }
457         try {
458             return this.node(
459                 manager.getChild(
460                     ivorn.toString(),
461                     path
462                     )
463                 );
464             }
465         catch (RemoteException ouch)
466             {
467             //
468             // Look for the expected exceptions.
469             serviceException(ouch);
470             identifierException(ouch);
471             nodeNotFoundException(ouch);
472             //
473             // Throw a generic service exception.
474             throw new FileManagerServiceException(
475                 "Error occurred in WebService call",
476                 ouch
477                 ) ;
478             }
479         }
480 
481     /***
482      * Get the children of a specific node.
483      * @param ivorn The identifier of the parent node.
484      * @return A List of Ivorns for the child nodes.
485      * @throws FileManagerIdentifierException If the node identifier is invalid.
486      * @throws NodeNotFoundException If the parent node does not exist.
487      * @throws FileManagerServiceException If a problem occurs when handling the request. 
488      * @todo Change this to return a list of the child ivorn(s) ... or 'child' objects (name, ivorn, type).
489      *
490      */
491     protected List getChildren(Ivorn ivorn)
492         throws FileManagerServiceException, FileManagerIdentifierException, NodeNotFoundException
493         {
494         if (null == ivorn)
495             {
496             throw new IllegalArgumentException(
497                 "Null identifier"
498                 );
499             }
500         try {
501             List ivorns  = new ArrayList();
502             List strings = Arrays.asList(
503                 manager.getChildren(
504                     ivorn.toString()
505                     )
506                 );
507             Iterator iter = strings.iterator();
508             while (iter.hasNext())
509                 {
510                 try {
511                     ivorns.add(
512                         new Ivorn(
513                             (String) iter.next()
514                             )
515                         );
516                     }
517                 catch (URISyntaxException ouch)
518                     {
519                     throw new FileManagerServiceException(
520                         "Unable to parse node ivorn"
521                         ) ;
522                     }
523                 }
524             return Collections.unmodifiableList(
525                 ivorns
526                 );
527             }
528         catch (RemoteException ouch)
529             {
530             //
531             // Look for the expected exceptions.
532             serviceException(ouch);
533             identifierException(ouch);
534             nodeNotFoundException(ouch);
535             //
536             // Throw a generic service exception.
537             throw new FileManagerServiceException(
538                 "Error occurred in WebService call",
539                 ouch
540                 ) ;
541             }
542         }
543 
544     /***
545      * Initialise a data transfer into a FileStore.
546      * @param request The request properties.
547      * @throws NodeNotFoundException If the target node does not exist.
548      * @throws FileManagerServiceException If the service is unable to handle the request.
549      * @throws FileManagerPropertiesException If the required properties are incomplete.
550      *
551      */
552     protected TransferProperties importInit(FileManagerProperties request)
553         throws FileManagerServiceException, FileManagerPropertiesException, NodeNotFoundException
554         {
555         if (null == request)
556             {
557             throw new IllegalArgumentException(
558                 "Null request properties"
559                 );
560             }
561         try {
562             return manager.importInit(
563                 request.toArray()
564                 );
565             }
566         catch (RemoteException ouch)
567             {
568             //
569             // Look for the expected exceptions.
570             serviceException(ouch);
571             propertiesException(ouch);
572             nodeNotFoundException(ouch);
573             //
574             // Throw a generic service exception.
575             throw new FileManagerServiceException(
576                 "Error occurred in WebService call",
577                 ouch
578                 ) ;
579             }
580         }
581 
582     /***
583      * Initialise a data transfer from a FileStore.
584      * @param request The request properties.
585      * @throws NodeNotFoundException If the target node does not exist.
586      * @throws FileManagerServiceException If the service is unable to handle the request.
587      * @throws FileManagerPropertiesException If the required properties are incomplete.
588      *
589      */
590     protected TransferProperties exportInit(FileManagerProperties request)
591         throws FileManagerServiceException, FileManagerPropertiesException, NodeNotFoundException
592         {
593         if (null == request)
594             {
595             throw new IllegalArgumentException(
596                 "Null request properties"
597                 );
598             }
599         try {
600             return manager.exportInit(
601                 request.toArray()
602                 );
603             }
604         catch (RemoteException ouch)
605             {
606             //
607             // Look for the expected exceptions.
608             serviceException(ouch);
609             propertiesException(ouch);
610             nodeNotFoundException(ouch);
611             //
612             // Throw a generic service exception.
613             throw new FileManagerServiceException(
614                 "Error occurred in WebService call",
615                 ouch
616                 ) ;
617             }
618         }
619 
620     /***
621      * A converter utility to unpack a FileStoreServiceException from a RemoteException.
622      * @throws FileStoreServiceException If the RemoteException cause was a FileStoreServiceException.
623      *
624      */
625     public void serviceException(RemoteException ouch)
626         throws FileManagerServiceException
627         {
628         log.debug("----") ;
629         log.debug("FileManagerCoreDelegate.serviceException") ;
630         log.debug("  Exception : " + ouch) ;
631         log.debug("  Type      : " + ouch.getClass()) ;
632         log.debug("  Cause     : " + ouch.getCause()) ;
633         //
634         // If we have the original Exception.
635         if (ouch.getCause() != null)
636             {
637             log.debug("  Got cause") ;
638             if (ouch.getCause() instanceof FileManagerServiceException)
639                 {
640                 throw (FileManagerServiceException) ouch.getCause() ;
641                 }
642             }
643         //
644         // If we don't have the original Exception.
645         else {
646             log.debug("  Null cause") ;
647             //
648             // If the message starts with our class name.
649             String message  = ouch.getMessage() ;
650             String template = FileManagerServiceException.class.getName() + ": " ;
651             log.debug("  Message  : '" + message  + "'") ;
652             log.debug("  Template : '" + template + "'") ;
653             if (null != message)
654                 {
655                 if (message.startsWith(template))
656                     {
657                     log.debug("  Matches template") ;
658                     throw new FileManagerServiceException(
659                         message.substring(
660                             template.length()
661                             )
662                         ) ;
663                     }
664                 }
665             }
666         log.debug("  Not handled") ;
667         }
668 
669     /***
670      * A converter utility to unpack a NodeNotFoundException from a RemoteException.
671      * @throws NodeNotFoundException If the RemoteException cause was a NodeNotFoundException.
672      *
673      */
674     public void nodeNotFoundException(RemoteException ouch)
675         throws NodeNotFoundException
676         {
677         log.debug("----") ;
678         log.debug("FileManagerCoreDelegate.nodeNotFoundException") ;
679         log.debug("  Exception : " + ouch) ;
680         log.debug("  Type      : " + ouch.getClass()) ;
681         log.debug("  Cause     : " + ouch.getCause()) ;
682         //
683         // If we have the original Exception.
684         if (ouch.getCause() != null)
685             {
686             log.debug("  Got cause") ;
687             if (ouch.getCause() instanceof NodeNotFoundException)
688                 {
689                 throw (NodeNotFoundException) ouch.getCause() ;
690                 }
691             }
692         //
693         // If we don't have the original Exception.
694         else {
695             log.debug("  Null cause") ;
696             //
697             // If the message starts with our class name.
698             String message  = ouch.getMessage() ;
699             String template = NodeNotFoundException.class.getName() + ": " ;
700             log.debug("  Message  : '" + message  + "'") ;
701             log.debug("  Template : '" + template + "'") ;
702             if (null != message)
703                 {
704                 if (message.startsWith(template))
705                     {
706                     log.debug("  Matches template") ;
707                     throw new NodeNotFoundException(
708                         message.substring(
709                             template.length()
710                             )
711                         ) ;
712                     }
713                 }
714             }
715         log.debug("  Not handled") ;
716         }
717 
718     /***
719      * A converter utility to unpack a NodeNotFoundException from a RemoteException.
720      * @throws NodeNotFoundException If the RemoteException cause was a NodeNotFoundException.
721      *
722      */
723     public void duplicateNodeException(RemoteException ouch)
724         throws DuplicateNodeException
725         {
726         log.debug("----") ;
727         log.debug("FileManagerCoreDelegate.duplicateNodeException") ;
728         log.debug("  Exception : " + ouch) ;
729         log.debug("  Type      : " + ouch.getClass()) ;
730         log.debug("  Cause     : " + ouch.getCause()) ;
731         //
732         // If we have the original Exception.
733         if (ouch.getCause() != null)
734             {
735             log.debug("  Got cause") ;
736             if (ouch.getCause() instanceof DuplicateNodeException)
737                 {
738                 throw (DuplicateNodeException) ouch.getCause() ;
739                 }
740             }
741         //
742         // If we don't have the original Exception.
743         else {
744             log.debug("  Null cause") ;
745             //
746             // If the message starts with our class name.
747             String message  = ouch.getMessage() ;
748             String template = DuplicateNodeException.class.getName() + ": " ;
749             log.debug("  Message  : '" + message  + "'") ;
750             log.debug("  Template : '" + template + "'") ;
751             if (null != message)
752                 {
753                 if (message.startsWith(template))
754                     {
755                     log.debug("  Matches template") ;
756                     throw new DuplicateNodeException(
757                         message.substring(
758                             template.length()
759                             )
760                         ) ;
761                     }
762                 }
763             }
764         log.debug("  Not handled") ;
765         }
766 
767     /***
768      * A converter utility to unpack a FileManagerIdentifierException from a RemoteException.
769      * @throws FileManagerIdentifierException If the RemoteException cause was a FileManagerIdentifierException.
770      *
771      */
772     public void identifierException(RemoteException ouch)
773         throws FileManagerIdentifierException
774         {
775         log.debug("----") ;
776         log.debug("FileManagerCoreDelegate.identifierException") ;
777         log.debug("  Exception : " + ouch) ;
778         log.debug("  Type      : " + ouch.getClass()) ;
779         log.debug("  Cause     : " + ouch.getCause()) ;
780         //
781         // If we have the original Exception.
782         if (ouch.getCause() != null)
783             {
784             log.debug("  Got cause") ;
785             if (ouch.getCause() instanceof FileManagerIdentifierException)
786                 {
787                 throw (FileManagerIdentifierException) ouch.getCause() ;
788                 }
789             }
790         //
791         // If we don't have the original Exception.
792         else {
793             log.debug("  Null cause") ;
794             //
795             // If the message starts with our class name.
796             String message  = ouch.getMessage() ;
797             String template = FileManagerIdentifierException.class.getName() + ": " ;
798             log.debug("  Message  : '" + message  + "'") ;
799             log.debug("  Template : '" + template + "'") ;
800             if (null != message)
801                 {
802                 if (message.startsWith(template))
803                     {
804                     log.debug("  Matches template") ;
805                     throw new FileManagerIdentifierException(
806                         message.substring(
807                             template.length()
808                             )
809                         ) ;
810                     }
811                 }
812             }
813         log.debug("  Not handled") ;
814         }
815 
816     /***
817      * A converter utility to unpack a FileManagerPropertiesException from a RemoteException.
818      * @throws FileManagerPropertiesException If the RemoteException cause was a FileManagerPropertiesException.
819      *
820      */
821     public void propertiesException(RemoteException ouch)
822         throws FileManagerPropertiesException
823         {
824         log.debug("----") ;
825         log.debug("FileManagerCoreDelegate.propertiesException") ;
826         log.debug("  Exception : " + ouch) ;
827         log.debug("  Type      : " + ouch.getClass()) ;
828         log.debug("  Cause     : " + ouch.getCause()) ;
829         //
830         // If we have the original Exception.
831         if (ouch.getCause() != null)
832             {
833             log.debug("  Got cause") ;
834             if (ouch.getCause() instanceof FileManagerPropertiesException)
835                 {
836                 throw (FileManagerPropertiesException) ouch.getCause() ;
837                 }
838             }
839         //
840         // If we don't have the original Exception.
841         else {
842             log.debug("  Null cause") ;
843             //
844             // If the message starts with our class name.
845             String message  = ouch.getMessage() ;
846             String template = FileManagerPropertiesException.class.getName() + ": " ;
847             log.debug("  Message  : '" + message  + "'") ;
848             log.debug("  Template : '" + template + "'") ;
849             if (null != message)
850                 {
851                 if (message.startsWith(template))
852                     {
853                     log.debug("  Matches template") ;
854                     throw new FileManagerPropertiesException(
855                         message.substring(
856                             template.length()
857                             )
858                         ) ;
859                     }
860                 }
861             }
862         log.debug("  Not handled") ;
863         }
864 
865     /***
866      * Move a node to a new location.
867      * If the node already has stored data, then this may involve transfering the data to a new location.
868      * @param request The properties for the move.
869      * @return A new set of properties describing the node.
870      *
871      * @throws DuplicateNodeException If a node with the same name already exists in the metadata tree.
872      * @throws NodeNotFoundException If the current node is no longer in the database.
873      * @throws NodeNotFoundException If the new parent node is no longer in the database.
874      * @throws FileManagerPropertiesException If the transfer properties are incomplete.
875      * @throws FileManagerServiceException If a problem occurs when handling the request.
876      *
877      */
878     protected FileManagerProperties move(FileManagerProperties request)
879         throws DuplicateNodeException, NodeNotFoundException, FileManagerPropertiesException, FileManagerServiceException
880         {
881         if (null == request)
882             {
883             throw new IllegalArgumentException(
884                 "Null request properties"
885                 );
886             }
887         try {
888             return new FileManagerProperties(
889                 manager.move(
890                     request.toArray()
891                     )
892                 );
893             }
894         catch (RemoteException ouch)
895             {
896             //
897             // Look for the expected exceptions.
898             serviceException(ouch);
899             propertiesException(ouch);
900             nodeNotFoundException(ouch);
901             duplicateNodeException(ouch);
902             //
903             // Throw a generic service exception.
904             throw new FileManagerServiceException(
905                 "Error occurred in WebService call",
906                 ouch
907                 ) ;
908             }
909         }
910 
911     /***
912      * Update the properties for a node.
913      * If this node has stored data, this will trigger a call to the FileStore to refresh the data properties.
914      * @param node The node to refresh.
915      * @return A new set of properties describing the node.
916      *
917      * @throws NodeNotFoundException If the node does not exist.
918      * @throws FileManagerIdentifierException If the node identifier is invalid.
919      * @throws FileManagerServiceException If a problem occurs when handling the request. 
920      *
921      */
922     public FileManagerProperties refresh(FileManagerNode node)
923         throws NodeNotFoundException, FileManagerIdentifierException, FileManagerServiceException
924         {
925         log.debug("");
926         log.debug("FileManagerCoreDelegate.refresh()");
927         if (null == node)
928             {
929             throw new IllegalArgumentException(
930                 "Null node"
931                 );
932             }
933         if (null == node.ivorn())
934             {
935             throw new IllegalArgumentException(
936                 "Null node"
937                 );
938             }
939         log.debug("  Node : " + node.ivorn().toString());
940         try {
941             return new FileManagerProperties(
942                 manager.refresh(
943                     node.ivorn().toString()
944                     )
945                 );
946             }
947         catch (RemoteException ouch)
948             {
949             //
950             // Look for the expected exceptions.
951             serviceException(ouch);
952             identifierException(ouch);
953             nodeNotFoundException(ouch);
954             //
955             // Throw a generic service exception.
956             throw new FileManagerServiceException(
957                 "Error occurred in WebService call",
958                 ouch
959                 ) ;
960             }
961         }
962 
963     /***
964      * Create a copy of a node.
965      * If the node already has stored data, then this will create a new copy of the data.
966      * @param  properties The request properties.
967      * @return The new node.
968      * @throws DuplicateNodeException If a node with the same name already exists in the metadata tree.
969      * @throws NodeNotFoundException If the current node is no longer in the database.
970      * @throws NodeNotFoundException If the new parent node is no longer in the database.
971      * @throws FileManagerPropertiesException If the transfer properties are incomplete.
972      * @throws FileManagerServiceException If a problem occurs when handling the request.
973      *
974      */
975     protected FileManagerNode copy(FileManagerProperties request)
976         throws DuplicateNodeException, NodeNotFoundException, FileManagerPropertiesException, FileManagerServiceException
977         {
978         if (null == request)
979             {
980             throw new IllegalArgumentException(
981                 "Null request properties"
982                 );
983             }
984         try {
985             return this.node(
986                 manager.copy(
987                     request.toArray()
988                     )
989                 );
990             }
991         catch (RemoteException ouch)
992             {
993             //
994             // Look for the expected exceptions.
995             serviceException(ouch);
996             propertiesException(ouch);
997             nodeNotFoundException(ouch);
998             duplicateNodeException(ouch);
999             //
1000             // Throw a generic service exception.
1001             throw new FileManagerServiceException(
1002                 "Error occurred in WebService call",
1003                 ouch
1004                 ) ;
1005             }
1006         }
1007     }
1008