Coverage Report - org.boretti.drools.integration.drools5.implementation.DroolsCallable
 
Classes in this File Line Coverage Branch Coverage Complexity
DroolsCallable
81 %
13/16
100 %
2/2
3
 
 1  
 /*
 2  
     Drools5 Integration Helper
 3  
     Copyright (C) 2009  Mathieu Boretti mathieu.boretti@gmail.com
 4  
 
 5  
     This program is free software: you can redistribute it and/or modify
 6  
     it under the terms of the GNU General Public License as published by
 7  
     the Free Software Foundation, either version 3 of the License, or
 8  
     (at your option) any later version.
 9  
 
 10  
     This program is distributed in the hope that it will be useful,
 11  
     but WITHOUT ANY WARRANTY; without even the implied warranty of
 12  
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 13  
     GNU General Public License for more details.
 14  
 
 15  
     You should have received a copy of the GNU General Public License
 16  
     along with this program.  If not, see <http://www.gnu.org/licenses/>.
 17  
 
 18  
  */
 19  
 package org.boretti.drools.integration.drools5.implementation;
 20  
 
 21  
 import java.lang.reflect.Method;
 22  
 import java.lang.reflect.ParameterizedType;
 23  
 import java.util.List;
 24  
 import java.util.concurrent.Callable;
 25  
 
 26  
 import org.apache.log4j.Logger;
 27  
 import org.boretti.drools.integration.drools5.DroolsSessionType;
 28  
 
 29  
 /**
 30  
  * @author mbo
 31  
  *
 32  
  */
 33  
 class DroolsCallable<T> implements Callable<Object> {
 34  
         
 35  4
         private final Logger logger = Logger.getLogger(DroolsCallable.class);
 36  
 
 37  
         private DroolsProxy<T> dp;
 38  
         
 39  
         private Object proxy;
 40  
         
 41  
         private Method method;
 42  
                         
 43  
         private DroolsSessionType session;
 44  
         
 45  
         private Object[] args;
 46  
         
 47  
         private List<Object> fact;
 48  
         
 49  
         private Class<?> returnType;
 50  
         
 51  4
         public DroolsCallable(DroolsProxy<T> dp,Object proxy,Class<?> returnType,Method method,DroolsSessionType session,Object[] args,List<Object> fact) {
 52  4
                 this.dp=dp;
 53  4
                 this.proxy=proxy;
 54  4
                 this.method=method;
 55  4
                 this.session=session;
 56  4
                 this.args=args;
 57  4
                 this.fact=fact;
 58  4
                 this.returnType=returnType;
 59  4
         }
 60  
         
 61  
         @Override
 62  
         public Object call() throws Exception {
 63  
                 try {
 64  4
                         Class<?> rt = returnType;
 65  4
                         if (rt==null) rt=(Class<?>)((ParameterizedType)method.getGenericReturnType()).getActualTypeArguments()[0];
 66  4
                         return dp.invokeInternal(proxy,method,rt,session,args,fact);
 67  0
                 } catch (Throwable e) {
 68  0
                         logger.error(""+e.getMessage(),e);
 69  0
                         throw new Exception(""+e.getMessage(),e);
 70  
                 }
 71  
         }
 72  
 
 73  
 }