Coverage Report - org.mule.module.scripting.component.GroovyRefreshableBeanBuilder
 
Classes in this File Line Coverage Branch Coverage Complexity
GroovyRefreshableBeanBuilder
0%
0/18
0%
0/6
2.167
 
 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.module.scripting.component;
 8  
 
 9  
 import org.mule.api.DefaultMuleException;
 10  
 import org.mule.api.MuleEventContext;
 11  
 import org.mule.api.lifecycle.Callable;
 12  
 import org.mule.config.i18n.CoreMessages;
 13  
 import org.mule.util.StringUtils;
 14  
 
 15  
 import groovy.lang.GroovyObject;
 16  
 import groovy.lang.MetaMethod;
 17  
 
 18  
 public class GroovyRefreshableBeanBuilder implements Callable
 19  
 {
 20  
     private volatile Object refreshableBean;
 21  
     private String methodName;
 22  
     private static final String ON_CALL = "onCall";
 23  0
     private static final Class[] MULE_EVENT_CONTEXT = new Class[]{MuleEventContext.class};
 24  
 
 25  
     public GroovyRefreshableBeanBuilder()
 26  
     {
 27  0
         super();
 28  0
     }
 29  
 
 30  
     public Object onCall(MuleEventContext eventContext) throws Exception
 31  
     {
 32  0
         if (refreshableBean instanceof GroovyObject)
 33  
         {
 34  0
             GroovyObject script = (GroovyObject)refreshableBean;
 35  0
             MetaMethod onCall = script.getMetaClass().pickMethod("onCall", MULE_EVENT_CONTEXT);
 36  
 
 37  0
             if (onCall != null)
 38  
             {
 39  0
                 return script.invokeMethod(ON_CALL, eventContext);
 40  
             }
 41  
             else
 42  
             {
 43  0
                 if (StringUtils.isEmpty(methodName))
 44  
                 {
 45  0
                     throw new DefaultMuleException(CoreMessages.propertiesNotSet("methodName"));
 46  
                 }
 47  
                 
 48  0
                 return script.invokeMethod(methodName, eventContext.getMessage().getPayload());
 49  
             }
 50  
             
 51  
         }
 52  
         
 53  0
         throw new Exception(new DefaultMuleException("script engine not supported"));
 54  
     }
 55  
 
 56  
     public Object getRefreshableBean()
 57  
     {
 58  0
         return refreshableBean;
 59  
     }
 60  
 
 61  
     public void setRefreshableBean(Object refreshableBean)
 62  
     {
 63  0
         this.refreshableBean = refreshableBean;
 64  0
     }
 65  
     
 66  
     public String getMethodName()
 67  
     {
 68  0
         return methodName;
 69  
     }
 70  
 
 71  
     public void setMethodName(String methodName)
 72  
     {
 73  0
         this.methodName = methodName;
 74  0
     }
 75  
 }
 76  
 
 77