11/*
2- * Copyright 2002-2013 the original author or authors.
2+ * Copyright 2002-2014 the original author or authors.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
5656 * <b>Note:</b> Quartz 1.x support is deprecated - please upgrade to Quartz 2.0+.
5757 *
5858 * @author Juergen Hoeller
59+ * @author Stephane Nicoll
5960 * @since 2.5.6
6061 */
6162public abstract class SchedulerAccessor implements ResourceLoaderAware {
@@ -395,7 +396,8 @@ private JobDetail findJobDetail(Trigger trigger) {
395396 }
396397 else {
397398 try {
398- Map <?, ?> jobDataMap = (Map <?, ?>) ReflectionUtils .invokeMethod (Trigger .class .getMethod ("getJobDataMap" ), trigger );
399+ Map <?, ?> jobDataMap =
400+ (Map <?, ?>) ReflectionUtils .invokeMethod (Trigger .class .getMethod ("getJobDataMap" ), trigger );
399401 return (JobDetail ) jobDataMap .remove (JobDetailAwareTrigger .JOB_DETAIL_KEY );
400402 }
401403 catch (NoSuchMethodException ex ) {
@@ -472,19 +474,33 @@ protected void registerListeners() throws SchedulerException {
472474 target = getScheduler ();
473475 quartz2 = false ;
474476 }
477+ Class <?> targetClass = target .getClass ();
475478
476479 try {
477480 if (this .schedulerListeners != null ) {
478- Method addSchedulerListener = target . getClass () .getMethod ("addSchedulerListener" , SchedulerListener .class );
481+ Method addSchedulerListener = targetClass .getMethod ("addSchedulerListener" , SchedulerListener .class );
479482 for (SchedulerListener listener : this .schedulerListeners ) {
480483 ReflectionUtils .invokeMethod (addSchedulerListener , target , listener );
481484 }
482485 }
483486 if (this .globalJobListeners != null ) {
484- Method addJobListener = target .getClass ().getMethod (
485- (quartz2 ? "addJobListener" : "addGlobalJobListener" ), JobListener .class );
487+ Method addJobListener ;
488+ if (quartz2 ) {
489+ // addJobListener(JobListener) only introduced as late as Quartz 2.2, so we need
490+ // to fall back to the Quartz 2.0/2.1 compatible variant with an empty matchers List
491+ addJobListener = targetClass .getMethod ("addJobListener" , JobListener .class , List .class );
492+ }
493+ else {
494+ addJobListener = targetClass .getMethod ("addGlobalJobListener" , JobListener .class );
495+ }
486496 for (JobListener listener : this .globalJobListeners ) {
487- ReflectionUtils .invokeMethod (addJobListener , target , listener );
497+ if (quartz2 ) {
498+ List <?> emptyMatchers = new LinkedList <Object >();
499+ ReflectionUtils .invokeMethod (addJobListener , target , listener , emptyMatchers );
500+ }
501+ else {
502+ ReflectionUtils .invokeMethod (addJobListener , target , listener );
503+ }
488504 }
489505 }
490506 if (this .jobListeners != null ) {
@@ -497,10 +513,23 @@ protected void registerListeners() throws SchedulerException {
497513 }
498514 }
499515 if (this .globalTriggerListeners != null ) {
500- Method addTriggerListener = target .getClass ().getMethod (
501- (quartz2 ? "addTriggerListener" : "addGlobalTriggerListener" ), TriggerListener .class );
516+ Method addTriggerListener ;
517+ if (quartz2 ) {
518+ // addTriggerListener(TriggerListener) only introduced as late as Quartz 2.2, so we need
519+ // to fall back to the Quartz 2.0/2.1 compatible variant with an empty matchers List
520+ addTriggerListener = targetClass .getMethod ("addTriggerListener" , TriggerListener .class , List .class );
521+ }
522+ else {
523+ addTriggerListener = targetClass .getMethod ("addGlobalTriggerListener" , TriggerListener .class );
524+ }
502525 for (TriggerListener listener : this .globalTriggerListeners ) {
503- ReflectionUtils .invokeMethod (addTriggerListener , target , listener );
526+ if (quartz2 ) {
527+ List <?> emptyMatchers = new LinkedList <Object >();
528+ ReflectionUtils .invokeMethod (addTriggerListener , target , listener , emptyMatchers );
529+ }
530+ else {
531+ ReflectionUtils .invokeMethod (addTriggerListener , target , listener );
532+ }
504533 }
505534 }
506535 if (this .triggerListeners != null ) {
0 commit comments