1 26 27 package org.objectweb.jonas_lib.deployment.work; 28 29 import java.io.File ; 30 31 import java.util.Enumeration ; 32 import java.util.Vector ; 33 34 import org.objectweb.util.monolog.api.Logger; 35 import org.objectweb.util.monolog.api.BasicLevel; 36 37 import org.objectweb.jonas.common.Log; 38 39 44 public abstract class AbsCleanTask { 45 46 49 private static Logger logger = Log.getLogger(Log.JONAS_DEPLOY_WORK_PREFIX); 50 51 54 protected AbsCleanTask() { 55 } 56 57 60 protected static Logger getLogger() { 61 return logger; 62 } 63 64 71 protected abstract boolean isValidLogEntry(LogEntry logEntry) throws CleanerException; 72 73 79 protected abstract void removeLogEntry(LogEntry logEntry) throws CleanerException; 80 81 85 protected abstract Vector getLogEntries(); 86 87 93 protected abstract boolean isDeployLogEntry(LogEntry logEntry) throws CleanerException; 94 95 99 public void execute() throws CleanerException { 100 101 if (getLogger().isLoggable(BasicLevel.DEBUG)) { 102 getLogger().log(BasicLevel.DEBUG, "execute : called"); 103 } 104 105 Vector logEntries = getLogEntries(); 107 108 LogEntry logEntry = null; 110 111 for (Enumeration e = logEntries.elements(); e.hasMoreElements();) { 112 113 logEntry = (LogEntry) e.nextElement(); 114 if (getLogger().isLoggable(BasicLevel.DEBUG)) { 115 getLogger().log(BasicLevel.DEBUG, 116 "LogEntry <" + logEntry.getOriginal().getName() + "," + logEntry.getCopy().getName() + ">"); 117 } 118 119 if (isDeployLogEntry(logEntry)) { 121 if (getLogger().isLoggable(BasicLevel.DEBUG)) { 122 getLogger().log(BasicLevel.DEBUG, "LogEntry currently deployed - > do nothing"); 123 } 124 125 continue; 126 127 } 128 129 if (!isValidLogEntry(logEntry)) { 132 133 removeLogEntry(logEntry); 135 136 e = logEntries.elements(); 139 140 } 141 } 143 } 144 145 149 protected void removeRecursiveDirectory(File file) { 150 151 if (!file.exists()) { 153 return; 154 } 155 156 if (file.isDirectory()) { 158 File [] childFiles = file.listFiles(); 160 for (int i = 0; i < childFiles.length; i++) { 161 removeRecursiveDirectory(childFiles[i]); 162 } 163 } 164 file.delete(); 166 } 167 } | Popular Tags |