AbsCleanTask.java

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         // Get the entries from the logger
00104         Vector logEntries = getLogEntries();
00105 
00106         // Check if the files in this vector exists
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             // if the package is deployed, do nothing
00116             if (isDeployLogEntry(logEntry)) {
00117                 getLogger().log(BasicLevel.DEBUG, "LogEntry currently deployed - > do nothing");
00118 
00119                 continue;
00120 
00121             }
00122 
00123             // if the source package file doesn't exists anymore
00124             // or if the file is present but don't care the right timestamp
00125             if (!isValidLogEntry(logEntry)) {
00126 
00127                 // we remove the entry
00128                 removeLogEntry(logEntry);
00129 
00130                 // enumeration is now inconsistent, so we 're restarting the
00131                 // loop
00132                 e = logEntries.elements();
00133 
00134             }
00135             //else time stamp always the same
00136         }
00137     }
00138 
00143     protected void removeRecursiveDirectory(File file) {
00144 
00145         //File or directory doesn't exists, exit.
00146         if (!file.exists()) {
00147             return;
00148         }
00149 
00150         //Remove the child before the current file(directory)
00151         if (file.isDirectory()) {
00152             //remove all the child
00153             File[] childFiles = file.listFiles();
00154             for (int i = 0; i < childFiles.length; i++) {
00155                 removeRecursiveDirectory(childFiles[i]);
00156             }
00157         }
00158         //Since all childs are removed , remove us
00159         file.delete();
00160     }
00161 }

Generated on Tue Feb 15 15:05:50 2005 for JOnAS by  doxygen 1.3.9.1