001 /* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 package org.apache.camel.spring.util; 018 019 import org.aopalliance.intercept.MethodInvocation; 020 import org.apache.camel.Exchange; 021 import org.apache.camel.Expression; 022 023 import java.lang.reflect.AccessibleObject; 024 import java.lang.reflect.InvocationTargetException; 025 import java.lang.reflect.Method; 026 027 /** 028 * @version $Revision: $ 029 */ 030 public class MethodInfo { 031 private Class type; 032 private Method method; 033 private Expression parametersExpression; 034 035 public MethodInfo(Class type, Method method, Expression parametersExpression) { 036 this.type = type; 037 this.method = method; 038 this.parametersExpression = parametersExpression; 039 } 040 041 public MethodInvocation createMethodInvocation(final Object pojo, final Exchange messageExchange) { 042 final Object[] arguments = (Object[]) parametersExpression.evaluate(messageExchange); 043 return new MethodInvocation() { 044 public Method getMethod() { 045 return method; 046 } 047 048 public Object[] getArguments() { 049 return arguments; 050 } 051 052 public Object proceed() throws Throwable { 053 return invoke(method, pojo, arguments, messageExchange); 054 } 055 056 public Object getThis() { 057 return pojo; 058 } 059 060 public AccessibleObject getStaticPart() { 061 return method; 062 } 063 }; 064 } 065 066 public Class getType() { 067 return type; 068 } 069 070 public Method getMethod() { 071 return method; 072 } 073 074 public Expression getParametersExpression() { 075 return parametersExpression; 076 } 077 078 protected Object invoke(Method mth, Object pojo, Object[] arguments, Exchange exchange) throws IllegalAccessException, InvocationTargetException { 079 return mth.invoke(pojo, arguments); 080 } 081 }