KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > diagnostics > Archiver


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 package com.sun.enterprise.diagnostics;
24
25 import java.io.File JavaDoc;
26 import java.io.IOException JavaDoc;
27 import java.util.logging.Logger JavaDoc;
28 import com.sun.logging.LogDomains;
29 import com.sun.enterprise.diagnostics.util.FileUtils;
30 import com.sun.enterprise.diagnostics.util.UniqueNameGenerator;
31
32 /**
33  * Generates a zip file containing diagnostic data
34  * @author Manisha Umbarje
35  */

36 public class Archiver {
37    
38     
39     private static Logger JavaDoc logger =
40             LogDomains.getLogger(LogDomains.ADMIN_LOGGER);
41     /** Creates a new instance of Archiver */
42     public Archiver() {
43     }
44     
45     /**
46      * generates zip file containing diagnostic report
47      * @param file name of archived file
48      * @param target target at which report generation is invoked
49      * @throws com.sun.enterprise.diagnostics.DiagnosticException
50      * @return zip file containing diagnostic report.
51      */

52     public java.util.jar.JarFile JavaDoc archive(ReportTarget target, String JavaDoc file)
53             throws DiagnosticException {
54         try {
55             if (file == null) {
56                 // Generate uniqu name
57
file = File.separator + target.getDefaultReportDir() +
58                         File.separator +
59                         UniqueNameGenerator.getName(target.getName());
60             }
61             String JavaDoc dirTobeArchived = target.getArchiveDir();
62             
63             // Generate the jar file
64
FileUtils.jarDirectory(new File JavaDoc(file),dirTobeArchived);
65             
66             //Delete report folder
67
FileUtils.deleteFile(dirTobeArchived);
68
69             return new java.util.jar.JarFile JavaDoc(file);
70             
71         } catch (IOException JavaDoc ioe) {
72             throw new DiagnosticException(ioe.getMessage());
73         }
74     }
75 }
76
Popular Tags