2006/unicorn/src/org/w3c/unicorn/tasklist TaskListUnmarshallerBeans.java,1.1.2.1,1.1.2.2

Update of /sources/public/2006/unicorn/src/org/w3c/unicorn/tasklist
In directory hutz:/tmp/cvs-serv31117/src/org/w3c/unicorn/tasklist

Modified Files:
      Tag: dev2
	TaskListUnmarshallerBeans.java 
Log Message:
addTask() throws UnknownOberverException in case a task references an observer that doesn't exist

Index: TaskListUnmarshallerBeans.java
===================================================================
RCS file: /sources/public/2006/unicorn/src/org/w3c/unicorn/tasklist/Attic/TaskListUnmarshallerBeans.java,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -u -d -r1.1.2.1 -r1.1.2.2
--- TaskListUnmarshallerBeans.java	11 Aug 2009 16:05:40 -0000	1.1.2.1
+++ TaskListUnmarshallerBeans.java	17 Aug 2009 16:35:22 -0000	1.1.2.2
@@ -30,6 +30,7 @@
 import org.w3c.unicorn.contract.InputMethod;
 import org.w3c.unicorn.contract.Observer;
 import org.w3c.unicorn.exceptions.ParameterException;
+import org.w3c.unicorn.exceptions.UnknownObserverException;
 import org.w3c.unicorn.tasklist.parameters.Mapping;
 import org.w3c.unicorn.tasklist.parameters.Parameter;
 import org.w3c.unicorn.tasklist.parameters.ParameterFactory;
@@ -74,7 +75,7 @@
 		this.mapOfObserver = mapOfObserver;
 	}
 
-	private void addTask(final TaskType aTask) throws ParameterException {
+	private void addTask(final TaskType aTask) throws ParameterException, UnknownObserverException {
 		TaskListUnmarshallerBeans.logger.trace("addTask");
 
 		if (aTask == null) {
@@ -82,10 +83,8 @@
 			return;
 		}
 
-		if (TaskListUnmarshallerBeans.logger.isDebugEnabled()) {
-			TaskListUnmarshallerBeans.logger.trace("Add task : "
-					+ aTask.getId());
-		}
+		TaskListUnmarshallerBeans.logger.trace("Add task : "
+				+ aTask.getId());
 
 		final Task aTaskCurrent = new Task();
 		// Create the execution level tree
@@ -359,8 +358,9 @@
 	 * 
 	 * @param myTask
 	 *            the task to transform into a tree
+	 * @throws UnknownObserverException 
 	 */
-	public TLTNode ExpandTree(TaskType myTask) {
+	public TLTNode ExpandTree(TaskType myTask) throws UnknownObserverException {
 		TaskListUnmarshallerBeans.logger
 				.trace("Creation of the tree based on the Task "
 						+ myTask.getId());
@@ -368,6 +368,8 @@
 		root.setID(NodeID++);
 		for (ExecType exec : myTask.getRoutine().getExecArray()) {
 			final Observer obs = Framework.mapOfObserver.get(exec.getValue());
+			if (obs == null)
+				throw new UnknownObserverException("The observer " + exec.getValue() + " does not exist. Exec ID: " + exec.getId());
 			root.addExec(new TLTExec(exec.getId(), obs, exec.getValue(), exec
 					.getType(), exec.getParam()));
 		}
@@ -383,13 +385,16 @@
 	 * @param myThen
 	 *            the ThenType node for the recursion
 	 * @return the node created
+	 * @throws UnknownObserverException 
 	 */
-	private TLTNode FillNode(TaskType myTask, ThenType myThen) {
+	private TLTNode FillNode(TaskType myTask, ThenType myThen) throws UnknownObserverException {
 		TaskListUnmarshallerBeans.logger.trace("Creation of a then branch ");
 		TLTNode node = new TLTNode();
 		node.setID(NodeID++);
 		for (ExecType exec : myThen.getExecArray()) {
 			final Observer obs = Framework.mapOfObserver.get(exec.getValue());
+			if (obs==null)
+				throw new UnknownObserverException("The observer " + exec.getValue() + " does not exist. Exec ID: " + exec.getId());
 			node.addExec(new TLTExec(exec.getId(), obs, exec.getValue(), exec
 					.getType(), exec.getParam()));
 		}
@@ -405,8 +410,9 @@
 	 * @param ifs
 	 *            the IfType node template to create the Ifnode
 	 * @return the node created
+	 * @throws UnknownObserverException 
 	 */
-	private TLTIf fillIfs(TaskType myTask, IfType ifs) {
+	private TLTIf fillIfs(TaskType myTask, IfType ifs) throws UnknownObserverException {
 		TaskListUnmarshallerBeans.logger.trace("Creation of an If ");
 		// Create the if node
 		TLTIf ifnode = new TLTIf();
@@ -520,7 +526,7 @@
 		}
 	}
 
-	public void unmarshal() throws Exception {
+	public void unmarshal() {
 		TaskListUnmarshallerBeans.logger.trace("unmarshal tasklist");
 		// creates the tasklist without computing references
 		for (final TaskType aTask : this.aTaskList.getTasklist().getTaskArray()) {
@@ -528,7 +534,15 @@
 				TaskListUnmarshallerBeans.logger.warn("Task with id "
 						+ aTask.getId() + " already defined.");
 			} else {
-				this.addTask(aTask);
+				try {
+					Framework.logger.debug("> Found task: " + aTask.getId());
+					this.addTask(aTask);
+					Framework.logger.debug("Successfully loaded task: " + aTask.getId());
+				} catch (ParameterException e) {
+					Framework.logger.error("Task \"" + aTask.getId() + "\" threw a ParameterException. This task is ignored.", e);
+				} catch (UnknownObserverException e) {
+					Framework.logger.warn("Task \"" + aTask.getId() + "\" references an unknown observer. This task is ignored.", e);
+				}
 			}
 		}
 

Received on Monday, 17 August 2009 16:35:39 UTC