Coverage Report - org.mule.transport.quartz.jobs.CustomJobFromMessageConfig
 
Classes in this File Line Coverage Branch Coverage Complexity
CustomJobFromMessageConfig
63%
19/30
50%
6/12
2.222
 
 1  
 /*
 2  
  * $Id: CustomJobFromMessageConfig.java 11733 2008-05-13 08:08:45Z dirk.olmes $
 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  
 package org.mule.transport.quartz.jobs;
 11  
 
 12  
 import org.mule.api.MuleMessage;
 13  
 import org.mule.config.i18n.CoreMessages;
 14  
 import org.mule.transport.quartz.config.AbstractJobConfig;
 15  
 import org.mule.transport.quartz.config.JobConfig;
 16  
 import org.mule.util.ClassUtils;
 17  
 import org.mule.util.expression.ExpressionEvaluatorManager;
 18  
 
 19  
 import java.lang.reflect.InvocationTargetException;
 20  
 
 21  
 import org.quartz.Job;
 22  
 
 23  
 /**
 24  
  * This configuration simply holds a reference to a user defined job to execute.
 25  
  */
 26  170
 public class CustomJobFromMessageConfig extends AbstractJobConfig
 27  
 {
 28  
     private String expression;
 29  
     private String evaluator;
 30  
     private String customEvaluator;
 31  
 
 32  
     public Job getJob(MuleMessage message) throws ClassNotFoundException, IllegalAccessException, NoSuchMethodException, InvocationTargetException, InstantiationException
 33  
     {
 34  4
         if (evaluator.equals("custom"))
 35  
         {
 36  0
             evaluator = customEvaluator;
 37  
         }
 38  
 
 39  4
         Object result = ExpressionEvaluatorManager.evaluate(expression, evaluator, message, true);
 40  
         Class clazz;
 41  4
         if (result instanceof Job)
 42  
         {
 43  0
             return (Job) result;
 44  
         }
 45  4
         else if (result instanceof JobConfig)
 46  
         {
 47  4
             clazz = ((JobConfig)result).getJobClass();
 48  
         }
 49  
         else
 50  
         {
 51  0
             throw new IllegalStateException(CoreMessages.propertyIsNotSupportedType(evaluator + ":" + expression,
 52  
                     new Class[]{Job.class, JobConfig.class}, result.getClass()).getMessage());
 53  
         }
 54  
 
 55  4
         return (Job) ClassUtils.instanciateClass(clazz, ClassUtils.NO_ARGS);
 56  
     }
 57  
 
 58  
     public JobConfig getJobConfig(MuleMessage message) throws ClassNotFoundException, IllegalAccessException, NoSuchMethodException, InvocationTargetException, InstantiationException
 59  
     {
 60  4
         if (evaluator.equals("custom"))
 61  
         {
 62  0
             evaluator = customEvaluator;
 63  
         }
 64  
 
 65  4
         Object result = ExpressionEvaluatorManager.evaluate(expression, evaluator, message, true);
 66  4
         if (result instanceof Job)
 67  
         {
 68  0
             CustomJobConfig customJob = new CustomJobConfig();
 69  0
             customJob.setJob((Job) result);
 70  0
             return customJob;
 71  
         }
 72  4
         else if (result instanceof JobConfig)
 73  
         {
 74  4
             return (JobConfig)result;
 75  
         }
 76  
         else
 77  
         {
 78  0
             throw new IllegalStateException(CoreMessages.propertyIsNotSupportedType(evaluator + ":" + expression,
 79  
                     new Class[]{Job.class, JobConfig.class, Class.class, String.class}, result.getClass()).getMessage());
 80  
         }
 81  
     }
 82  
 
 83  
     public String getCustomEvaluator()
 84  
     {
 85  2
         return customEvaluator;
 86  
     }
 87  
 
 88  
     public void setCustomEvaluator(String customEvaluator)
 89  
     {
 90  0
         this.customEvaluator = customEvaluator;
 91  0
     }
 92  
 
 93  
     public String getEvaluator()
 94  
     {
 95  2
         return evaluator;
 96  
     }
 97  
 
 98  
     public void setEvaluator(String evaluator)
 99  
     {
 100  170
         this.evaluator = evaluator;
 101  170
     }
 102  
 
 103  
     public String getExpression()
 104  
     {
 105  2
         return expression;
 106  
     }
 107  
 
 108  
     public void setExpression(String expression)
 109  
     {
 110  170
         this.expression = expression;
 111  170
     }
 112  
 
 113  
     public Class getJobClass()
 114  
     {
 115  0
         return CustomJob.class;
 116  
     }
 117  
 
 118  
 }