Coverage Report - org.apache.camel.spring.util.MethodInfo
 
Classes in this File Line Coverage Branch Coverage Complexity
MethodInfo
61% 
N/A 
1
 
 1  
 /*
 2  
  * Licensed to the Apache Software Foundation (ASF) under one or more
 3  
  * contributor license agreements.  See the NOTICE file distributed with
 4  
  * this work for additional information regarding copyright ownership.
 5  
  * The ASF licenses this file to You under the Apache License, Version 2.0
 6  
  * (the "License"); you may not use this file except in compliance with
 7  
  * the License.  You may obtain a copy of the License at
 8  
  *
 9  
  *      http://www.apache.org/licenses/LICENSE-2.0
 10  
  *
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 16  
  */
 17  
 package org.apache.camel.spring.util;
 18  
 
 19  
 import org.aopalliance.intercept.MethodInvocation;
 20  
 import org.apache.camel.Exchange;
 21  
 import org.apache.camel.Expression;
 22  
 
 23  
 import java.lang.reflect.AccessibleObject;
 24  
 import java.lang.reflect.InvocationTargetException;
 25  
 import java.lang.reflect.Method;
 26  
 
 27  
 /**
 28  
  * @version $Revision: $
 29  
  */
 30  1
 public class MethodInfo {
 31  
     private Class type;
 32  
     private Method method;
 33  
     private Expression parametersExpression;
 34  
 
 35  1
     public MethodInfo(Class type, Method method, Expression parametersExpression) {
 36  1
         this.type = type;
 37  1
         this.method = method;
 38  1
         this.parametersExpression = parametersExpression;
 39  1
     }
 40  
 
 41  
     public MethodInvocation createMethodInvocation(final Object pojo, final Exchange messageExchange) {
 42  1
         final Object[] arguments = (Object[]) parametersExpression.evaluate(messageExchange);
 43  1
         return new MethodInvocation() {
 44  
             public Method getMethod() {
 45  0
                 return method;
 46  
             }
 47  
 
 48  
             public Object[] getArguments() {
 49  0
                 return arguments;
 50  
             }
 51  
 
 52  
             public Object proceed() throws Throwable {
 53  1
                 return invoke(method, pojo, arguments, messageExchange);
 54  
             }
 55  
 
 56  
             public Object getThis() {
 57  0
                 return pojo;
 58  
             }
 59  
 
 60  1
             public AccessibleObject getStaticPart() {
 61  0
                 return method;
 62  
             }
 63  
         };
 64  
     }
 65  
 
 66  
     public Class getType() {
 67  0
         return type;
 68  
     }
 69  
 
 70  
     public Method getMethod() {
 71  0
         return method;
 72  
     }
 73  
 
 74  
     public Expression getParametersExpression() {
 75  0
         return parametersExpression;
 76  
     }
 77  
 
 78  
     protected Object invoke(Method mth, Object pojo, Object[] arguments, Exchange exchange) throws IllegalAccessException, InvocationTargetException {
 79  1
         return mth.invoke(pojo, arguments);
 80  
     }
 81  
 }