KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > config > backup > pluggable > impl > DefaultBackupEnvironment


1 /*
2  * BackupEnvironment.java
3  *
4  * Created on December 19, 2003, 9:55 PM
5  */

6
7 package com.sun.enterprise.config.backup.pluggable.impl;
8
9 import com.sun.enterprise.config.backup.pluggable.BackupEnvironment;
10 import com.sun.enterprise.config.backup.pluggable.EnvironmentFactory;
11 import com.sun.enterprise.config.backup.status.StatusConstants;
12 import com.sun.enterprise.config.backup.DefaultConstants;
13 import com.sun.enterprise.config.backup.BackupAbortException;
14 import com.sun.enterprise.config.backup.EnvironmentConstants;
15 import com.sun.enterprise.config.backup.utils.SystemPropsHelper;
16
17 /**
18  * This class provides Default implementation of BackupEnvironment
19  * It reads Environment variables for determining locations.
20  *
21  * This class expects EXECUTION_TYPE, DIRS_TO_BACKUP,
22  * DIR_TO_STORE_BACKUP_FILES to be set in environment
23  *
24  * @author sridatta
25  */

26 public class DefaultBackupEnvironment implements BackupEnvironment,
27                                                 StatusConstants,
28                                                 DefaultConstants,
29                                                 EnvironmentConstants {
30     
31    
32     
33     private String JavaDoc _snapshotFileNamePrefix;
34     private String JavaDoc _backupFileNamePrefix;
35     private String JavaDoc _backupHistoryFileName;
36     private int _maxBackups;
37     private int _maxSnapShots;
38     private String JavaDoc _backupStorageType;
39     
40     private String JavaDoc[] _directoriesToBackup;
41     private String JavaDoc _directoryToStoreBackupFiles;
42     private String JavaDoc _directoryToStoreSnapshotFile;
43     private String JavaDoc _directoryToStoreHistoryFile;
44     private String JavaDoc _statusInfoFileName;
45     
46     /** Creates a new instance of BackupEnvironment */
47     public DefaultBackupEnvironment() {
48         initialize();
49     }
50     
51     protected void initialize() {
52         initializeDefaults();
53         initializeFromEnvironment();
54     }
55     
56     private void initializeDefaults() {
57         _snapshotFileNamePrefix = DEFAULT_SNAPSHOT_FILENAME_PREFIX;
58         _backupFileNamePrefix = DEFAULT_BACKUP_FILENAME_PREFIX;
59         _backupHistoryFileName = DEFAULT_BACKUP_HISTORY_FILENAME;
60         _maxBackups = DEFAULT_MAX_BACKUPS;
61         _maxSnapShots = DEFAULT_MAX_SNAPSHOTS;
62         _statusInfoFileName = DEFAULT_STATUS_INFO_FILENAME;
63     }
64     
65     private void initializeFromEnvironment() {
66         setDirectoriesToBackup(getEnvArr(DIRS_TO_BACKUP));
67         
68         String JavaDoc dir = getEnv(DIR_TO_STORE_BACKUP_FILES);
69         
70         setDirectoryToStoreBackupFiles(dir);
71         setDirectoryToStoreSnapshotFile(dir);
72         setDirectoryToStoreHistoryFile(dir);
73         setBackupStorageType(getEnv(BACKUP_STORAGE_TYPE));
74     }
75     
76     /**
77      * This method is expected to be overridden
78      */

79     protected String JavaDoc getEnv(String JavaDoc var) {
80         return SystemPropsHelper.getProperty(var);
81     }
82     
83     /**
84      * This method is expected to be overridden
85      */

86     protected String JavaDoc[] getEnvArr(String JavaDoc var) {
87         //FIXME null checks
88
return SystemPropsHelper.getProperty(var).split(",");
89     }
90     
91     /*private void setExecutionType(String type) throws BackupInitException {
92         _executionType = type;
93     }
94      */

95     
96     public String JavaDoc[] getDirectoriesToBackup() {
97         return _directoriesToBackup;
98     }
99     
100     public String JavaDoc getDirectoryToStoreBackupFiles() {
101         return _directoryToStoreBackupFiles;
102     }
103     
104     public String JavaDoc getDirectoryToStoreHistoryFile() {
105         return _directoryToStoreHistoryFile;
106     }
107     
108     public String JavaDoc getDirectoryToStoreSnapshotFile() {
109         return _directoryToStoreSnapshotFile;
110     }
111     
112     /**
113      * name of the snapshot file
114      * Timestamp is added to this prefix
115      */

116     public String JavaDoc getSnapshotFileNamePrefix() {
117         return _snapshotFileNamePrefix;
118     }
119     
120     /**
121      * prefix to be used for backup files
122      * timestamp and the backup number is
123      * added to this prefix
124      */

125     public String JavaDoc getBackupFileNamePrefix() {
126         return _backupFileNamePrefix;
127     }
128     
129     /**
130      * Name of the history file
131      */

132     public String JavaDoc getBackupHistoryFileName() {
133         return _backupHistoryFileName;
134     }
135     
136     /**
137      * Keeps backups upto max backups. After that many backups,
138      * oldest backup is deleted.
139      */

140     public int getMaxBackups() {
141         return _maxBackups;
142     }
143       /**
144      * Keeps backups upto max backups. After that many backups,
145      * oldest backup is deleted.
146      */

147     public int getMaxSnapShots() {
148         return _maxSnapShots;
149     }
150     
151     
152     public String JavaDoc getExecutionType() {
153         return getEnv(EXECUTION_TYPE);
154     }
155     
156     private void setDirectoryToStoreBackupFiles(String JavaDoc dir) {
157         _directoryToStoreBackupFiles = dir;
158     }
159     private void setDirectoryToStoreSnapshotFile(String JavaDoc dir) {
160         _directoryToStoreSnapshotFile = dir;
161     }
162     private void setDirectoryToStoreHistoryFile(String JavaDoc dir) {
163         _directoryToStoreHistoryFile = dir;
164     }
165     private void setDirectoriesToBackup(String JavaDoc[] dirs) {
166         _directoriesToBackup = dirs;
167     }
168     
169     public String JavaDoc getBackupStorageType() {
170         return _backupStorageType;
171     }
172     
173     private void setBackupStorageType(String JavaDoc type) {
174         _backupStorageType = type;
175     }
176     
177     public String JavaDoc getStatusInfoFileName() {
178         return _statusInfoFileName;
179     }
180     
181 }
182
Popular Tags