01: /*
02:
03: This software is OSI Certified Open Source Software.
04: OSI Certified is a certification mark of the Open Source Initiative.
05:
06: The license (Mozilla version 1.0) can be read at the MMBase site.
07: See http://www.MMBase.org/license
08:
09: */
10: package org.mmbase.module;
11:
12: import org.mmbase.util.xml.ModuleReader;
13: import org.mmbase.util.functions.*;
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.16 2007/06/19 14:58:02 michiel Exp $
23: */
24: public abstract class ReloadableModule extends Module {
25:
26: private static final Logger log = Logging
27: .getLoggerInstance(ReloadableModule.class);
28:
29: public ReloadableModule() {
30: }
31:
32: public ReloadableModule(String name) {
33: super (name);
34: }
35:
36: /**
37: * Reloads the configuration file.
38: *
39: * The module cannot change class, so if you change that in the XML, an error is logged, and nothing will
40: * happen.
41: *
42: * This method should be called from your extension if and when the configuration must be reloaded.
43: *
44: * @return Whether successful.
45: */
46: protected boolean reloadConfiguration() {
47: ModuleReader parser = getModuleReader();
48: if (parser == null) {
49: log.error("Configuration missing for module " + getName()
50: + " with path '" + configurationPath
51: + "': Canceling reload");
52: return false;
53: } else {
54: return reloadConfiguration(parser);
55: }
56: }
57:
58: protected boolean reloadConfiguration(ModuleReader parser) {
59: if (parser.getStatus().equals("inactive")) {
60: log.error("Cannot set module to inactive. "
61: + parser.getSystemId() + " Canceling reload");
62: return false;
63: }
64: String className = parser.getClassName();
65: if (!className.equals(getClass().getName())) {
66: log.error("Cannot change the class of a module. "
67: + className + " != " + getClass().getName() + " "
68: + parser.getSystemId() + ". Canceling reload.");
69: return false;
70: }
71:
72: setMaintainer(parser.getMaintainer());
73: setVersion(parser.getVersion());
74: properties = parser.getProperties();
75: parser.getLocalizedDescription(getLocalizedDescription());
76: parser.getLocalizedGUIName(getLocalizedGUIName());
77: loadInitParameters();
78: return true;
79: }
80:
81: /**
82: * This method should be called when the module should be reloaded.
83: */
84: public abstract void reload();
85:
86: {
87: addFunction(new AbstractFunction<Void>("reload") {
88: public Void getFunctionValue(Parameters arguments) {
89: ReloadableModule.this.reload();
90: return null;
91: }
92: });
93: }
94:
95: }
|