00001
00027 package org.objectweb.jonas_lib.deployment.work;
00028
00029 import java.io.File;
00030
00031 import java.util.Enumeration;
00032 import java.util.Vector;
00033
00034 import org.objectweb.util.monolog.api.Logger;
00035 import org.objectweb.util.monolog.api.BasicLevel;
00036
00037 import org.objectweb.jonas.common.Log;
00038
00044 public abstract class AbsCleanTask {
00045
00049 private static Logger logger = Log.getLogger(Log.JONAS_DEPLOY_WORK_PREFIX);
00050
00054 protected AbsCleanTask() {
00055 }
00056
00060 protected static Logger getLogger() {
00061 return logger;
00062 }
00063
00071 protected abstract boolean isValidLogEntry(LogEntry logEntry) throws CleanerException;
00072
00079 protected abstract void removeLogEntry(LogEntry logEntry) throws CleanerException;
00080
00085 protected abstract Vector getLogEntries();
00086
00093 protected abstract boolean isDeployLogEntry(LogEntry logEntry) throws CleanerException;
00094
00099 public void execute() throws CleanerException {
00100
00101 getLogger().log(BasicLevel.DEBUG, "execute : called");
00102
00103
00104 Vector logEntries = getLogEntries();
00105
00106
00107 LogEntry logEntry = null;
00108
00109 for (Enumeration e = logEntries.elements(); e.hasMoreElements();) {
00110
00111 logEntry = (LogEntry) e.nextElement();
00112 getLogger().log(BasicLevel.DEBUG,
00113 "LogEntry <" + logEntry.getOriginal().getName() + "," + logEntry.getCopy().getName() + ">");
00114
00115
00116 if (isDeployLogEntry(logEntry)) {
00117 getLogger().log(BasicLevel.DEBUG, "LogEntry currently deployed - > do nothing");
00118
00119 continue;
00120
00121 }
00122
00123
00124
00125 if (!isValidLogEntry(logEntry)) {
00126
00127
00128 removeLogEntry(logEntry);
00129
00130
00131
00132 e = logEntries.elements();
00133
00134 }
00135
00136 }
00137 }
00138
00143 protected void removeRecursiveDirectory(File file) {
00144
00145
00146 if (!file.exists()) {
00147 return;
00148 }
00149
00150
00151 if (file.isDirectory()) {
00152
00153 File[] childFiles = file.listFiles();
00154 for (int i = 0; i < childFiles.length; i++) {
00155 removeRecursiveDirectory(childFiles[i]);
00156 }
00157 }
00158
00159 file.delete();
00160 }
00161 }