summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Branson <andrew.branson@cern.ch>2012-11-09 09:55:43 +0100
committerAndrew Branson <andrew.branson@cern.ch>2012-11-09 09:55:43 +0100
commit8a0ee840f4b9f91ce5ba5ae3ea86320a3dbf2998 (patch)
tree9dd6f5d31ab927929af3c4ce74e615ddfe6974e1
parent1e67b454efd84a88877205917038da13a47a2f6b (diff)
Validate module xml against schema before unmarshalling. Fixes #82
-rw-r--r--src/main/java/com/c2kernel/process/module/ModuleManager.java18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/main/java/com/c2kernel/process/module/ModuleManager.java b/src/main/java/com/c2kernel/process/module/ModuleManager.java
index 6eb37c9..e78c25d 100644
--- a/src/main/java/com/c2kernel/process/module/ModuleManager.java
+++ b/src/main/java/com/c2kernel/process/module/ModuleManager.java
@@ -1,5 +1,6 @@
package com.c2kernel.process.module;
+import java.io.IOException;
import java.net.URL;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
@@ -8,11 +9,14 @@ import java.util.HashMap;
import java.util.Properties;
import com.c2kernel.common.CannotManageException;
+import com.c2kernel.common.InvalidDataException;
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.persistency.outcome.OutcomeValidator;
+import com.c2kernel.persistency.outcome.Schema;
import com.c2kernel.process.Gateway;
import com.c2kernel.scripting.ScriptingEngineException;
import com.c2kernel.utils.FileStringUtility;
@@ -24,15 +28,29 @@ public class ModuleManager {
HashMap<String, String> modulesXML = new HashMap<String, String>();
Properties props = new Properties();
boolean isServer;
+ OutcomeValidator moduleValidator;
public ModuleManager(Enumeration<URL> moduleEnum, boolean isServer) throws ModuleException {
this.isServer = isServer;
+ try {
+ Schema moduleSchema = new Schema("Module", 0, false,
+ FileStringUtility.url2String(Resource.getKernelResourceURL("boot/OD/Module.xsd")));
+ moduleValidator = new OutcomeValidator(moduleSchema);
+ } catch (InvalidDataException ex) {
+ Logger.error(ex);
+ throw new ModuleException("Module Schema is not valid");
+ } catch (IOException ex) {
+ throw new ModuleException("Could not load Module Schema from kernel resources");
+ }
ArrayList<String> loadedModules = new ArrayList<String>();
ArrayList<String> moduleNs = new ArrayList<String>();
while(moduleEnum.hasMoreElements()) {
URL newModuleURL = moduleEnum.nextElement();
try {
String moduleXML = FileStringUtility.url2String(newModuleURL);
+ String errors = moduleValidator.validate(moduleXML);
+ if (errors.length() > 0)
+ throw new ModuleException("Module XML found at "+newModuleURL+" was not valid: "+errors);
Module newModule = (Module)Gateway.getMarshaller().unmarshall(moduleXML);
Resource.addModuleBaseURL(newModule.ns, newModule.resURL);
modules.add(newModule);