Index: /DCWoRMS/branches/coolemall/src/schedframe/scheduling/tasks/Job.java
===================================================================
--- /DCWoRMS/branches/coolemall/src/schedframe/scheduling/tasks/Job.java	(revision 490)
+++ /DCWoRMS/branches/coolemall/src/schedframe/scheduling/tasks/Job.java	(revision 1150)
@@ -4,4 +4,5 @@
 import org.qcg.broker.schemas.resreqs.ParentType;
 import org.qcg.broker.schemas.resreqs.ResourceRequirements;
+import org.qcg.broker.schemas.resreqs.Workflow;
 import org.qcg.broker.schemas.resreqs.types.TaskStatesName;
 
@@ -31,4 +32,6 @@
 	protected boolean isRegistered;
 	
+	private int status;
+	
 	public Job(String id){
 		tasks = new ArrayList<Task>();
@@ -139,10 +142,4 @@
 			Task t = tasks.get(i);
 			isForAll = (t.getStatus() == baseStatus);
-			switch(t.getStatus()){
-				case (int)BrokerConstants.TASK_STATUS_QUEUED: 
-					return (int)BrokerConstants.TASK_STATUS_QUEUED;
-				case (int)BrokerConstants.TASK_STATUS_UNSUBMITTED:
-					return (int)BrokerConstants.TASK_STATUS_UNSUBMITTED;
-			}
 		}
 		
@@ -150,5 +147,5 @@
 			return (int)BrokerConstants.JOB_STATUS_FINISHED;
 		
-		return -1;
+		return status;
 	}
 	
@@ -182,6 +179,6 @@
 	}
 
-	public void setStatus(int status) throws Exception{
-
+	public void setStatus(int status){
+		this.status = status;
 	}
 
@@ -192,5 +189,4 @@
 	public void register(JobRegistryImpl jobRegistry) {
 		isRegistered = jobRegistry.addJob(this);
-		
 	}
 	
@@ -200,46 +196,89 @@
 	}
 	
-	private List<Task> getReadyTasks(){
-		
-		List<Task> readyTasks = new ArrayList<Task>();
+	private List<Task> getReadyTasks() throws NoSuchFieldException{
+		
+		List<Task> availableTasks = new ArrayList<Task>();
 		int size = tasks.size();
 		
 		for(int i = 0; i < size; i++){
 			int parCnt;
-			int previousTaskReadyCnt = 0;
+			int previousTaskSucceedCnt = 0;
 			Task task = tasks.get(i);
 			if(task.getStatus() != (int)BrokerConstants.TASK_STATUS_UNSUBMITTED)
 				continue;
-			try{		
-				parCnt = task.getDescription().getWorkflow().getParentCount();
-			} catch(Exception e){
-				parCnt = 0;
-			}
-			if(parCnt == 0) {
-				readyTasks.add(task);
-			}
-			else {
-				for(int j = 0; j < parCnt; j++){
-					ParentType par = task.getDescription().getWorkflow().getParent(j);
-					if(par.getTriggerState().compareTo(TaskStatesName.FINISHED) == 0){
-						try {
+			//the following procedure supports only one nested structure
+			Workflow w = task.getDescription().getWorkflow();
+			if (w == null){
+				availableTasks.add(task);
+				continue;
+			}
+			if(w.getAnd() != null) {
+				parCnt = w.getAnd().getParentOpTypeItemCount();
+				if(parCnt == 0)
+				{
+					availableTasks.add(task);
+				}
+				else
+				{
+					for(int j = 0; j < parCnt; j++){
+						ParentType par = w.getAnd().getParentOpTypeItem(j).getParent();
+						if(par.getTriggerState().compareTo(TaskStatesName.FINISHED) == 0){
 							if(!getTask(par.getContent()).isFinished()){
 								break;
 							}
-						} catch (NoSuchFieldException e) {
-							// TODO Auto-generated catch block
-							e.printStackTrace();
 						}
+						previousTaskSucceedCnt++;
 					}
-					previousTaskReadyCnt++;
-				}
-				
-				if(previousTaskReadyCnt == parCnt && task.getDescription().getWorkflow().getAnd() != null)
-						readyTasks.add(task);
-				else if(previousTaskReadyCnt > 0 && task.getDescription().getWorkflow().getOr() != null)
-					readyTasks.add(task);
+
+					if(previousTaskSucceedCnt == parCnt)
+						availableTasks.add(task);
+				}
+			} 
+			else if(w.getOr() != null) {
+				parCnt = w.getOr().getParentOpTypeItemCount();
+				if(parCnt == 0)
+				{
+					availableTasks.add(task);
+				}
+				else
+				{
+					for(int j = 0; j < parCnt; j++){
+						ParentType par = w.getOr().getParentOpTypeItem(j).getParent();
+						if(par.getTriggerState().compareTo(TaskStatesName.FINISHED) == 0){
+							if(!getTask(par.getContent()).isFinished()){
+								continue;
+							}
+						}
+						previousTaskSucceedCnt++;
+					}
+
+					if(previousTaskSucceedCnt > 0)
+						availableTasks.add(task);
+				}
+			}
+			else {
+				parCnt = w.getParentCount();
+				if(parCnt == 0)
+				{
+					availableTasks.add(task);
+				}
+				else
+				{
+					for(int j = 0; j < parCnt; j++){
+						ParentType par = w.getParent(j);
+						if(par.getTriggerState().compareTo(TaskStatesName.FINISHED) == 0){
+							if(!getTask(par.getContent()).isFinished()){
+								continue;
+							}
+						}
+						previousTaskSucceedCnt++;
+					}
+
+					if(previousTaskSucceedCnt == parCnt)
+						availableTasks.add(task);
+				}
 			}
 		}		
-		return readyTasks;
+		return availableTasks;
 	}
 	
