summaryrefslogtreecommitdiff
path: root/src/main/java/com/c2kernel/process/module/ModuleManager.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/c2kernel/process/module/ModuleManager.java')
-rw-r--r--src/main/java/com/c2kernel/process/module/ModuleManager.java34
1 files changed, 28 insertions, 6 deletions
diff --git a/src/main/java/com/c2kernel/process/module/ModuleManager.java b/src/main/java/com/c2kernel/process/module/ModuleManager.java
index aa598fa..ca47ec9 100644
--- a/src/main/java/com/c2kernel/process/module/ModuleManager.java
+++ b/src/main/java/com/c2kernel/process/module/ModuleManager.java
@@ -1,15 +1,19 @@
package com.c2kernel.process.module;
-import java.io.IOException;
import java.net.URL;
+import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.Properties;
+import com.c2kernel.common.CannotManageException;
+import com.c2kernel.common.ObjectAlreadyExistsException;
+import com.c2kernel.common.ObjectCannotBeUpdated;
import com.c2kernel.common.ObjectNotFoundException;
import com.c2kernel.entity.proxy.ItemProxy;
import com.c2kernel.lookup.DomainPath;
import com.c2kernel.process.Gateway;
+import com.c2kernel.scripting.ScriptingEngineException;
import com.c2kernel.utils.FileStringUtility;
import com.c2kernel.utils.Logger;
@@ -18,20 +22,22 @@ public class ModuleManager {
Properties props = new Properties();
boolean isServer;
- public ModuleManager(Enumeration<URL> moduleEnum, boolean isServer) throws ModuleException{
+ 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 = (Module)Gateway.getMarshaller().unmarshall(FileStringUtility.url2String(newModuleURL));
+ //Resource.addModuleBaseURL(newModule.ns, newModule.resURL);
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();
+ Properties modProp = newModule.getProperties(isServer);
for (Enumeration<?> e = modProp.propertyNames(); e.hasMoreElements();) {
String propName = (String)e.nextElement();
props.put(propName, modProp.get(propName));
@@ -39,7 +45,7 @@ public class ModuleManager {
} catch (ModuleException e) {
Logger.error("Could not load module description from "+newModuleURL);
throw e;
- } catch (IOException e) {
+ } catch (Exception e) {
Logger.error(e);
throw new ModuleException("Could not load module.xml from "+newModuleURL);
}
@@ -76,11 +82,16 @@ public class ModuleManager {
public void runScripts(String event) {
for (Module thisMod : modules) {
- thisMod.runScript(event, isServer);
+ try {
+ thisMod.runScript(event, isServer);
+ } catch (ScriptingEngineException e) {
+ Logger.error(e);
+ Logger.die(e.getMessage());
+ }
}
}
- public void registerModules() throws ObjectNotFoundException {
+ public void registerModules() throws ObjectNotFoundException, ObjectCannotBeUpdated, CannotManageException, ObjectAlreadyExistsException, NoSuchAlgorithmException {
ItemProxy serverEntity = (ItemProxy)Gateway.getProxyManager().getProxy(new DomainPath("/servers/"+Gateway.getProperty("ItemServer.name")));
Logger.debug(3, "Registering modules");
for (Module thisMod : modules) {
@@ -89,4 +100,15 @@ public class ModuleManager {
Logger.msg("Module "+thisMod.getName()+" registered");
}
}
+
+ public void dumpModules() {
+ for (Module thisMod : modules) {
+ try {
+ FileStringUtility.string2File(thisMod.getName()+".xml", Gateway.getMarshaller().marshall(thisMod));
+ } catch (Exception e) {
+ Logger.error(e);
+ }
+ }
+
+ }
}