}
protected Timer createTimer(ExecutionContext executionContext) {
Date baseDate = null;
Date dueDateDate = null;
Duration duration;
String durationString = null;
String durationSeparator = null;
Timer timer = new Timer(executionContext.getToken());
timer.setName(timerName);
timer.setRepeat(repeat);
if (dueDate!=null) {
if (dueDate.startsWith("#")) {
String baseDateEL = dueDate.substring(0,dueDate.indexOf("}")+1);
Object o = JbpmExpressionEvaluator.evaluate(baseDateEL, executionContext);
if (o instanceof Date) {
baseDate = (Date) o;
} else {
if (o instanceof Calendar) {
baseDate = ((Calendar) o).getTime();
} else {
throw new JbpmException("Invalid basedate type: " + baseDateEL + " is of type " + o.getClass().getName() +". Only Date and Calendar are supported");
}
}
int endOfELIndex = dueDate.indexOf("}");
if (endOfELIndex < (dueDate.length() -1) ) {
durationSeparator = dueDate.substring(endOfELIndex+1).trim().substring(0,1);
if ( !(durationSeparator.equals("+") || durationSeparator.equals("-") ) ){
throw new JbpmException("Invalid duedate, + or - missing after EL");
}
durationString = dueDate.substring(endOfELIndex+1).trim();
}
} else {
durationString = dueDate;
}
if (baseDate != null && (durationString == null || durationString.length() == 0)) {
dueDateDate = baseDate;
} else {
duration = new Duration(durationString);
dueDateDate = businessCalendar.add( (baseDate != null) ? baseDate : Clock.getCurrentTime(), duration );
}
timer.setDueDate(dueDateDate);
}
timer.setAction(timerAction);