KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > config > backup > phase > BackupPhases


1 /*
2  * BackupPhases.java
3  *
4  * Created on December 24, 2003, 10:07 AM
5  */

6
7 package com.sun.enterprise.config.backup.phase;
8
9 import com.sun.enterprise.config.backup.status.BackupStatus;
10 import com.sun.enterprise.config.backup.BackupException;
11 import com.sun.enterprise.config.backup.status.Status;
12 import com.sun.enterprise.config.backup.status.StatusConstants;
13 import com.sun.enterprise.config.backup.StatusRegistry;
14 import com.sun.enterprise.config.backup.utils.LoggerHelper;
15 import com.sun.enterprise.config.backup.utils.LocalStringsHelper;
16 import com.sun.enterprise.config.backup.pluggable.BackupStorage;
17 import com.sun.enterprise.config.backup.BackupAbortException;
18 import com.sun.enterprise.config.backup.utils.BackupHelper;
19 import com.sun.enterprise.config.backup.utils.FactoryHelper;
20
21 /**
22  *
23  * @author sridatta
24  */

25 public class BackupPhases extends PhasesBase {
26     
27     /** Creates a new instance of BackupPhases */
28     public BackupPhases() {
29     }
30     
31    /* public void assertStatusNotFailed(BackupStatus bs) {
32         assertNotNull(bs);
33         assertNotFailed(bs);
34     }
35     */

36     
37     public void assertStatusNotNull(BackupStatus bs) {
38         if(bs == null) {
39             LoggerHelper.info("null_status_in_backup");
40             //should never happen
41
BackupStatus bs1 = new BackupStatus();
42             setStatusInRegistry(bs1);
43             throw new BackupAbortException(
44                 "error_invoking_backup_null_status",
45                 LocalStringsHelper.getString(
46                     "error_invoking_backup_null_status"));
47         }
48     }
49     
50
51     public void setAbsoluteBackupFileName(String JavaDoc absoluteTargetFile) {
52         getStatus().setAbsoluteBackupFileName(absoluteTargetFile);
53         LoggerHelper.fine("Target File for backup is " + absoluteTargetFile);
54         
55     }
56     
57     public BackupStatus getStatus() {
58         return (BackupStatus)getStatusFromRegistry();
59     }
60     
61     public void monitorBackupDir() {
62         try {
63             FactoryHelper.getBackupStorageMonitor().run();
64         } catch(Exception JavaDoc e) {
65             //log it
66
LoggerHelper.warning("error_monitoring_backup_dir");
67             LoggerHelper.fine("error_monitoring_backup_dir", e);
68         }
69     }
70     
71     public void setBackupFileSize(long size) {
72           getStatus().setBackupFileSize(size);
73     }
74     
75     public long backup() throws Exception JavaDoc {
76         String JavaDoc[] srcDirs = getStatus().getDirectoriesToBackup();
77               LoggerHelper.fine("Source Directory for backup is "
78                                 + BackupHelper.ArrayToString(srcDirs));
79              
80               String JavaDoc absTargetFile = getStatus().getAbsoluteBackupFileName();
81               //get the correct storage class
82
BackupStorage backupStorage = FactoryHelper.getStorage();
83               return backupStorage.backup(srcDirs, absTargetFile);
84     }
85     
86     public void addStatusFile() {
87         String JavaDoc absTargetFile = getStatus().getAbsoluteBackupFileName();
88         //get the correct storage class
89
BackupStorage backupStorage = FactoryHelper.getStorage();
90         backupStorage.createStatusFile(absTargetFile, getStatus());
91     }
92         
93 }
94
Popular Tags