View Javadoc

1   /*$Id: JesUtil.java,v 1.9 2004/12/03 14:47:41 jdt Exp $
2    * Created on 03-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.jes.types.v1.cea.axis.JobIdentifierType;
14  import org.astrogrid.workflow.beans.v1.Step;
15  import org.astrogrid.workflow.beans.v1.Workflow;
16  import org.astrogrid.workflow.beans.v1.execution.StepExecutionRecord;
17  
18  import org.apache.commons.logging.Log;
19  import org.apache.commons.logging.LogFactory;
20  
21  import java.util.Iterator;
22  
23  /*** class of static helper methods.
24   * <p>
25   * primarily stuff for mappinig between castor and axis object models.
26   * @author Noel Winstanley nw@jb.man.ac.uk 03-Mar-2004
27   *
28   */
29  public class JesUtil {
30      /***
31       * Commons Logger for this class
32       */
33      private static final Log logger = LogFactory.getLog(JesUtil.class);
34  
35      /*** Construct a new JesUtil
36       * 
37       */
38      private JesUtil() {
39          super();
40      }
41    
42      /*** return an iterator of all job steps in the workflow
43       * 
44       * @param wf workflow
45       * @return non-null iterator of step objects
46       * @see org.astrogrid.workflow.beans.v1.Step
47       */    
48      public static Iterator getJobSteps(Workflow wf) {
49          wf.addFunctions(JesFunctions.FUNCTIONS);
50          return wf.findXPathIterator("//*[jes:isStep()]");
51      }
52      /*** extract the jobURN portion of a job identifier
53       * @see #createJobId(org.astrogrid.workflow.beans.v1.execution.JobURN, String)
54       * @param id job identifier
55       * @return the urn portion of the identifier.
56       */
57      public static org.astrogrid.workflow.beans.v1.execution.JobURN extractURN(JobIdentifierType id) {
58           if (id == null) {
59               return null;
60           }
61           int pos = id.getValue().lastIndexOf('#');
62           org.astrogrid.workflow.beans.v1.execution.JobURN result = new org.astrogrid.workflow.beans.v1.execution.JobURN();
63           result.setContent(id.getValue().substring(0,pos));
64           return result;
65       }
66  
67      /*** extract the xpath portion of a job identifier
68       * @see #createJobId(org.astrogrid.workflow.beans.v1.execution.JobURN, String)
69       * @param id job identifier 
70       * @return xpath portion of the identifier
71       * @todo maybe rename, if scripting extension takes off - as its not an xpath any more.
72       */
73       public static String extractXPath(JobIdentifierType id) {
74           if (id == null) {
75               return null;
76           }
77           int pos = id.getValue().lastIndexOf('#');
78           return id.getValue().substring(pos + 1);
79       }
80      
81      /*** create a job identifier - for passing out into an application contorller - from a jobURN and xpath of the step to execute */
82       public static JobIdentifierType createJobId(org.astrogrid.workflow.beans.v1.execution.JobURN urn, String xpath) {
83           JobIdentifierType id = new JobIdentifierType();
84           id.setValue(urn.getContent() + "#" + xpath);
85           return id;
86       }
87      
88       /*** gets most recent record step. if none present, will insert one */
89       public static StepExecutionRecord getLatestOrNewRecord(Step s) {
90           int count = s.getStepExecutionRecordCount();
91           if (count ==0) {
92               StepExecutionRecord rec = new StepExecutionRecord();
93               s.addStepExecutionRecord(rec);
94               return rec;            
95           } else {
96               return s.getStepExecutionRecord(count-1);
97           }
98       }
99  
100 
101 
102 /*** extract mesasges from a chain of exceptions 
103  * */
104 public static String getMessageChain(Throwable  e) {
105     StringBuffer buff = new StringBuffer();
106     Throwable next = e;
107     boolean first = true;
108     while (next != null) {
109         if (!first) {
110             buff.append("\n caused by \n");
111         }
112         first = false;
113         
114         buff.append(next.getClass().getName());
115         buff.append(" ");
116         buff.append(next.getMessage());
117         next = next.getCause();
118     }
119     return buff.toString();        
120 }
121 }
122 
123 /* 
124 $Log: JesUtil.java,v $
125 Revision 1.9  2004/12/03 14:47:41  jdt
126 Merges from workflow-nww-776
127 
128 Revision 1.8.2.1  2004/12/01 21:47:44  nw
129 moved castor-axis conversion methods to workflow-objects
130 
131 Revision 1.8  2004/11/29 20:00:24  clq2
132 jes-nww-714
133 
134 Revision 1.7.100.3  2004/11/25 23:48:13  nw
135 formatting
136 
137 Revision 1.7.100.2  2004/11/25 23:43:07  nw
138 bugfix
139 
140 Revision 1.7.100.1  2004/11/25 23:34:34  nw
141 improved error messages reported from jes
142 
143 Revision 1.7  2004/07/09 09:30:28  nw
144 merged in scripting workflow interpreter from branch
145 nww-x-workflow-extensions
146 
147 Revision 1.6  2004/07/01 21:15:00  nw
148 added results-listener interface to jes
149 
150 Revision 1.5  2004/03/18 16:41:57  pah
151 moved the axis2castor stuff to the common project under beans package
152 
153 Revision 1.4  2004/03/15 23:45:07  nw
154 improved javadoc
155 
156 Revision 1.3  2004/03/09 14:23:12  nw
157 integrated new JobController wsdl interface
158 
159 Revision 1.2  2004/03/05 16:16:23  nw
160 worked now object model through jes.
161 implemented basic scheduling policy
162 removed internal facade
163 
164 Revision 1.1  2004/03/04 01:57:35  nw
165 major refactor.
166 upgraded to latest workflow object model.
167 removed internal facade
168 replaced community snippet with objects
169  
170 */