View Javadoc

1   /*$Id: JesFunctions.java,v 1.2 2004/03/15 23:45:07 nw Exp $
2    * Created on 05-Mar-2004
3    *
4    * Copyright (C) AstroGrid. All rights reserved.
5    *
6    * This software is published under the terms of the AstroGrid 
7    * Software License version 1.2, a copy of which has been included 
8    * with this distribution in the LICENSE.txt file.  
9    *
10  **/
11  package org.astrogrid.jes.util;
12  
13  import org.astrogrid.applications.beans.v1.cea.castor.types.ExecutionPhase;
14  import org.astrogrid.workflow.beans.v1.Step;
15  
16  import org.apache.commons.jxpath.ClassFunctions;
17  import org.apache.commons.jxpath.ExpressionContext;
18  import org.apache.commons.jxpath.Functions;
19  import org.apache.commons.jxpath.Pointer;
20  
21  
22  /*** A class of jxpath functions,used within policy implementations to search a workflow tree */
23  public class JesFunctions {
24      public static final Functions FUNCTIONS = new ClassFunctions(JesFunctions.class,"jes");
25      /*** returns true if the current node is a step that is in the 'Pending' Execition Phase*/
26      public static boolean isPendingStep(ExpressionContext ctxt) {
27          Pointer p = ctxt.getContextNodePointer();
28          if (p == null) {
29              return false;
30          }
31          Object o = p.getValue();
32          if (! (o instanceof Step)) {
33              return false;
34          }
35          Step s = (Step)o;
36          int count = s.getStepExecutionRecordCount();
37          if (count  == 0) {
38              return true;
39          } else {
40              return s.getStepExecutionRecord(count-1).getStatus().getType() == ExecutionPhase.PENDING_TYPE;
41          }
42      }
43      /*** returns true if the current node is a step */
44      public static boolean isStep(ExpressionContext ctxt) {
45          Pointer p = ctxt.getContextNodePointer();            
46          if (p  == null) {
47              return false;
48          }
49          return p.getValue() instanceof Step;
50      }
51      /*** count the number of execution records contained in this step */
52      public static int execCount(ExpressionContext ctxt) {
53          Pointer p = ctxt.getContextNodePointer();
54          if (p == null) {
55              return 0;
56          }
57          Step step = (Step)p.getValue();
58          if (step == null) {
59              return 0;
60          }
61          return step.getStepExecutionRecordCount();
62      }
63      /*** access the latest status (Execution Phase) for this step */
64      public static String latestStatus(ExpressionContext ctxt) {
65          Pointer p = ctxt.getContextNodePointer();
66          if (p == null) {
67              return "null";
68          } 
69          Step step = (Step)p.getValue();
70          if (step == null) {
71              return "null";
72          }
73          int pos = step.getStepExecutionRecordCount();
74          if (pos == 0) {
75              return ExecutionPhase.PENDING.toString();
76          } else {
77              return step.getStepExecutionRecord(pos-1).getStatus().toString();
78      }
79      }
80  }
81  
82  /* 
83  $Log: JesFunctions.java,v $
84  Revision 1.2  2004/03/15 23:45:07  nw
85  improved javadoc
86  
87  Revision 1.1  2004/03/05 16:16:24  nw
88  worked now object model through jes.
89  implemented basic scheduling policy
90  removed internal facade
91   
92  */