1
1
/*
2
- * Copyright 2002-2013 the original author or authors.
2
+ * Copyright 2002-2014 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
54
54
* <p>Compatible with Quartz 1.5+ as well as Quartz 2.0-2.2, as of Spring 3.2.
55
55
*
56
56
* @author Juergen Hoeller
57
+ * @author Stephane Nicoll
57
58
* @since 2.5.6
58
59
*/
59
60
public abstract class SchedulerAccessor implements ResourceLoaderAware {
@@ -63,6 +64,7 @@ public abstract class SchedulerAccessor implements ResourceLoaderAware {
63
64
private static Class <?> triggerKeyClass ;
64
65
65
66
static {
67
+ // Quartz 2.0 job/trigger key available?
66
68
try {
67
69
jobKeyClass = Class .forName ("org.quartz.JobKey" );
68
70
triggerKeyClass = Class .forName ("org.quartz.TriggerKey" );
@@ -258,7 +260,7 @@ protected void registerJobsAndTriggers() throws SchedulerException {
258
260
clh .initialize ();
259
261
try {
260
262
// Quartz 1.8 or higher?
261
- Class dataProcessorClass = getClass ().getClassLoader ().loadClass ("org.quartz.xml.XMLSchedulingDataProcessor" );
263
+ Class <?> dataProcessorClass = getClass ().getClassLoader ().loadClass ("org.quartz.xml.XMLSchedulingDataProcessor" );
262
264
logger .debug ("Using Quartz 1.8 XMLSchedulingDataProcessor" );
263
265
Object dataProcessor = dataProcessorClass .getConstructor (ClassLoadHelper .class ).newInstance (clh );
264
266
Method processFileAndScheduleJobs = dataProcessorClass .getMethod ("processFileAndScheduleJobs" , String .class , Scheduler .class );
@@ -268,7 +270,7 @@ protected void registerJobsAndTriggers() throws SchedulerException {
268
270
}
269
271
catch (ClassNotFoundException ex ) {
270
272
// Quartz 1.6
271
- Class dataProcessorClass = getClass ().getClassLoader ().loadClass ("org.quartz.xml.JobSchedulingDataProcessor" );
273
+ Class <?> dataProcessorClass = getClass ().getClassLoader ().loadClass ("org.quartz.xml.JobSchedulingDataProcessor" );
272
274
logger .debug ("Using Quartz 1.6 JobSchedulingDataProcessor" );
273
275
Object dataProcessor = dataProcessorClass .getConstructor (ClassLoadHelper .class , boolean .class , boolean .class ).newInstance (clh , true , true );
274
276
Method processFileAndScheduleJobs = dataProcessorClass .getMethod ("processFileAndScheduleJobs" , String .class , Scheduler .class , boolean .class );
@@ -396,7 +398,8 @@ private JobDetail findJobDetail(Trigger trigger) {
396
398
}
397
399
else {
398
400
try {
399
- Map <?, ?> jobDataMap = (Map <?, ?>) ReflectionUtils .invokeMethod (Trigger .class .getMethod ("getJobDataMap" ), trigger );
401
+ Map <?, ?> jobDataMap =
402
+ (Map <?, ?>) ReflectionUtils .invokeMethod (Trigger .class .getMethod ("getJobDataMap" ), trigger );
400
403
return (JobDetail ) jobDataMap .remove (JobDetailAwareTrigger .JOB_DETAIL_KEY );
401
404
}
402
405
catch (NoSuchMethodException ex ) {
@@ -473,19 +476,33 @@ protected void registerListeners() throws SchedulerException {
473
476
target = getScheduler ();
474
477
quartz2 = false ;
475
478
}
479
+ Class <?> targetClass = target .getClass ();
476
480
477
481
try {
478
482
if (this .schedulerListeners != null ) {
479
- Method addSchedulerListener = target . getClass () .getMethod ("addSchedulerListener" , SchedulerListener .class );
483
+ Method addSchedulerListener = targetClass .getMethod ("addSchedulerListener" , SchedulerListener .class );
480
484
for (SchedulerListener listener : this .schedulerListeners ) {
481
485
ReflectionUtils .invokeMethod (addSchedulerListener , target , listener );
482
486
}
483
487
}
484
488
if (this .globalJobListeners != null ) {
485
- Method addJobListener = target .getClass ().getMethod (
486
- (quartz2 ? "addJobListener" : "addGlobalJobListener" ), JobListener .class );
489
+ Method addJobListener ;
490
+ if (quartz2 ) {
491
+ // addJobListener(JobListener) only introduced as late as Quartz 2.2, so we need
492
+ // to fall back to the Quartz 2.0/2.1 compatible variant with an empty matchers List
493
+ addJobListener = targetClass .getMethod ("addJobListener" , JobListener .class , List .class );
494
+ }
495
+ else {
496
+ addJobListener = targetClass .getMethod ("addGlobalJobListener" , JobListener .class );
497
+ }
487
498
for (JobListener listener : this .globalJobListeners ) {
488
- ReflectionUtils .invokeMethod (addJobListener , target , listener );
499
+ if (quartz2 ) {
500
+ List <?> emptyMatchers = new LinkedList <Object >();
501
+ ReflectionUtils .invokeMethod (addJobListener , target , listener , emptyMatchers );
502
+ }
503
+ else {
504
+ ReflectionUtils .invokeMethod (addJobListener , target , listener );
505
+ }
489
506
}
490
507
}
491
508
if (this .jobListeners != null ) {
@@ -498,10 +515,23 @@ protected void registerListeners() throws SchedulerException {
498
515
}
499
516
}
500
517
if (this .globalTriggerListeners != null ) {
501
- Method addTriggerListener = target .getClass ().getMethod (
502
- (quartz2 ? "addTriggerListener" : "addGlobalTriggerListener" ), TriggerListener .class );
518
+ Method addTriggerListener ;
519
+ if (quartz2 ) {
520
+ // addTriggerListener(TriggerListener) only introduced as late as Quartz 2.2, so we need
521
+ // to fall back to the Quartz 2.0/2.1 compatible variant with an empty matchers List
522
+ addTriggerListener = targetClass .getMethod ("addTriggerListener" , TriggerListener .class , List .class );
523
+ }
524
+ else {
525
+ addTriggerListener = targetClass .getMethod ("addGlobalTriggerListener" , TriggerListener .class );
526
+ }
503
527
for (TriggerListener listener : this .globalTriggerListeners ) {
504
- ReflectionUtils .invokeMethod (addTriggerListener , target , listener );
528
+ if (quartz2 ) {
529
+ List <?> emptyMatchers = new LinkedList <Object >();
530
+ ReflectionUtils .invokeMethod (addTriggerListener , target , listener , emptyMatchers );
531
+ }
532
+ else {
533
+ ReflectionUtils .invokeMethod (addTriggerListener , target , listener );
534
+ }
505
535
}
506
536
}
507
537
if (this .triggerListeners != null ) {
0 commit comments