KickJava   Java API By Example, From Geeks To Geeks.

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


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
25 /*
26  * ListManager.java
27  *
28  * Created on March 30, 2004, 9:01 PM
29  */

30
31 package com.sun.enterprise.config.backup;
32
33 import com.sun.enterprise.config.backup.util.FileUtils;
34 import java.io.*;
35
36 /**
37  *
38  * This class is responsible for returning information about backups.
39  * It opens each backup zip file and examines the properties file for the
40  * information that was stored when the backup was performed.
41  * It returns all this information to CLI as a String.
42  *
43  * @author bnevins
44  */

45 public class ListManager extends BackupRestoreManager
46 {
47     
48     /** Creates an instance of ListManager.
49      * The superclass will call init() so it is
50      * possible for Exceptions to be thrown.
51      * @param req The BackupRequest instance with required information.
52      * @throws BackupException if there is a fatal error with the BackupRequest object.
53      * @throws BackupWarningException if there is a non-fatal error with the BackupRequest object.
54      */

55     public ListManager(BackupRequest req) throws BackupException, BackupWarningException
56     {
57         super(req);
58     }
59
60     /**
61      * Find all backup zip files in a domain and return a String
62      * summarizing information about the backup.
63      * The summary is shorter if the "terse" option is true.
64      * @return a String summary
65      * @throws BackupException if there is a fatal error
66      */

67     public String JavaDoc list() throws BackupException
68     {
69         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
70         
71         findZips();
72         
73         // it is GUARANTEED that the length > 0
74
for(int i = 0; i < zips.length; i++)
75         {
76             Status status = new Status();
77             sb.append(status.read(zips[i], request.terse));
78             sb.append("\n");
79             
80             if(request.terse == false)
81                 sb.append("\n");
82         }
83         
84         return sb.toString();
85     }
86
87     
88     ///////////////////////////////////////////////////////////////////////////////
89
//
90
/**
91      * Finish initializing the BackupRequest object.
92      * note: this method is called by the super class...
93      * @throws BackupException for fatal errors
94      * @throws BackupWarningException for non-fatal errors - these are errors
95      * where we can not continue execution.
96      */

97     void init() throws BackupException, BackupWarningException
98     {
99         super.init();
100         
101         if(!FileUtils.safeIsDirectory(request.domainDir))
102             throw new BackupException("backup-res.NoDomainDir", request.domainDir);
103
104         request.backupDir = new File(request.domainDir, Constants.BACKUP_DIR);
105
106         // It's a warning to not exist...
107
if(!FileUtils.safeIsDirectory(request.backupDir))
108             throw new BackupWarningException("backup-res.NoBackupDir", request.backupDir);
109     }
110     
111     ///////////////////////////////////////////////////////////////////////////////
112

113     /** Looks through the backups directory and assembles
114      * a list of all backup files found.
115      * @throws BackupWarningException if there are no backup zip files
116      */

117     void findZips() throws BackupWarningException
118     {
119         zips = request.backupDir.listFiles(new ZipFilenameFilter());
120
121         if(zips == null || zips.length <= 0)
122             throw new BackupWarningException("backup-res.NoBackupFiles", request.backupDir);
123     }
124     
125     ///////////////////////////////////////////////////////////////////////////////
126

127     File[] zips;
128 }
129
Popular Tags