KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mmbase > module > ReloadableModule


1 /*
2
3 This software is OSI Certified Open Source Software.
4 OSI Certified is a certification mark of the Open Source Initiative.
5
6 The license (Mozilla version 1.0) can be read at the MMBase site.
7 See http://www.MMBase.org/license
8
9 */

10 package org.mmbase.module;
11
12 import java.util.Hashtable JavaDoc;
13 import org.mmbase.util.xml.ModuleReader;
14 import org.mmbase.util.logging.*;
15
16 /**
17  * A Reloadable Module has a 'reload' method. You can extend your own modules from this. If you need
18  * to happen the reload automaticly, then {@link WatchedReloadableModule}.
19  *
20  * @author Michiel Meeuwissen
21  * @since MMBase-1.8
22  * @version $Id: ReloadableModule.java,v 1.9 2005/10/09 14:55:03 ernst Exp $
23  */

24 public abstract class ReloadableModule extends Module {
25
26     private static final Logger log = Logging.getLoggerInstance(ReloadableModule.class);
27
28     /**
29      * Reloads the configuration file.
30      *
31      * The module cannot change class, so if you change that in the XML, an error is logged, and nothing will
32      * happen.
33      *
34      * This method should be called from your extension if and when the configuration must be reloaded.
35      *
36      * @return Whether successful.
37      */

38
39     protected boolean reloadConfiguration(String JavaDoc moduleName) {
40         ModuleReader parser = getModuleReader(moduleName);
41         if (parser == null) {
42             log.error("Configuration missing for: " + moduleName + " Canceling reload");
43             return false;
44         } else {
45             return reloadConfiguration(parser);
46         }
47     }
48
49     protected boolean reloadConfiguration(ModuleReader parser) {
50         if (parser.getStatus().equals("inactive")) {
51             log.error("Cannot set module to inactive. " + parser.getSystemId() + " Canceling reload");
52             return false;
53         }
54         String JavaDoc className = parser.getClassName();
55         if (! className.equals(getClass().getName())) {
56             log.error("Cannot change the class of a module. " + className + " != " + getClass().getName() + " " + parser.getSystemId() + ". Canceling reload.");
57             return false;
58         }
59
60         properties = new Hashtable JavaDoc(parser.getProperties());
61         setMaintainer(parser.getMaintainer());
62         setVersion(parser.getVersion());
63         return true;
64     }
65
66
67     /**
68      * This method should be called when the module should be reloaded.
69      */

70
71     public abstract void reload();
72
73
74 }
75
Popular Tags