KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > config > backup > appserver > Main


1 /*
2  * Main.java
3  *
4  * Created on December 13, 2000, 9:37 AM
5  */

6
7 package com.sun.enterprise.config.backup.appserver;
8
9 import com.sun.enterprise.config.backup.status.StatusConstants;
10 import com.sun.enterprise.config.backup.*;
11 import com.sun.enterprise.config.backup.status.*;
12 import com.sun.enterprise.config.backup.EnvironmentConstants;
13 import com.sun.enterprise.config.backup.BackupRequest;
14 import com.sun.enterprise.config.backup.utils.SystemPropsHelper;
15
16 /**
17  * This is the main class to be used for CLI in
18  * the offline mode
19  *
20  * @author sridatta
21  */

22 public class Main {
23     private static final int HISTORY_NUMBER = 6;
24     
25     /** Creates a new instance of Main */
26     public Main() {
27     }
28     
29     public static void main(String JavaDoc[] args)
30     {
31         entry(args);
32     }
33
34     // bnevins TEMPORARY TBD
35
public static void entry(BackupRequest br)
36     {
37         br.verify();
38         String JavaDoc[] dirs = br.getDirsToBackup();
39         String JavaDoc allDirs = dirs[0];
40         
41         for(int i = 1; i < dirs.length; i++)
42             allDirs += ',' + dirs[i];
43         
44         SystemPropsHelper.setProperty(EnvironmentConstants.DIRS_TO_BACKUP, allDirs);
45         SystemPropsHelper.setProperty(EnvironmentConstants.DIR_TO_STORE_BACKUP_FILES, br.getDirToStoreBackupFiles());
46         SystemPropsHelper.setProperty(EnvironmentConstants.BACKUP_STORAGE_TYPE, br.getBackupStorageType());
47
48         try
49         {
50             BackupRestore bri = Util.getBackupRestore();
51             Status s = bri.backup(null);
52             System.out.println("==================");
53             printStatus(s);
54             System.out.println("==================");
55             System.out.println(s.getExtraInfo());
56             System.out.println("==================");
57         }
58         catch(Exception JavaDoc e)
59         {
60             e.printStackTrace();
61         }
62     }
63     
64     /**
65      * @param args the command line arguments
66      */

67     private static void entry(String JavaDoc[] args) {
68         try {
69             if(args == null || args.length <1 || args[0] == null || "".equals(args[0])) {
70                 usage();
71                 return;
72             }
73
74             System.setProperty(EnvironmentConstants.DIRS_TO_BACKUP, "C:/tmp/tmp/tmp");
75             System.setProperty(EnvironmentConstants.DIR_TO_STORE_BACKUP_FILES, "C:/temp/backup");
76             System.setProperty(EnvironmentConstants.BACKUP_STORAGE_TYPE, "directory");
77             //System.setProperty("backup_storage_type", "zip");
78
BackupRestore bri = Util.getBackupRestore();
79             Status s = null;
80             if("backup".equals(args[0])) {
81                 String JavaDoc userInfo = null;
82                 if(args.length == 1) { // && (args[1] == null || "".equals(args[1]))) {
83
s = bri.backup(null);
84                 } else if(args.length == 2) { //&& (args[2] == null || "".equals(args[2]))) {
85
System.out.println("info=" + args[1]);
86                     s = bri.backup(args[1]);
87                 } else if(args.length == 3) {
88                     s = bri.backup(args[1], args[2]);
89                 } else {
90                     usage();
91                     return;
92                 }
93             } else if ("restore".equals(args[0])) {
94                 s = bri.restore();
95             } else if("undorestore".equals(args[0])) {
96                 s = bri.undoRestore();
97             } else if("listbackups".equals(args[0])) {
98                 BackupStatus[] bs = bri.listBackups();
99                 System.out.println("==================");
100                 
101                 printBackupStatus(bs);
102                 System.out.println("==================");
103                 
104                 return;
105             } else if("listhistory".equals(args[0])) {
106                 int n=HISTORY_NUMBER;
107                 if(args.length==2) { // && args != null && !args[1].equals("") ) {
108
n = getHistoryNumber(args[1]);
109                 }
110                 BackupHistory bh = bri.getBackupHistory(n);
111                 System.out.println("==================");
112                 
113                 //printBackupStatus(bh);
114
System.out.println(bh);
115                 System.out.println("==================");
116                 
117                 return;
118             } else {
119                 System.out.println("sub-command invalid");
120                 usage();
121                 return;
122             }
123             System.out.println("==================");
124             printStatus(s);
125             System.out.println("==================");
126             System.out.println(s.getExtraInfo());
127             System.out.println("==================");
128             
129             //parse args
130

131             //invoke on the right method
132

133             //return correct values
134

135         } catch(Exception JavaDoc e){
136             e.printStackTrace();
137         }
138         
139     }
140     
141     private static void printBackupStatus(BackupStatus[] bs) {
142         if (bs == null || bs.length == 0) {
143             System.out.println("There are no Backups");
144         }
145         System.out.println("Available Backups are:");
146         for (int i = 0 ; i < bs.length; i ++) {
147             System.out.println(bs[i]);
148         }
149     }
150     private static void printStatus(Status s) {
151         System.out.println(s);
152     }
153     
154     private static void usage() {
155         System.out.println("Usage: \n" +
156          "asbackup backup <userInfo>\n" +
157          "asbackup backup absoluteFileName userInfo\n" +
158          "asbackup restore \n" +
159          "asbackup undorestore \n" +
160          "asbackup listbackups \n" +
161          "asbackup listhistory <numberOfHistories>");
162     }
163     
164     private static int getHistoryNumber(String JavaDoc arg) {
165         try {
166             return new Integer JavaDoc(arg).intValue();
167         } catch(Exception JavaDoc e) {
168             return HISTORY_NUMBER;
169         }
170     }
171 }
172
Popular Tags