JModule.java

00001 /*
00002  * JOnAS: Java(TM) Open Application Server
00003  * Copyright (C) 1999 Bull S.A.
00004  * Contact: jonas-team@objectweb.org
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or any later version.
00010  *
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with this library; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
00019  * USA
00020  *
00021  * --------------------------------------------------------------------------
00022  * $Id:
00023  * --------------------------------------------------------------------------
00024  */
00025 
00026 
00027 package org.objectweb.jonas.common;
00028 
00029 import java.io.File;
00030 import java.io.FileInputStream;
00031 import java.util.ArrayList;
00032 import java.util.Collections;
00033 import java.util.Properties;
00034 
00039 public class JModule {
00043     public static final String EJBJAR_EXTENSION = "jar";
00044     public static final String RAR_EXTENSION = "rar";
00045     public static final String WAR_EXTENSION = "war";
00046     public static final String EAR_EXTENSION = "ear";
00047 
00051     public static final String EJBJAR_CHILD_DIR = "META-INF";
00052     public static final String RAR_CHILD_DIR = "META-INF";
00053     public static final String WAR_CHILD_DIR = "WEB-INF";
00054     public static final String EAR_CHILD_DIR = "META-INF";
00055 
00059     public static final String EJBJAR_CONFIRM_FILE = "ejb-jar.xml";
00060     public static final String RAR_CONFIRM_FILE = "ra.xml";
00061     public static final String WAR_CONFIRM_FILE = "web.xml";
00062     public static final String EAR_CONFIRM_FILE = "application.xml";
00063 
00067     public static final String PROPS_EXTENSION = "properties";
00068 
00069 
00073     public static final String CONF_DIR = "conf";
00074 
00075     public static ArrayList getFilesInDir(String dirName, String extension) throws Exception {
00076         ArrayList al = new ArrayList();
00077         File file = new File(dirName);
00078         String[] files = file.list();
00079         int pos;
00080         String fileName;
00081         if (files != null) {
00082             for (int i = 0; i < files.length; i++) {
00083                 file = new File(dirName, files[i]);
00084                 if (file.isFile() == true) {
00085                     fileName = file.getName().toLowerCase();
00086                     pos = fileName.lastIndexOf(extension);
00087                     if (pos > -1) {
00088                         if (pos == (fileName.length() - extension.length())) {
00089                             al.add(file.getName());
00090                         }
00091                     }
00092                 }
00093             }
00094         }
00095         Collections.sort(al);
00096         return al;
00097     }
00098 
00099     public static ArrayList getDatasourcePropsInDir() throws Exception {
00100         // Get all files include in configuration directory
00101         ArrayList al = getFilesInDir(JProp.getJonasBase() + File.separator + CONF_DIR, PROPS_EXTENSION);
00102         // Keep all datasources properties
00103         String sPath;
00104         Properties oProps = new Properties();
00105         boolean bDelete;
00106         int i = 0;
00107         while (i < al.size()) {
00108             sPath = JProp.getJonasBase() + File.separator + CONF_DIR  + File.separator
00109                 + al.get(i).toString();
00110             bDelete = true;
00111             try {
00112                 oProps.clear();
00113                 oProps.load(new FileInputStream(sPath));
00114                 // Detect datasource property
00115                 if (oProps.getProperty("datasource.name") != null) {
00116                     // Remove Extension
00117                     int iPos = al.get(i).toString().toLowerCase().lastIndexOf(".properties");
00118                     al.set(i, al.get(i).toString().substring(0, iPos));
00119                     // Next
00120                     i++;
00121                     bDelete = false;
00122                 }
00123             }
00124             catch (Exception e) {
00125                 // none
00126             }
00127             finally {
00128                 // Remove no-datasource
00129                 if (bDelete == true) {
00130                     al.remove(i);
00131                 }
00132             }
00133         }
00134         return al;
00135     }
00136 
00137     public static ArrayList getMailFactoryPropsInDir(String type) throws Exception {
00138         // Get all files include in configuration directory
00139         ArrayList al = getFilesInDir(JProp.getJonasBase() + File.separator + CONF_DIR, PROPS_EXTENSION);
00140         // Keep all datasources properties
00141         String sPath;
00142         Properties oProps = new Properties();
00143         boolean bDelete;
00144         int i = 0;
00145         while (i < al.size()) {
00146             sPath = JProp.getJonasBase() + File.separator + CONF_DIR  + File.separator
00147                 + al.get(i).toString();
00148             bDelete = true;
00149             try {
00150                 oProps.clear();
00151                 oProps.load(new FileInputStream(sPath));
00152                 // Detect mail factory property
00153                 if (oProps.getProperty("mail.factory.name") != null) {
00154                     boolean bToReturn;
00155                     if (type == null) { 
00156                         // any type OK
00157                         bToReturn = true;  
00158                     } else {
00159                         // Check type 
00160                         if (oProps.getProperty("mail.factory.type").equals(type) == true) {
00161                             bToReturn = true;
00162                         } else {
00163                             bToReturn = false;
00164                         }
00165                     }
00166                     if (bToReturn == true) {                     
00167                         // Remove Extension
00168                         int iPos = al.get(i).toString().toLowerCase().lastIndexOf(".properties");
00169                         al.set(i, al.get(i).toString().substring(0, iPos));
00170                         // Next
00171                         i++;
00172                         bDelete = false;
00173                     }
00174                 }
00175             }
00176             catch (Exception e) {
00177                 // none
00178             }
00179             finally {
00180                 // Remove no-mail factory
00181                 if (bDelete == true) {
00182                     al.remove(i);
00183                 }
00184             }
00185         }
00186         return al;
00187     }
00188     public static ArrayList getMailFactoryPropsInDir() throws Exception {
00189         return getMailFactoryPropsInDir(null);
00190     }
00191 
00192     public static void prefixAutoload(String autoloaddir, ArrayList p_List) {
00193         String sDir = autoloaddir + File.separator;// "autoloaddir/"
00194         for (int i = 0; i < p_List.size(); i++) {
00195             p_List.set(i, sDir + p_List.get(i));
00196         }
00197     }
00198 
00219     public static ArrayList getInstalledContainersInDir(String p_DirName, String p_Extension
00220         , String p_DirChildConfirm, String p_FileConfirm)
00221         throws Exception {
00222 
00223         // Return variable
00224         ArrayList al = new ArrayList();
00225         // Variables used in loop
00226         int iPos;
00227         String sFilename;
00228         File oDirChild;
00229         File oFileConfirm;
00230         // Search all files in directory
00231         File oFile = new File(p_DirName);
00232         String[] asFiles = oFile.list();
00233 
00234         if (asFiles != null) {
00235             // Loop for each found file
00236             for (int i = 0; i < asFiles.length; i++) {
00237                 oFile = new File(p_DirName, asFiles[i]);
00238                 // Detect file with extension
00239                 if (oFile.isFile() == true) {
00240                     sFilename = oFile.getName().toLowerCase();
00241                     iPos = sFilename.lastIndexOf(p_Extension);
00242                     if (iPos > -1) {
00243                         if (iPos == (sFilename.length() - p_Extension.length())) {
00244                             al.add(oFile.getCanonicalFile().toURL().getPath());
00245                         }
00246                     }
00247                 }
00248                 // Detect directory of expanded container
00249                 else if (oFile.isDirectory() == true) {
00250                     oDirChild = new File(oFile, p_DirChildConfirm);
00251                     if ((oDirChild.exists() == true) && (oDirChild.isDirectory() == true)) {
00252                         oFileConfirm = new File(oDirChild, p_FileConfirm);
00253                         if (oFileConfirm.exists() == true) {
00254                             al.add(oFile.getCanonicalFile().toURL().getPath());
00255                         }
00256                     }
00257                 }
00258             }
00259         }
00260         return al;
00261     }
00262 
00263 }

Generated on Tue Feb 15 15:05:14 2005 for JOnAS by  doxygen 1.3.9.1