extensions/net.sf.basedb.opengrid/trunk/src/net/sf/basedb/opengrid/filetransfer/AbstractFileTransfer.java

Code
Comments
Other
Rev Date Author Line
4122 22 Sep 16 nicklas 1 package net.sf.basedb.opengrid.filetransfer;
4122 22 Sep 16 nicklas 2
4122 22 Sep 16 nicklas 3 /**
4124 23 Sep 16 nicklas 4   Abstract base implementation that is suitable when implementing
4124 23 Sep 16 nicklas 5   both file upload and download. This class provides functionality
4124 23 Sep 16 nicklas 6   that is common to both the {@link DownloadTarget} and {@link UploadSource}
4124 23 Sep 16 nicklas 7   interfaces, eg. the name and file metdata information.
4124 23 Sep 16 nicklas 8   
4124 23 Sep 16 nicklas 9   {@link DownloadTarget} implementations only need to extend this class and
4124 23 Sep 16 nicklas 10   implement the {@link DownloadTarget#getOutputStream()} method. File metadata
4124 23 Sep 16 nicklas 11   about the remote file should be available in the {@link #getMetadata()} 
4124 23 Sep 16 nicklas 12   instance when the {@link DownloadTarget#getOutputStream()} method is called.
4124 23 Sep 16 nicklas 13   
4124 23 Sep 16 nicklas 14   {@link UploadSource} implementations that are extending this class
4124 23 Sep 16 nicklas 15   need to implement the {@link UploadSource#getInputStream()} method.
4124 23 Sep 16 nicklas 16   If file metadata is important the implementation should call
4124 23 Sep 16 nicklas 17   {@link #getMetadata()} and initialize the information before the 
4124 23 Sep 16 nicklas 18   {@link UploadSource#getInputStream()} method is called.
4122 22 Sep 16 nicklas 19
4122 22 Sep 16 nicklas 20   @author nicklas
4122 22 Sep 16 nicklas 21   @since 1.0
4122 22 Sep 16 nicklas 22 */
4124 23 Sep 16 nicklas 23 public abstract class AbstractFileTransfer 
4122 22 Sep 16 nicklas 24 {
4122 22 Sep 16 nicklas 25
4122 22 Sep 16 nicklas 26   private final String name;
4124 23 Sep 16 nicklas 27   private FileMetaData metadata;
4122 22 Sep 16 nicklas 28   
4124 23 Sep 16 nicklas 29   protected AbstractFileTransfer(String name)
4122 22 Sep 16 nicklas 30   {
4122 22 Sep 16 nicklas 31     this.name = name;
4122 22 Sep 16 nicklas 32   }
4122 22 Sep 16 nicklas 33
4124 23 Sep 16 nicklas 34   /**
4124 23 Sep 16 nicklas 35     Get the name of the file.
4124 23 Sep 16 nicklas 36     @see UploadSource#getName()
4124 23 Sep 16 nicklas 37     @see DownloadTarget#getName()
4124 23 Sep 16 nicklas 38   */
4122 22 Sep 16 nicklas 39   public String getName()
4122 22 Sep 16 nicklas 40   {
4122 22 Sep 16 nicklas 41     return name;
4122 22 Sep 16 nicklas 42   }
4122 22 Sep 16 nicklas 43
4122 22 Sep 16 nicklas 44   /**
4124 23 Sep 16 nicklas 45     Get metadata about the local file or receive metadata for
4124 23 Sep 16 nicklas 46     the remote file.
4124 23 Sep 16 nicklas 47     @see UploadSource#getMetadata()
4124 23 Sep 16 nicklas 48     @see DownloadTarget#getMetadata()
4122 22 Sep 16 nicklas 49   */
4124 23 Sep 16 nicklas 50   public FileMetaData getMetadata()
4122 22 Sep 16 nicklas 51   {
4124 23 Sep 16 nicklas 52     if (metadata == null) 
4124 23 Sep 16 nicklas 53     {
4124 23 Sep 16 nicklas 54       metadata = new FileMetaData();
4124 23 Sep 16 nicklas 55       initMetadata(metadata);
4124 23 Sep 16 nicklas 56     }
4124 23 Sep 16 nicklas 57     return metadata;
4122 22 Sep 16 nicklas 58   }
4122 22 Sep 16 nicklas 59   
4122 22 Sep 16 nicklas 60   /**
4124 23 Sep 16 nicklas 61     Subclasses that are implementing the {@link UploadSource}
4124 23 Sep 16 nicklas 62     interface should override this method and initialize the
4124 23 Sep 16 nicklas 63     metadata instance with information about the loca file.
4124 23 Sep 16 nicklas 64
4124 23 Sep 16 nicklas 65     This method is called also for {@link DownloadTarget}
4124 23 Sep 16 nicklas 66     implementations but can typically be ignored since
4124 23 Sep 16 nicklas 67     the metadata will be overwritten with information from
4124 23 Sep 16 nicklas 68     the remote server.
4122 22 Sep 16 nicklas 69   */
4124 23 Sep 16 nicklas 70   protected void initMetadata(FileMetaData metadata)
4124 23 Sep 16 nicklas 71   {}
4124 23 Sep 16 nicklas 72   
4122 22 Sep 16 nicklas 73 }