KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > admingui > util > FileUtil


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.tools.admingui.util;
24
25 import java.io.*;
26 import java.io.IOException JavaDoc;
27 import java.util.jar.*;
28 import java.util.zip.ZipEntry JavaDoc;
29
30 import com.sun.enterprise.admin.server.core.AdminService;
31
32 /**
33  * File pathname/location management utility methods
34  */

35 public class FileUtil {
36     public static final String JavaDoc DEPLOY = "deploy";
37     public static final String JavaDoc REDEPLOY = "redeploy";
38     public static final String JavaDoc TRANSFORMATION_RULE = "transformationRule";
39     public static final String JavaDoc INSTANCE_ROOT = System.getProperty("com.sun.aas.instanceRoot");
40     public static final String JavaDoc GEN_XML_DIR = INSTANCE_ROOT + File.separator + "generated" + File.separator + "xml";
41     public static final String JavaDoc GEN_XML_APP_DIR = GEN_XML_DIR + File.separator + "j2ee-apps";
42     public static final String JavaDoc GEN_XML_MOD_DIR = GEN_XML_DIR + File.separator + "j2ee-modules";
43
44     public static String JavaDoc getUploadDir() throws Exception JavaDoc {
45         return AdminService.getAdminService().getGUITempDirPath(); //TODO: Get directory from admin gui side instead of depending on external module
46
}
47     
48     public static boolean isEARFile(File file) {
49         try {
50             JarFile jar = new JarFile(file);
51             ZipEntry JavaDoc result = jar.getEntry("META-INF/application.xml");
52             jar.close();
53             return result != null;
54         } catch (IOException JavaDoc ex) {
55             return false;
56         }
57     }
58
59     public static boolean isWARFile(File file) {
60         try {
61             JarFile jar = new JarFile(file);
62             ZipEntry JavaDoc result = jar.getEntry("WEB-INF/web.xml");
63             jar.close();
64             return result != null;
65         } catch (IOException JavaDoc ex) {
66             return false;
67         }
68     }
69
70     public static boolean isEJBJar(File file) {
71         try {
72             JarFile jar = new JarFile(file);
73             ZipEntry JavaDoc result = jar.getEntry("META-INF/ejb-jar.xml");
74             jar.close();
75             return result != null;
76         } catch (IOException JavaDoc ex) {
77             return false;
78         }
79     }
80
81     public static boolean isJarFile(File file) {
82     //Check whether this is a valid file
83
//for now return true.
84
try {
85             boolean result = false;
86
87             if(file.getName().endsWith(".jar")) {
88                JarFile jar = new JarFile(file);
89                if ( jar != null ) {
90                   result = jar.entries().hasMoreElements();
91                }
92                jar.close();
93                return result ;
94             } else {
95            return false;
96             }
97           
98         } catch (IOException JavaDoc ex) {
99             return false;
100         }
101     }
102
103     public static boolean isRARFile(File file) {
104         try {
105             JarFile jar = new JarFile(file);
106             ZipEntry JavaDoc result = jar.getEntry("META-INF/ra.xml");
107             jar.close();
108             return result != null;
109         } catch (IOException JavaDoc ex) {
110             return false;
111         }
112     }
113
114     public static boolean isAppClientJar(File file) {
115         try {
116             JarFile jar = new JarFile(file);
117             ZipEntry JavaDoc result = jar.getEntry("META-INF/application-client.xml");
118             jar.close();
119             return result != null;
120         } catch (IOException JavaDoc ex) {
121             return false;
122         }
123     }
124     
125     public static void extractMbeanJarFile(String JavaDoc domainRoot, String JavaDoc fileName ) throws IOException JavaDoc {
126             File f = new File(fileName);
127             if(FileUtil.isJarFile(f))
128             {
129                //We have to extract it into mbeans directory for the classloader to load it.
130
JarExtract.extract(fileName, domainRoot+"/applications/mbeans");
131             }
132     }
133     
134 }
135
Popular Tags