blob: b99b3253f8f91cf74671338c8e79ff2f3f57f6c1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
package com.c2kernel.process.module;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.Properties;
import com.c2kernel.common.ObjectNotFoundException;
import com.c2kernel.entity.proxy.ItemProxy;
import com.c2kernel.lookup.DomainPath;
import com.c2kernel.process.Gateway;
import com.c2kernel.utils.FileStringUtility;
import com.c2kernel.utils.Logger;
public class ModuleManager {
ArrayList<Module> modules = new ArrayList<Module>();
Properties props = new Properties();
boolean isServer;
public ModuleManager(Enumeration<URL> moduleEnum, boolean isServer) throws ModuleException{
this.isServer = isServer;
ArrayList<String> loadedModules = new ArrayList<String>();
ArrayList<String> moduleNs = new ArrayList<String>();
while(moduleEnum.hasMoreElements()) {
URL newModuleURL = moduleEnum.nextElement();
try {
Module newModule = new Module(FileStringUtility.url2String(newModuleURL));
modules.add(newModule);
if (loadedModules.contains(newModule.getName())) throw new ModuleException("Module name clash: "+newModule.getName());
if (moduleNs.contains(newModule.getNs())) throw new ModuleException("Module namespace clash: "+newModule.getNs());
Logger.debug(4, "Module found: "+newModule.getNs()+" - "+newModule.getName());
loadedModules.add(newModule.getName()); moduleNs.add(newModule.getNs());
Properties modProp = isServer?newModule.getServerProperties():newModule.getClientProperties();
for (Enumeration<?> e = modProp.propertyNames(); e.hasMoreElements();) {
String propName = (String)e.nextElement();
props.put(propName, modProp.get(propName));
}
} catch (ModuleException e) {
Logger.error("Could not load module description from "+newModuleURL);
throw e;
} catch (IOException e) {
Logger.error(e);
throw new ModuleException("Could not load module.xml from "+newModuleURL);
}
}
Logger.debug(5, "Checking dependencies");
boolean depFailed = false;
for (Module thisMod : modules) {
ArrayList<String> deps = thisMod.getDependencies();
for (String dep : deps) {
if (!loadedModules.contains(dep)) {
Logger.error("UNMET MODULE DEPENDENCY: "+thisMod.getName()+" requires "+dep);
depFailed = true;
}
}
}
if (depFailed) Logger.die("Unmet module dependencies. Cannot continue");
}
public String getModuleVersions() {
StringBuffer ver = new StringBuffer();
for (Module thisMod : modules) {
if (ver.length()>0) ver.append(";");
ver.append(thisMod.getName()+"("+thisMod.getVersion()+")");
}
return ver.toString();
}
public Properties getAllModuleProperties() {
return props;
}
public void runScripts(String event) {
for (Module thisMod : modules) {
thisMod.runScript(event, isServer);
}
}
public void registerModules() throws ObjectNotFoundException {
ItemProxy serverEntity = (ItemProxy)Gateway.getProxyManager().getProxy(new DomainPath("/servers/"+Gateway.getProperty("ItemServer.name")));
Logger.debug(3, "Registering modules");
for (Module thisMod : modules) {
Logger.msg("Registering module "+thisMod.getName());
thisMod.importAll(serverEntity);
Logger.msg("Module "+thisMod.getName()+" registered");
}
}
}
|