KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > outerj > daisy > backupTool > AbstractBackupEntry


1 /*
2  * Copyright 2004 Outerthought bvba and Schaubroeck nv
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.outerj.daisy.backupTool;
17
18 import java.io.File JavaDoc;
19
20 public abstract class AbstractBackupEntry implements BackupEntry {
21     protected File JavaDoc backupFile;
22     protected BackupInstance buInstance;
23     
24     public AbstractBackupEntry (File JavaDoc backupFile, BackupInstance buInstance) {
25         this.backupFile = backupFile;
26         this.buInstance = buInstance;
27     }
28     
29     public String JavaDoc generateDigest() throws Exception JavaDoc{
30         return BackupHelper.generateMD5Hash(backupFile);
31     }
32
33     public void backupCleanup() throws Exception JavaDoc {
34         if (!isNothing()) {
35             try {
36                 BackupHelper.fileToZip(getTempPath(), backupFile);
37             } catch (Throwable JavaDoc e) {
38                 throw new Exception JavaDoc("Error zipping backup files into " + backupFile.getAbsolutePath(), e);
39             }
40         } else {
41             System.out.println("Excluding " + backupFile.getName() + " from the backup because it is empty.");
42         }
43
44         try {
45             BackupHelper.deleteFile(getTempPath());
46         } catch (Throwable JavaDoc e) {
47             throw new Exception JavaDoc("Error deleting temporary backup file or directory: " + getTempPath().getAbsolutePath(), e);
48         }
49     }
50
51     protected abstract File JavaDoc getTempPath();
52
53     /**
54      * If this backup entry results in no file to be included in the backup,
55      * this method returns true.
56      */

57     protected abstract boolean isNothing();
58 }
59
Popular Tags