KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > providers > quartz > jobs > DelegatingJob


1 /*
2  * $Id: DelegatingJob.java 3982 2006-11-22 14:28:01Z lajos $
3  * --------------------------------------------------------------------------------------
4  * Copyright (c) MuleSource, Inc. All rights reserved. http://www.mulesource.com
5  *
6  * The software in this package is published under the terms of the MuleSource MPL
7  * license, a copy of which has been included with this distribution in the
8  * LICENSE.txt file.
9  */

10
11 package org.mule.providers.quartz.jobs;
12
13 import org.mule.MuleManager;
14 import org.mule.config.i18n.Message;
15 import org.mule.providers.quartz.QuartzConnector;
16 import org.mule.umo.manager.ObjectNotFoundException;
17 import org.quartz.Job;
18 import org.quartz.JobDataMap;
19 import org.quartz.JobExecutionContext;
20 import org.quartz.JobExecutionException;
21
22 /**
23  * Extracts the Job object to invoke from the context. The Job itself can be
24  * scheduled by dispatching an event over a quartz endpoint. The job can either be
25  * set as a property on the event (this property can be a container reference or the
26  * actual job object) or the payload of the event can be the Job (in which case when
27  * the job is fired it will have a NullPayload)
28  *
29  * @see org.mule.providers.NullPayload
30  */

31 public class DelegatingJob implements Job
32 {
33     public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException
34     {
35         JobDataMap jobDataMap = jobExecutionContext.getJobDetail().getJobDataMap();
36         Object JavaDoc tempJob = jobDataMap.get(QuartzConnector.PROPERTY_JOB_OBJECT);
37         if (tempJob == null)
38         {
39             tempJob = jobDataMap.get(QuartzConnector.PROPERTY_JOB_REF);
40             if (tempJob == null)
41             {
42                 throw new JobExecutionException(new Message("quartz", 2).getMessage());
43             }
44             else
45             {
46                 try
47                 {
48                     tempJob = MuleManager.getInstance().getContainerContext().getComponent(tempJob);
49                 }
50                 catch (ObjectNotFoundException e)
51                 {
52                     throw new JobExecutionException(e);
53                 }
54                 if (!(tempJob instanceof Job))
55                 {
56                     throw new JobExecutionException(new Message("quartz", 3).getMessage());
57                 }
58             }
59         }
60         else if (!(tempJob instanceof Job))
61         {
62             throw new JobExecutionException(new Message("quartz", 3).toString());
63         }
64         ((Job)tempJob).execute(jobExecutionContext);
65     }
66 }
67
Popular Tags