Clover coverage report - Drools - 2.0-rc2
Coverage timestamp: Wed May 11 2005 07:12:26 BST
file stats: LOC: 99   Methods: 9
NCLOC: 75   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
RuleReflectMethod.java 100% 88.5% 77.8% 86.5%
coverage coverage
 1    package org.drools.semantics.annotation.model;
 2   
 3    import java.io.Externalizable;
 4    import java.io.IOException;
 5    import java.io.ObjectInput;
 6    import java.io.ObjectOutput;
 7    import java.lang.reflect.Method;
 8   
 9    import org.drools.rule.Rule;
 10    import org.drools.spi.Tuple;
 11   
 12    class RuleReflectMethod implements Externalizable
 13    {
 14    private Rule rule;
 15    private Object pojo;
 16    private Method method;
 17    private ParameterValue[] parameterValues;
 18   
 19    /**
 20    * Not intended to be called. Required only for Externalizable.
 21    */
 22  1 public RuleReflectMethod() {}
 23   
 24  29 public RuleReflectMethod( Rule rule, Object pojo, Method method,
 25    ParameterValue[] parameterValues )
 26    {
 27  29 this.rule = rule;
 28  29 this.pojo = pojo;
 29  29 this.method = method;
 30  29 this.parameterValues = parameterValues;
 31    }
 32   
 33  12 public ParameterValue[] getParameterValues( )
 34    {
 35  12 return parameterValues;
 36    }
 37   
 38  8 public Object invokeMethod( Tuple tuple ) throws Exception
 39    {
 40  8 method.setAccessible( true );
 41  8 return method.invoke( pojo, getMethodArguments( tuple ) );
 42    }
 43   
 44  8 private Object[] getMethodArguments( Tuple tuple )
 45    {
 46  8 Object[] args = new Object[parameterValues.length];
 47  8 for (int i = 0; i < parameterValues.length; i++)
 48    {
 49  12 args[i] = parameterValues[i].getValue( tuple );
 50    }
 51  8 return args;
 52    }
 53   
 54  1 public void writeExternal(ObjectOutput out) throws IOException
 55    {
 56  1 out.writeObject(rule);
 57  1 out.writeObject(pojo);
 58  1 out.writeObject(method.getName());
 59  1 out.writeObject(method.getParameterTypes());
 60  1 out.writeObject(parameterValues);
 61    }
 62   
 63  1 public void readExternal(ObjectInput in) throws IOException,
 64    ClassNotFoundException
 65    {
 66  1 rule = (Rule) in.readObject();
 67  1 pojo = in.readObject();
 68   
 69  1 String methodName = (String) in.readObject();
 70  1 Class[] parameterTypes = (Class[]) in.readObject();
 71  1 try
 72    {
 73  1 method = pojo.getClass().getMethod(methodName, parameterTypes);
 74    }
 75    catch ( Exception e )
 76    {
 77  0 throw new RuntimeException(e);
 78    }
 79   
 80  1 parameterValues = (ParameterValue[]) in.readObject();
 81    }
 82   
 83  0 public String toString() {
 84  0 return pojo.getClass().getSimpleName()
 85    + "." + method.getName()
 86    + "(" + toStringParamterTypes() + ")";
 87    }
 88   
 89  0 private String toStringParamterTypes() {
 90  0 return "...";
 91    // StringBuilder value = new StringBuilder();
 92    // String prefix = "";
 93    // for (Class clazz : method.getParameterTypes()) {
 94    // value.append(prefix).append(clazz.getSimpleName());
 95    // prefix = ",";
 96    // }
 97    // return value.toString();
 98    }
 99    }