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 java.util.Map; 020 import java.util.concurrent.ConcurrentHashMap; 021 022 import org.aopalliance.intercept.MethodInvocation; 023 import org.apache.camel.Expression; 024 import org.apache.camel.Exchange; 025 import org.apache.camel.Endpoint; 026 import org.apache.camel.RuntimeCamelException; 027 import org.apache.camel.Message; 028 import org.apache.camel.builder.ExpressionBuilder; 029 030 /** 031 * Represents the strategy used to figure out how to map a message exchange to a POJO method invocation 032 * 033 * @version $Revision:$ 034 */ 035 public class DefaultMethodInvocationStrategy implements MethodInvocationStrategy { 036 037 private Map<Class, Expression> parameterTypeToExpressionMap = new ConcurrentHashMap<Class, Expression>(); 038 039 public DefaultMethodInvocationStrategy() { 040 } 041 042 public synchronized Expression getDefaultParameterTypeExpression(Class parameterType) { 043 return parameterTypeToExpressionMap.get(parameterType); 044 } 045 046 /** 047 * Adds a default parameter type mapping to an expression 048 */ 049 public synchronized void addParameterMapping(Class parameterType, Expression expression) { 050 parameterTypeToExpressionMap.put(parameterType, expression); 051 } 052 053 054 /** 055 * Creates an invocation on the given POJO using annotations to decide which method to invoke 056 * and to figure out which parameters to use 057 */ 058 /* 059 public MethodInvocation createInvocation(Object pojo, 060 BeanInfo beanInfo, 061 Exchange messageExchange, 062 Endpoint pojoEndpoint) throws RuntimeCamelException { 063 return beanInfo.createInvocation(pojo, messageExchange); 064 } 065 */ 066 067 068 public void loadDefaultRegistry() { 069 addParameterMapping(Exchange.class, ExpressionBuilder.exchangeExpression()); 070 addParameterMapping(Message.class, ExpressionBuilder.inMessageExpression()); 071 } 072 073 074 }