KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > config > backup > BackupManager


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.enterprise.config.backup;
25
26 import com.sun.enterprise.config.backup.util.*;
27 import java.io.*;
28 import java.util.*;
29
30
31 /**
32  *
33  * @author Byron Nevins
34  */

35
36
37 public class BackupManager extends BackupRestoreManager
38 {
39     public BackupManager(BackupRequest req) throws BackupException
40     {
41         super(req);
42     }
43     
44     ///////////////////////////////////////////////////////////////////////////////
45

46     public final String JavaDoc backup() throws BackupException
47     {
48         String JavaDoc mesg = StringHelper.get("backup-res.SuccessfulBackup");
49         String JavaDoc statusString = writeStatus();
50         
51         if(request.terse == false)
52         {
53             mesg += "\n\n" + statusString;
54         }
55         
56         try
57         {
58             ZipStorage zs = new ZipStorage(request);
59             zs.store();
60             return mesg;
61         }
62         finally
63         {
64             status.delete();
65             FileUtils.protect(request.backupFile);
66         }
67     }
68     
69     ///////////////////////////////////////////////////////////////////////////////
70

71     void init() throws BackupException
72     {
73         super.init();
74         
75         if(request.backupFile != null)
76             throw new BackupException("backup-res.InternalError", "No backupFilename may be specified for a backup -- it is reserved for restore operations only.");
77         
78         if(!FileUtils.safeIsDirectory(request.domainDir))
79             throw new BackupException("backup-res.NoDomainDir", request.domainDir);
80
81         File backupDir = new File(request.domainDir, Constants.BACKUP_DIR);
82
83         // not an error for this directory to not exist yet
84
backupDir.mkdirs();
85
86         // NOW it's an error to not exist...
87
if(!FileUtils.safeIsDirectory(backupDir))
88             throw new BackupException("backup-res.NoBackupDirCantCreate", backupDir);
89
90         String JavaDoc ts = "" + request.timestamp + ".zip";
91         BackupFilenameManager bfmgr = new BackupFilenameManager(backupDir);
92         request.backupFile = bfmgr.next();
93         //request.backupFile = new File(backupDir, ts);
94
}
95     
96     ///////////////////////////////////////////////////////////////////////////////
97

98     private String JavaDoc writeStatus()
99     {
100         status = new Status();
101         return status.write(request);
102     }
103     
104     ///////////////////////////////////////////////////////////////////////////////
105

106     Status status;
107 }
108
Popular Tags