final List<Timer> timers = timerConsumer.getTimer();
// TODO : The NamedMethod object implements equals and hashCode, so we could rely on that rather than collecting strings
final Set<String> methodsConfiguredInDeploymentXml = new HashSet<String>();
for (final Timer timer : timers) {
final NamedMethod namedMethod = timer.getTimeoutMethod();
methodsConfiguredInDeploymentXml.add(namedMethod.getMethodName() + (namedMethod.getMethodParams() == null ? "" : Join.join("", namedMethod.getMethodParams().getMethodParam())));
}
for (final Annotated<Method> method : scheduleMethods) {
// Don't add the schedules from annotations if the schedules have been
// supplied for this method via xml. The xml is considered an override.
if (methodsConfiguredInDeploymentXml.contains(method.get().getName() + Join.join("", (Object[]) asStrings(method.get().getParameterTypes())))) {
continue;
}
final List<Schedule> scheduleAnnotationList = new ArrayList<Schedule>();
final Schedules schedulesAnnotation = method.getAnnotation(Schedules.class);
if (schedulesAnnotation != null) {
scheduleAnnotationList.addAll(Arrays.asList(schedulesAnnotation.value()));
}
final Schedule scheduleAnnotation = method.getAnnotation(Schedule.class);
if (scheduleAnnotation != null) {
scheduleAnnotationList.add(scheduleAnnotation);
}
for (final Schedule schedule : scheduleAnnotationList) {
final Timer timer = new Timer();
timer.setPersistent(schedule.persistent());
timer.setInfo(schedule.info() == null || schedule.info().isEmpty() ? null : schedule.info());
timer.setTimezone(schedule.timezone() == null || schedule.timezone().isEmpty() ? null : schedule.timezone());
//Copy TimerSchedule
final TimerSchedule timerSchedule = new TimerSchedule();
timerSchedule.setSecond(schedule.second());
timerSchedule.setMinute(schedule.minute());
timerSchedule.setHour(schedule.hour());
timerSchedule.setDayOfWeek(schedule.dayOfWeek());
timerSchedule.setDayOfMonth(schedule.dayOfMonth());
timerSchedule.setMonth(schedule.month());
timerSchedule.setYear(schedule.year());
timer.setSchedule(timerSchedule);
//Copy Method Signature
timer.setTimeoutMethod(new NamedMethod(method.get()));
timers.add(timer);
}
}
}