1
2
3
4
5
6
7
8
9
10
11 package org.mule.transport.quartz.jobs;
12
13 import org.mule.api.MuleContext;
14 import org.mule.api.config.MuleProperties;
15 import org.mule.transport.quartz.QuartzConnector;
16 import org.mule.transport.quartz.i18n.QuartzMessages;
17
18 import org.quartz.Job;
19 import org.quartz.JobDataMap;
20 import org.quartz.JobExecutionContext;
21 import org.quartz.JobExecutionException;
22 import org.quartz.SchedulerContext;
23 import org.quartz.SchedulerException;
24
25
26
27
28
29
30
31
32
33
34 public class CustomJob extends AbstractJob
35 {
36 protected void doExecute(JobExecutionContext jobExecutionContext) throws JobExecutionException
37 {
38 JobDataMap jobDataMap = jobExecutionContext.getJobDetail().getJobDataMap();
39 Object tempJob = jobDataMap.get(QuartzConnector.PROPERTY_JOB_OBJECT);
40 if (tempJob == null)
41 {
42 tempJob = jobDataMap.get(QuartzConnector.PROPERTY_JOB_REF);
43 if (tempJob == null)
44 {
45 throw new JobExecutionException(QuartzMessages.invalidPayloadType().getMessage());
46 }
47 else
48 {
49 tempJob = muleContext.getRegistry().lookupObject((String) tempJob);
50 if (tempJob == null)
51 {
52 throw new JobExecutionException("Job not found: " + tempJob);
53 }
54 if (!(tempJob instanceof Job))
55 {
56 throw new JobExecutionException(QuartzMessages.invalidJobObject().getMessage());
57 }
58 }
59 }
60 else if (!(tempJob instanceof Job))
61 {
62 throw new JobExecutionException(QuartzMessages.invalidJobObject().toString());
63 }
64 ((Job)tempJob).execute(jobExecutionContext);
65 }
66 }