From 24314dc1699c7e73048fa24e33729f1aa1ec0e86 Mon Sep 17 00:00:00 2001 From: Andrew Branson Date: Fri, 6 Jul 2012 11:00:24 +0200 Subject: Modules serialize with Castor. Just about to remove the parsing. CastorXMLUtility is now a static member of gateway. Domain specific instances can be used by domain applications, but the maps do not interfere with the kernel. --- .../com/c2kernel/process/module/ModuleManager.java | 34 ++++++++++++++++++---- 1 file changed, 28 insertions(+), 6 deletions(-) (limited to 'src/main/java/com/c2kernel/process/module/ModuleManager.java') 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 moduleEnum, boolean isServer) throws ModuleException{ + public ModuleManager(Enumeration moduleEnum, boolean isServer) throws ModuleException { this.isServer = isServer; ArrayList loadedModules = new ArrayList(); ArrayList moduleNs = new ArrayList(); 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); + } + } + + } } -- cgit v1.2.3