KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jbpm > scheduler > def > CreateTimerAction


1 package org.jbpm.scheduler.def;
2
3 import java.util.Date JavaDoc;
4
5 import org.dom4j.Element;
6 import org.jbpm.calendar.BusinessCalendar;
7 import org.jbpm.calendar.Duration;
8 import org.jbpm.graph.def.Action;
9 import org.jbpm.graph.exe.ExecutionContext;
10 import org.jbpm.jpdl.xml.JpdlXmlReader;
11 import org.jbpm.scheduler.exe.Timer;
12
13 public class CreateTimerAction extends Action {
14
15   private static final long serialVersionUID = 1L;
16   private static BusinessCalendar businessCalendar = new BusinessCalendar();
17
18   String JavaDoc timerName = null;
19   String JavaDoc dueDate = null;
20   String JavaDoc repeat = null;
21   String JavaDoc transitionName = null;
22   Action timerAction = null;
23   
24   public void read(Element actionElement, JpdlXmlReader jpdlReader) {
25     timerName = actionElement.attributeValue("name");
26     timerAction = jpdlReader.readSingleAction(actionElement);
27     
28     dueDate = actionElement.attributeValue("duedate");
29     if (dueDate==null) {
30       jpdlReader.addWarning("no duedate specified in create timer action '"+actionElement+"'");
31     }
32     repeat = actionElement.attributeValue("repeat");
33     if ( "true".equalsIgnoreCase(repeat)
34          || "yes".equalsIgnoreCase(repeat) ) {
35       repeat = dueDate;
36     }
37     transitionName = actionElement.attributeValue("transition");
38   }
39
40   public void execute(ExecutionContext executionContext) throws Exception JavaDoc {
41     Duration duration = new Duration(dueDate);
42     Date JavaDoc dueDate = businessCalendar.add( new Date JavaDoc(), duration );
43     
44     Timer timer = new Timer(executionContext.getToken());
45     timer.setName(timerName);
46     timer.setRepeat(repeat);
47     timer.setDueDate(dueDate);
48     timer.setAction(timerAction);
49     timer.setTransitionName(transitionName);
50     timer.setGraphElement(executionContext.getEventSource());
51     timer.setTaskInstance(executionContext.getTaskInstance());
52
53     executionContext.getSchedulerInstance().schedule(timer);
54   }
55   public String JavaDoc getDueDate() {
56     return dueDate;
57   }
58   public void setDueDate(String JavaDoc dueDateDuration) {
59     this.dueDate = dueDateDuration;
60   }
61   public String JavaDoc getRepeat() {
62     return repeat;
63   }
64   public void setRepeat(String JavaDoc repeatDuration) {
65     this.repeat = repeatDuration;
66   }
67   public String JavaDoc getTransitionName() {
68     return transitionName;
69   }
70   public void setTransitionName(String JavaDoc transitionName) {
71     this.transitionName = transitionName;
72   }
73   public String JavaDoc getTimerName() {
74     return timerName;
75   }
76   public void setTimerName(String JavaDoc timerName) {
77     this.timerName = timerName;
78   }
79   public Action getTimerAction() {
80     return timerAction;
81   }
82   public void setTimerAction(Action timerAction) {
83     this.timerAction = timerAction;
84   }
85 }
86
Popular Tags