KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas_lib > deployment > work > JarCleanTask


1 /**
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999-2004 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * Initial developer(s): Benoit PELLETIER
22  * --------------------------------------------------------------------------
23  * $Id: JarCleanTask.java,v 1.4 2005/04/28 16:53:00 benoitf Exp $
24  * --------------------------------------------------------------------------
25  */

26 package org.objectweb.jonas_lib.deployment.work;
27
28 import java.io.File JavaDoc;
29 import java.net.MalformedURLException JavaDoc;
30 import java.util.Vector JavaDoc;
31
32 import org.objectweb.jonas.container.EJBService;
33 import org.objectweb.jonas.service.ServiceManager;
34
35 import org.objectweb.util.monolog.api.BasicLevel;
36
37 /**
38  * JOnAS Jar unused copy clean task class. This class provides a way for
39  * removing copies wich are unconsistent for jar files.
40  * @author Florent BENOIT
41  * @author Benoit PELLETIER
42  */

43 public class JarCleanTask extends AbsCleanTask {
44
45     /**
46      * reference to the deployerLog
47      */

48     private static DeployerLog jarDeployerLog = null;
49
50     /**
51      * Default constructor : Construct a new cleaner.
52      * @param jarDeployerLog the deployer logger
53      */

54     public JarCleanTask(DeployerLog jarDeployerLog) {
55         super();
56         JarCleanTask.jarDeployerLog = jarDeployerLog;
57     }
58
59     /**
60      * Return true if the work copy exists and is up to date
61      * @param logEntry entry in a deploy log
62      * @return true if the work copy exists and is up to date
63      * @throws CleanerException if it fails
64      */

65     protected boolean isValidLogEntry(LogEntry logEntry) throws CleanerException {
66         String JavaDoc fTimeStamp = null;
67         File JavaDoc jarOriginalFile = logEntry.getOriginal();
68         File JavaDoc jarCopyFile = logEntry.getCopy();
69
70         if (getLogger().isLoggable(BasicLevel.DEBUG)) {
71             getLogger().log(BasicLevel.DEBUG, "LogEntry exist :" + jarOriginalFile.exists());
72         }
73
74         // if the file doesn't exist, return
75
if (!jarOriginalFile.exists()) {
76             return false;
77         }
78
79         //get the timestamp
80
try {
81             fTimeStamp = FileManager.fileToTimeStampDir(jarOriginalFile.toURL(), ".jar");
82         } catch (FileManagerException efme) {
83             throw new CleanerException("Can't get the timestamp of the file " + jarOriginalFile + " : "
84                     + efme.getMessage());
85         } catch (MalformedURLException JavaDoc mue) {
86             throw new CleanerException("Can't get the timestamp of the file " + jarOriginalFile + " : "
87                     + mue.getMessage());
88         }
89
90         if (getLogger().isLoggable(BasicLevel.DEBUG)) {
91             getLogger().log(BasicLevel.DEBUG, "LogEntry fTimeStamp :" + fTimeStamp);
92             getLogger().log(BasicLevel.DEBUG, "LogEntry isValid :" + fTimeStamp.equalsIgnoreCase(jarCopyFile.getName()));
93         }
94
95         //compare
96
return (fTimeStamp.equalsIgnoreCase(jarCopyFile.getName()));
97
98     }
99
100     /**
101      * Remove the work copy specified in the log entry and the log entry
102      * @param logEntry entry in a deploy log
103      * @throws CleanerException if it fails
104      */

105     protected void removeLogEntry(LogEntry logEntry) throws CleanerException {
106         // it's a file but this should work
107
removeRecursiveDirectory(logEntry.getCopy());
108
109         try {
110             jarDeployerLog.removeEntry(logEntry);
111         } catch (DeployerLogException edle) {
112             throw new CleanerException("Can't remove an entry" + edle.getMessage());
113         }
114
115     }
116
117     /**
118      * Gets the log entries
119      * @return the log entries
120      */

121     protected Vector JavaDoc getLogEntries() {
122         return jarDeployerLog.getEntries();
123     }
124
125     /**
126      * Check if the package pointed by the log entry is currently deploy
127      * @param logEntry entry in a deploy log
128      * @return true if the package pointed by the log entry is currently deployed
129      * @throws CleanerException if it fails
130      */

131     protected boolean isDeployLogEntry(LogEntry logEntry) throws CleanerException {
132
133         // get the ejbjar service
134
ServiceManager sm = null;
135
136         try {
137             sm = ServiceManager.getInstance();
138         } catch (Exception JavaDoc e) {
139             throw new CleanerException("Cannot get ServiceManager instance");
140         }
141         EJBService ejbService = (EJBService) sm.getEjbService();
142
143         // check if the jar file is deployed
144
return ejbService.isJarDeployedByWorkName(logEntry.getCopy().getName());
145
146     }
147 }
Popular Tags