1 25 26 package org.objectweb.jonas.jonasadmin.test.util; 27 28 import java.io.BufferedReader ; 29 import java.io.File ; 30 import java.io.FileReader ; 31 import java.io.IOException ; 32 import java.util.Vector ; 33 34 39 public class JonasAdminFiles { 40 41 45 private static Vector getCreatedFiles(String beginTime, String endTime) { 46 Vector createdFiles = new Vector (); 47 48 String jonasBase = System.getProperty("jonas.base"); 50 51 String conf = jonasBase + File.separator + "conf"; 53 54 File directory = new File (conf); 56 57 File [] files = directory.listFiles(); 59 60 String beginName = "server.xml." + beginTime; 62 63 String endName = "server.xml." + endTime; 65 66 for (int i = 0; i < files.length; i++) { 68 if (files[i].getName().compareTo(beginName) >= 0) { 69 if (files[i].getName().compareTo(endName) <= 0) { 70 createdFiles.add(files[i]); 71 } 72 } 73 } 74 return createdFiles; 75 } 76 77 82 public static void deleteCreatedFiles(String beginTime, String endTime) { 83 Vector files = getCreatedFiles(beginTime, endTime); 84 85 for (int i = 0; i < files.size(); i++) { 86 ((File ) files.get(i)).delete(); 88 } 89 } 90 91 96 public static void recoverServerConf(String beginTime, String endTime) { 97 Vector files = getCreatedFiles(beginTime, endTime); 98 99 if (files.size() > 0) { 100 File serverConf = getServerXmlFile(); 102 File copiedFile = (File ) files.get(0); 104 105 if (serverConf.canWrite()) { 107 copiedFile.renameTo(serverConf); 108 } 109 110 for (int i = 0; i < files.size(); i++) { 112 ((File ) files.get(i)).delete(); 113 } 114 } 115 } 116 117 118 122 public static File getServerXmlFile() { 123 String jonasBase = System.getProperty("jonas.base"); 125 126 String serverConfPath = jonasBase + File.separator + "conf" + File.separator + "server.xml"; 128 129 return new File (serverConfPath); 131 } 132 133 139 public static File getPreviousServerXmlFile(String beginTime, String endTime) { 140 Vector files = getCreatedFiles(beginTime, endTime); 141 return (File ) files.get(files.size() - 1); 142 } 143 144 150 public static String getJoramServerPort(String fileName) throws IOException { 151 String port = null; 152 153 String jonasBase = System.getProperty("jonas.base"); 155 156 String serverConfPath = jonasBase + File.separator + "conf" + File.separator + fileName; 158 159 File file = new File (serverConfPath); 161 162 BufferedReader read = new BufferedReader (new FileReader (file)); 164 String line = read.readLine(); 165 while (line != null) { 166 if (line.startsWith("Port")) { 167 port = line.substring("Port\t".length()); 169 } 170 line = read.readLine(); 171 } 172 read.close(); 173 174 return port; 175 } 176 177 183 public static String getJoramHostName(String fileName) throws IOException { 184 String hostName = null; 185 186 String jonasBase = System.getProperty("jonas.base"); 188 189 String serverConfPath = jonasBase + File.separator + "conf" + File.separator + fileName; 191 192 File file = new File (serverConfPath); 194 195 BufferedReader read = new BufferedReader (new FileReader (file)); 197 String line = read.readLine(); 198 while (line != null) { 199 if (line.startsWith("Host")) { 200 hostName = line.substring("Host\t".length()); 202 } 203 line = read.readLine(); 204 } 205 read.close(); 206 207 return hostName; 208 } 209 } 210 | Popular Tags |