Coverage Report - org.mule.transport.quartz.jobs.CustomJob
 
Classes in this File Line Coverage Branch Coverage Complexity
CustomJob
44%
7/16
20%
2/10
10
 
 1  
 /*
 2  
  * $Id: CustomJob.java 11613 2008-04-20 20:30:10Z rossmason $
 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 CPAL v1.0
 7  
  * license, a copy of which has been included with this distribution in the
 8  
  * LICENSE.txt file.
 9  
  */
 10  
 
 11  
 package org.mule.transport.quartz.jobs;
 12  
 
 13  
 import org.mule.RegistryContext;
 14  
 import org.mule.transport.quartz.QuartzConnector;
 15  
 import org.mule.transport.quartz.i18n.QuartzMessages;
 16  
 
 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.transport.NullPayload
 30  
  */
 31  4
 public class CustomJob implements Job
 32  
 {
 33  
     public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException
 34  
     {
 35  4
         JobDataMap jobDataMap = jobExecutionContext.getJobDetail().getJobDataMap();
 36  4
         Object tempJob = jobDataMap.get(QuartzConnector.PROPERTY_JOB_OBJECT);
 37  4
         if (tempJob == null)
 38  
         {
 39  0
             tempJob = jobDataMap.get(QuartzConnector.PROPERTY_JOB_REF);
 40  0
             if (tempJob == null)
 41  
             {
 42  0
                 throw new JobExecutionException(QuartzMessages.invalidPayloadType().getMessage());
 43  
             }
 44  
             else
 45  
             {
 46  0
                 tempJob = RegistryContext.getRegistry().lookupObject((String) tempJob);
 47  0
                 if(tempJob==null)
 48  
                 {
 49  0
                     throw new JobExecutionException("Job not found: " + tempJob);
 50  
                 }
 51  0
                 if (!(tempJob instanceof Job))
 52  
                 {
 53  0
                     throw new JobExecutionException(QuartzMessages.invalidJobObject().getMessage());
 54  
                 }
 55  
             }
 56  
         }
 57  4
         else if (!(tempJob instanceof Job))
 58  
         {
 59  0
             throw new JobExecutionException(QuartzMessages.invalidJobObject().toString());
 60  
         }
 61  4
         ((Job)tempJob).execute(jobExecutionContext);
 62  4
     }
 63  
 }