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  
  * $Id: GroovyRefreshableBeanBuilder.java 19191 2010-08-25 21:05:23Z tcarlson $
 3  
  * --------------------------------------------------------------------------------------
 4  
  * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.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.module.scripting.component;
 12  
 
 13  
 import org.mule.api.DefaultMuleException;
 14  
 import org.mule.api.MuleEventContext;
 15  
 import org.mule.api.lifecycle.Callable;
 16  
 import org.mule.config.i18n.CoreMessages;
 17  
 import org.mule.util.StringUtils;
 18  
 
 19  
 import groovy.lang.GroovyObject;
 20  
 import groovy.lang.MetaMethod;
 21  
 
 22  
 public class GroovyRefreshableBeanBuilder implements Callable
 23  
 {
 24  
     private volatile Object refreshableBean;
 25  
     private String methodName;
 26  
     private static final String ON_CALL = "onCall";
 27  0
     private static final Class[] MULE_EVENT_CONTEXT = new Class[]{MuleEventContext.class};
 28  
 
 29  
     public GroovyRefreshableBeanBuilder()
 30  
     {
 31  0
         super();
 32  0
     }
 33  
 
 34  
     public Object onCall(MuleEventContext eventContext) throws Exception
 35  
     {
 36  0
         if (refreshableBean instanceof GroovyObject)
 37  
         {
 38  0
             GroovyObject script = (GroovyObject)refreshableBean;
 39  0
             MetaMethod onCall = script.getMetaClass().pickMethod("onCall", MULE_EVENT_CONTEXT);
 40  
 
 41  0
             if (onCall != null)
 42  
             {
 43  0
                 return script.invokeMethod(ON_CALL, eventContext);
 44  
             }
 45  
             else
 46  
             {
 47  0
                 if (StringUtils.isEmpty(methodName))
 48  
                 {
 49  0
                     throw new DefaultMuleException(CoreMessages.propertiesNotSet("methodName"));
 50  
                 }
 51  
                 
 52  0
                 return script.invokeMethod(methodName, eventContext.getMessage().getPayload());
 53  
             }
 54  
             
 55  
         }
 56  
         
 57  0
         throw new Exception(new DefaultMuleException("script engine not supported"));
 58  
     }
 59  
 
 60  
     public Object getRefreshableBean()
 61  
     {
 62  0
         return refreshableBean;
 63  
     }
 64  
 
 65  
     public void setRefreshableBean(Object refreshableBean)
 66  
     {
 67  0
         this.refreshableBean = refreshableBean;
 68  0
     }
 69  
     
 70  
     public String getMethodName()
 71  
     {
 72  0
         return methodName;
 73  
     }
 74  
 
 75  
     public void setMethodName(String methodName)
 76  
     {
 77  0
         this.methodName = methodName;
 78  0
     }
 79  
 }
 80  
 
 81