Coverage Report - org.mule.transport.quartz.jobs.CustomJob
 
Classes in this File Line Coverage Branch Coverage Complexity
CustomJob
0%
0/21
0%
0/10
7
 
 1  
 /*
 2  
  * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
 3  
  * The software in this package is published under the terms of the CPAL v1.0
 4  
  * license, a copy of which has been included with this distribution in the
 5  
  * LICENSE.txt file.
 6  
  */
 7  
 package org.mule.transport.quartz.jobs;
 8  
 
 9  
 import org.mule.api.MuleContext;
 10  
 import org.mule.api.config.MuleProperties;
 11  
 import org.mule.transport.quartz.QuartzConnector;
 12  
 import org.mule.transport.quartz.i18n.QuartzMessages;
 13  
 
 14  
 import org.quartz.Job;
 15  
 import org.quartz.JobDataMap;
 16  
 import org.quartz.JobExecutionContext;
 17  
 import org.quartz.JobExecutionException;
 18  
 import org.quartz.SchedulerContext;
 19  
 import org.quartz.SchedulerException;
 20  
 
 21  
 /**
 22  
  * Extracts the Job object to invoke from the context. The Job itself can be
 23  
  * scheduled by dispatching an event over a quartz endpoint. The job can either be
 24  
  * set as a property on the event (this property can be a container reference or the
 25  
  * actual job object) or the payload of the event can be the Job (in which case when
 26  
  * the job is fired it will have a NullPayload)
 27  
  * 
 28  
  * @see org.mule.transport.NullPayload
 29  
  */
 30  0
 public class CustomJob implements Job
 31  
 {
 32  
     public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException
 33  
     {
 34  0
         MuleContext muleContext = lookupMuleContext(jobExecutionContext);
 35  
         
 36  0
         JobDataMap jobDataMap = jobExecutionContext.getJobDetail().getJobDataMap();
 37  0
         Object tempJob = jobDataMap.get(QuartzConnector.PROPERTY_JOB_OBJECT);
 38  0
         if (tempJob == null)
 39  
         {
 40  0
             tempJob = jobDataMap.get(QuartzConnector.PROPERTY_JOB_REF);
 41  0
             if (tempJob == null)
 42  
             {
 43  0
                 throw new JobExecutionException(QuartzMessages.invalidPayloadType().getMessage());
 44  
             }
 45  
             else
 46  
             {
 47  0
                 tempJob = muleContext.getRegistry().lookupObject((String) tempJob);
 48  0
                 if (tempJob == null)
 49  
                 {
 50  0
                     throw new JobExecutionException("Job not found: " + tempJob);
 51  
                 }
 52  0
                 if (!(tempJob instanceof Job))
 53  
                 {
 54  0
                     throw new JobExecutionException(QuartzMessages.invalidJobObject().getMessage());
 55  
                 }
 56  
             }
 57  
         }
 58  0
         else if (!(tempJob instanceof Job))
 59  
         {
 60  0
             throw new JobExecutionException(QuartzMessages.invalidJobObject().toString());
 61  
         }
 62  0
         ((Job)tempJob).execute(jobExecutionContext);
 63  0
     }
 64  
 
 65  
     private MuleContext lookupMuleContext(JobExecutionContext jobExecutionContext) throws JobExecutionException
 66  
     {
 67  
         try
 68  
         {
 69  0
             SchedulerContext schedulerContext = jobExecutionContext.getScheduler().getContext();
 70  0
             return (MuleContext) schedulerContext.get(MuleProperties.MULE_CONTEXT_PROPERTY);
 71  
         }
 72  0
         catch (SchedulerException e)
 73  
         {
 74  0
             throw new JobExecutionException("Failed to retrieve Mulecontext from the Scheduler Context: " + e.getMessage(), e);
 75  
         }
 76  
     }
 77  
 }