00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
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
00101 ArrayList al = getFilesInDir(JProp.getJonasBase() + File.separator + CONF_DIR, PROPS_EXTENSION);
00102
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
00115 if (oProps.getProperty("datasource.name") != null) {
00116
00117 int iPos = al.get(i).toString().toLowerCase().lastIndexOf(".properties");
00118 al.set(i, al.get(i).toString().substring(0, iPos));
00119
00120 i++;
00121 bDelete = false;
00122 }
00123 }
00124 catch (Exception e) {
00125
00126 }
00127 finally {
00128
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
00139 ArrayList al = getFilesInDir(JProp.getJonasBase() + File.separator + CONF_DIR, PROPS_EXTENSION);
00140
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
00153 if (oProps.getProperty("mail.factory.name") != null) {
00154 boolean bToReturn;
00155 if (type == null) {
00156
00157 bToReturn = true;
00158 } else {
00159
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
00168 int iPos = al.get(i).toString().toLowerCase().lastIndexOf(".properties");
00169 al.set(i, al.get(i).toString().substring(0, iPos));
00170
00171 i++;
00172 bDelete = false;
00173 }
00174 }
00175 }
00176 catch (Exception e) {
00177
00178 }
00179 finally {
00180
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;
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
00224 ArrayList al = new ArrayList();
00225
00226 int iPos;
00227 String sFilename;
00228 File oDirChild;
00229 File oFileConfirm;
00230
00231 File oFile = new File(p_DirName);
00232 String[] asFiles = oFile.list();
00233
00234 if (asFiles != null) {
00235
00236 for (int i = 0; i < asFiles.length; i++) {
00237 oFile = new File(p_DirName, asFiles[i]);
00238
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
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 }