KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * BackupDeleteHandler.java
3  *
4  * Created on December 23, 2003, 1:23 AM
5  */

6
7 package com.sun.enterprise.config.backup.phase;
8
9 import com.sun.enterprise.config.backup.utils.FactoryHelper;
10 import com.sun.enterprise.config.backup.utils.BackupHelper;
11 import com.sun.enterprise.config.backup.utils.LoggerHelper;
12 import com.sun.enterprise.config.backup.utils.LocalStringsHelper;
13 import com.sun.enterprise.config.backup.status.Status;
14 import com.sun.enterprise.config.backup.status.RemoveStatus;
15 import com.sun.enterprise.config.backup.status.StatusConstants;
16 import com.sun.enterprise.config.backup.BackupException;
17 import com.sun.enterprise.util.io.FileUtils;
18 import java.io.File JavaDoc;
19
20 /**
21  *
22  * @author sridatta
23  */

24 public class RemovePhases extends PhasesBase {
25     
26     /** Creates a new instance of BackupDeleteHandler */
27     public RemovePhases() {
28     }
29     
30     public RemoveStatus deleteBackup(File JavaDoc f, boolean system) {
31         LoggerHelper.fine("deleting_backup_file " + f.getName());
32         RemoveStatus rs = null;
33         try {
34            rs = new RemoveStatus(f.getName(), system);
35            if(!f.exists()) {
36                throw new BackupException(
37                 "error_delete_invalid_file",
38                 LocalStringsHelper.getString("error_delete_invalid_file",f));
39            }
40            FileUtils.liquidate(f);
41            setSuccess(rs);
42            //updateHistory(rs);//fixme
43
} catch(Exception JavaDoc e) {
44             RemoveStatus rs1 = null;
45             try {
46                rs1 = new RemoveStatus();
47                setFailure(rs1, e);
48             }catch (Exception JavaDoc ex){}
49             return rs1;
50         }
51         return rs;
52     }
53     
54     private void setSuccess(Status rs) {
55         try {
56                     rs.setStatusCode(StatusConstants.STATUS_SUCCESS);
57         } catch (Exception JavaDoc e) {
58             //ignore
59
}
60     }
61     
62     
63     private void setFailure(Status rs, Exception JavaDoc e) {
64         try {
65                     rs.setStatusCode(StatusConstants.STATUS_FAILURE);
66                     rs.setException(e);
67         } catch (Exception JavaDoc e1) {
68             //ignore
69
}
70     }
71     
72     public RemoveStatus deleteBackup(String JavaDoc name, boolean system) {
73         File JavaDoc f;
74         try {
75             f = new File JavaDoc(BackupHelper.getAbsoluteBackupFileName(name));
76         } catch(Exception JavaDoc e) {
77             RemoveStatus rs = null;
78             try {
79                rs = new RemoveStatus();
80                setFailure(rs, e);
81             } catch(Exception JavaDoc ex){}
82             return rs;
83         }
84         return deleteBackup(f, system);
85     }
86     
87     private void updateHistory(Status rs) {
88         try {
89             FactoryHelper.getHistoryManager().addHistoryEntry(rs);
90         } catch(Exception JavaDoc e) {
91             LoggerHelper.warning("error_adding_history_entry", e);
92             //ignore
93
}
94     }
95 }
96
Popular Tags