summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Branson <andrew.branson@cern.ch>2012-06-14 11:35:25 +0200
committerAndrew Branson <andrew.branson@cern.ch>2012-06-14 11:35:25 +0200
commitf20547a9f617a971d7dfa64a5a4564cd2f013170 (patch)
tree03cfcd0b2b344abedfcf857d320a3532a4649b49
parente55bf67f1ba4565ba2816ba58ab13b27807dd540 (diff)
Created ModuleException
-rw-r--r--src/main/java/com/c2kernel/process/Gateway.java11
-rw-r--r--src/main/java/com/c2kernel/process/Module.java28
-rw-r--r--src/main/java/com/c2kernel/process/ModuleManager.java16
3 files changed, 37 insertions, 18 deletions
diff --git a/src/main/java/com/c2kernel/process/Gateway.java b/src/main/java/com/c2kernel/process/Gateway.java
index aebd19e..8220a35 100644
--- a/src/main/java/com/c2kernel/process/Gateway.java
+++ b/src/main/java/com/c2kernel/process/Gateway.java
@@ -5,7 +5,6 @@ package com.c2kernel.process;
* @author $Author: abranson $
*/
-import java.io.IOException;
import java.net.MalformedURLException;
import java.util.Enumeration;
import java.util.Properties;
@@ -81,12 +80,12 @@ public class Gateway
// init module manager
try {
- mModules = new ModuleManager(ClassLoader.getSystemResources("module.xml"), isServer);
- } catch (IOException e) {
+ mModules = new ModuleManager(ClassLoader.getSystemResources("META-INF/cristal/module.xml"), isServer);
+ } catch (Exception e) {
Logger.error(e);
- throw new InvalidDataException("Could not load module definitions. Classpath problem", "");
- }
-
+ throw new InvalidDataException("Could not load module definitions.", "");
+ }
+
// Start with default props from kernel jar
try {
mC2KProps = FileStringUtility.loadConfigFile( Resource.getKernelResourceURL("textFiles/defaultConf.properties").toString());
diff --git a/src/main/java/com/c2kernel/process/Module.java b/src/main/java/com/c2kernel/process/Module.java
index e2a4f2e..6e5f8d1 100644
--- a/src/main/java/com/c2kernel/process/Module.java
+++ b/src/main/java/com/c2kernel/process/Module.java
@@ -47,21 +47,28 @@ public class Module {
private final ArrayList<ModuleImport> imports = new ArrayList<ModuleImport>();
private static DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
private final DocumentBuilder parser;
+ private Document moduleDOM;
static {
dbf.setValidating(false);
dbf.setNamespaceAware(false);
}
- public Module(String moduleXML) throws Exception {
- parser = dbf.newDocumentBuilder();
- Document moduleDOM = parser.parse(new InputSource(new StringReader(moduleXML)));
-
+ public Module(String moduleXML) throws ModuleException {
+ try {
+ parser = dbf.newDocumentBuilder();
+ moduleDOM = parser.parse(new InputSource(new StringReader(moduleXML)));
+ } catch (Exception e) {
+ Logger.error(e);
+ throw new ModuleException("Could not process modules. XML Parser exception");
+ }
+
Element root = (Element)moduleDOM.getElementsByTagName("CristalModule").item(0);
// Get module metadata
ns = root.getAttribute("ns");
name = root.getAttribute("name");
+
Element info = (Element)moduleDOM.getElementsByTagName("Info").item(0);
desc = ((Text)info.getElementsByTagName("Description").item(0).getFirstChild()).getData();
version = ((Text)info.getElementsByTagName("Version").item(0).getFirstChild()).getData();
@@ -95,10 +102,15 @@ public class Module {
String target = confElement.getAttribute("target");
String event = confElement.getAttribute("event");
String lang = confElement.getAttribute("lang");
- Script thisScript = new Script(lang, ((Text)confElement.getFirstChild()).getData(), ErrorInfo.class);
- // target can be 'client', 'server' or missing, which implies both.
- if (!target.equals("client")) serverScripts.put(event, thisScript);
- if (!target.equals("server")) clientScripts.put(event, thisScript);
+ try {
+ Script thisScript = new Script(lang, ((Text)confElement.getFirstChild()).getData(), ErrorInfo.class);
+ // target can be 'client', 'server' or missing, which implies both.
+ if (!target.equals("client")) serverScripts.put(event, thisScript);
+ if (!target.equals("server")) clientScripts.put(event, thisScript);
+ } catch (ScriptingEngineException e) {
+ Logger.error(e);
+ throw new ModuleException("Could not process module script");
+ }
}
// Get imports
diff --git a/src/main/java/com/c2kernel/process/ModuleManager.java b/src/main/java/com/c2kernel/process/ModuleManager.java
index e7be9e8..b336681 100644
--- a/src/main/java/com/c2kernel/process/ModuleManager.java
+++ b/src/main/java/com/c2kernel/process/ModuleManager.java
@@ -1,5 +1,6 @@
package com.c2kernel.process;
+import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Enumeration;
@@ -16,23 +17,30 @@ public class ModuleManager {
Properties props = new Properties();
boolean isServer;
- public ModuleManager(Enumeration<URL> moduleEnum, 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);
- loadedModules.add(newModule.getName());
+ 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 (Exception e) {
+ } 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);
}
}
@@ -74,7 +82,7 @@ public class ModuleManager {
ItemProxy serverEntity = (ItemProxy)Gateway.getProxyManager().getProxy(new DomainPath("/servers/"+Gateway.getProperty("ItemServer.name")));
Logger.debug(3, "Registering modules");
for (Module thisMod : modules) {
- Logger.debug(4, "Registering module "+thisMod.getName());
+ Logger.msg("Registering module "+thisMod.getName());
thisMod.importAll(serverEntity);
Logger.msg("Module "+thisMod.getName()+" registered");
}