KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * $Id: MuleReceiverJob.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.apache.commons.logging.Log;
14 import org.apache.commons.logging.LogFactory;
15 import org.mule.MuleManager;
16 import org.mule.impl.MuleMessage;
17 import org.mule.providers.AbstractMessageReceiver;
18 import org.mule.providers.NullPayload;
19 import org.mule.providers.quartz.QuartzConnector;
20 import org.mule.providers.quartz.QuartzMessageReceiver;
21 import org.mule.umo.manager.ObjectNotFoundException;
22 import org.quartz.Job;
23 import org.quartz.JobDataMap;
24 import org.quartz.JobExecutionContext;
25 import org.quartz.JobExecutionException;
26
27 /**
28  * Invokes a Quartz Message receiver with the payload attached to the Quartz job.
29  */

30 public class MuleReceiverJob implements Job
31 {
32
33     /**
34      * The logger used for this class
35      */

36     protected transient Log logger = LogFactory.getLog(getClass());
37
38     public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException
39     {
40         JobDataMap map = jobExecutionContext.getJobDetail().getJobDataMap();
41         AbstractMessageReceiver receiver = (AbstractMessageReceiver)map.get(QuartzMessageReceiver.QUARTZ_RECEIVER_PROPERTY);
42         Object JavaDoc payload = jobExecutionContext.getJobDetail().getJobDataMap().get(
43             QuartzConnector.PROPERTY_PAYLOAD);
44
45         try
46         {
47             if (payload == null)
48             {
49                 String JavaDoc ref = jobExecutionContext.getJobDetail().getJobDataMap().getString(
50                     QuartzConnector.PROPERTY_PAYLOAD_REFERENCE);
51                 // for backward compatibility check the old payload Class property
52
// too
53
if (ref == null)
54                 {
55                     ref = jobExecutionContext.getJobDetail().getJobDataMap().getString(
56                         QuartzConnector.PROPERTY_PAYLOAD_CLASS_NAME);
57                 }
58                 try
59                 {
60                     payload = MuleManager.getInstance().getContainerContext().getComponent(ref);
61                 }
62                 catch (ObjectNotFoundException e)
63                 {
64                     logger.warn("There is no payload attached to this quartz job. Sending Null payload");
65                     payload = new NullPayload();
66                 }
67             }
68             receiver.routeMessage(new MuleMessage(receiver.getConnector().getMessageAdapter(payload)));
69         }
70         catch (Exception JavaDoc e)
71         {
72             receiver.handleException(e);
73         }
74     }
75 }
76
Popular Tags