00001
00026 package org.objectweb.jonas_lib.deployment.work;
00027
00028 import java.io.File;
00029 import java.net.MalformedURLException;
00030 import java.util.Vector;
00031
00032 import org.objectweb.jonas.container.EJBService;
00033 import org.objectweb.jonas.service.ServiceManager;
00034
00035 import org.objectweb.util.monolog.api.BasicLevel;
00036
00043 public class JarCleanTask extends AbsCleanTask {
00044
00048 private static DeployerLog jarDeployerLog = null;
00049
00054 public JarCleanTask(DeployerLog jarDeployerLog) {
00055 super();
00056 JarCleanTask.jarDeployerLog = jarDeployerLog;
00057 }
00058
00065 protected boolean isValidLogEntry(LogEntry logEntry) throws CleanerException {
00066 String fTimeStamp = null;
00067 File jarOriginalFile = logEntry.getOriginal();
00068 File jarCopyFile = logEntry.getCopy();
00069
00070 getLogger().log(BasicLevel.DEBUG, "LogEntry exist :" + jarOriginalFile.exists());
00071
00072
00073 if (!jarOriginalFile.exists()) {
00074 return false;
00075 }
00076
00077
00078 try {
00079 fTimeStamp = FileManager.fileToTimeStampDir(jarOriginalFile.toURL(), ".jar");
00080 } catch (FileManagerException efme) {
00081 throw new CleanerException("Can't get the timestamp of the file " + jarOriginalFile + " : "
00082 + efme.getMessage());
00083 } catch (MalformedURLException mue) {
00084 throw new CleanerException("Can't get the timestamp of the file " + jarOriginalFile + " : "
00085 + mue.getMessage());
00086 }
00087
00088 getLogger().log(BasicLevel.DEBUG, "LogEntry fTimeStamp :" + fTimeStamp);
00089 getLogger().log(BasicLevel.DEBUG, "LogEntry isValid :" + fTimeStamp.equalsIgnoreCase(jarCopyFile.getName()));
00090
00091
00092 return (fTimeStamp.equalsIgnoreCase(jarCopyFile.getName()));
00093
00094 }
00095
00101 protected void removeLogEntry(LogEntry logEntry) throws CleanerException {
00102
00103 removeRecursiveDirectory(logEntry.getCopy());
00104
00105 try {
00106 jarDeployerLog.removeEntry(logEntry);
00107 } catch (DeployerLogException edle) {
00108 throw new CleanerException("Can't remove an entry" + edle.getMessage());
00109 }
00110
00111 }
00112
00117 protected Vector getLogEntries() {
00118 return jarDeployerLog.getEntries();
00119 }
00120
00127 protected boolean isDeployLogEntry(LogEntry logEntry) throws CleanerException {
00128
00129
00130 ServiceManager sm = null;
00131
00132 try {
00133 sm = ServiceManager.getInstance();
00134 } catch (Exception e) {
00135 throw new CleanerException("Cannot get ServiceManager instance");
00136 }
00137 EJBService ejbService = (EJBService) sm.getEjbService();
00138
00139
00140 return ejbService.isJarDeployedByWorkName(logEntry.getCopy().getName());
00141
00142 }
00143 }