View Javadoc

1   /*
2    *  DISCLAIMER
3    */
4   package org.flowfuse.base.model;
5   
6   import com.opensymphony.workflow.loader.StepDescriptor;
7   import com.opensymphony.workflow.loader.WorkflowDescriptor;
8   import com.opensymphony.workflow.spi.Step;
9   import org.apache.commons.logging.Log;
10  import org.apache.commons.logging.LogFactory;
11  
12  import java.util.Date;
13  import java.io.Serializable;
14  
15  /***
16   * <p>Instances of <code>WorkflowStep</code> represent a particular step
17   * of a particular <code>Workflow</code>.</p>
18   *
19   * <p>Instances of this class wrap lower-level objects from the OS
20   * Workflow engine.  Hence, this class is not persisted itself.</p>
21   *
22   * @author <a href="stefan@flowfuse.org">Stefan Kleineikenscheidt</a>,
23   *         Flowfuse.org
24   * @see Workflow
25   * @since 1.0
26   * @version $Id: WorkflowStep.java,v 1.2 2005/11/28 21:48:37 skleinei Exp $
27   */
28  public class WorkflowStep implements Serializable {
29  
30    /***
31     * RCS ID
32     */
33    public final static String rcsid = "$Id: WorkflowStep.java,v 1.2 2005/11/28 21:48:37 skleinei Exp $";
34  
35    /***
36     * Logger
37     */
38    protected final Log logger = LogFactory.getLog(this.getClass());
39  
40    /***
41     * Identifies this WorkflowStep.  This property is required and needs
42     * to be set by the constructor.
43     */
44    private Step step = null;
45  
46    /***
47     * Workflow descriptor this step belongs to.
48     */
49    private WorkflowDescriptor workflowDescriptor = null;
50  
51    /***
52     * Holds additional information about this WorkflowStep.  This property
53     * may be null.
54     */
55    private StepDescriptor stepDescriptor = null;
56  
57    /***
58     * Builds a new WorkflowStep instance based on a given OS Workflow
59     * <code>Step</step> instance.
60     *
61     * @param step The OS Workflow <code>Step</step>.
62     */
63    public WorkflowStep(Step step, WorkflowDescriptor workflowDescriptor) {
64      this.step = step;
65      this.workflowDescriptor = workflowDescriptor;
66    }
67  
68    /***
69     * Returns the caller of this WorkflowStep.
70     * @return The caller's id.
71     */
72    public String getCaller() {
73      return this.step.getCaller();
74    }
75  
76    /***
77     * Returns the date when this step was completed (e.g. by user input).
78     *
79     * @return The step's completion date.
80     */
81    public Date getFinishDate() {
82      return this.step.getFinishDate();
83    }
84  
85    /***
86     * Returns the status of this step.
87     *
88     * @return The steps's status.
89     */
90    public String getStatus() {
91      return this.step.getStatus();
92    }
93  
94    /***
95     * Returns the action which was executed to leave the step.
96     *
97     * @return The WorkflowAction to leave this step.
98     * @see WorkflowAction
99     */
100   public WorkflowAction getAction() {
101     return new WorkflowAction(this.step.getActionId(),
102             this.workflowDescriptor);
103   }
104 
105   public String getName() {
106     initializeStepDescriptor();
107     return this.stepDescriptor.getName();
108   }
109 
110   private void initializeStepDescriptor() {
111     if(this.stepDescriptor == null) {
112       int stepId = (int) this.step.getStepId();
113       this.stepDescriptor = this.workflowDescriptor.getStep(stepId);
114     }
115   }
116 
117 }
118 
119 /* EOF */