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 */ 017package org.apache.camel.component.bean; 018 019import java.util.Map; 020import java.util.concurrent.ConcurrentHashMap; 021 022import org.apache.camel.CamelContext; 023import org.apache.camel.Exchange; 024import org.apache.camel.Expression; 025import org.apache.camel.Message; 026import org.apache.camel.TypeConverter; 027import org.apache.camel.builder.ExpressionBuilder; 028import org.apache.camel.spi.Registry; 029 030/** 031 * Represents the strategy used to figure out how to map a message exchange to a POJO method invocation 032 * 033 * @version 034 */ 035public class DefaultParameterMappingStrategy implements ParameterMappingStrategy { 036 private final Map<Class<?>, Expression> parameterTypeToExpressionMap = new ConcurrentHashMap<Class<?>, Expression>(); 037 038 public DefaultParameterMappingStrategy() { 039 loadDefaultRegistry(); 040 } 041 042 public 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 void addParameterMapping(Class<?> parameterType, Expression expression) { 050 parameterTypeToExpressionMap.put(parameterType, expression); 051 } 052 053 public void loadDefaultRegistry() { 054 addParameterMapping(Exchange.class, ExpressionBuilder.exchangeExpression()); 055 addParameterMapping(Message.class, ExpressionBuilder.inMessageExpression()); 056 addParameterMapping(Exception.class, ExpressionBuilder.exchangeExceptionExpression()); 057 addParameterMapping(TypeConverter.class, ExpressionBuilder.typeConverterExpression()); 058 addParameterMapping(Registry.class, ExpressionBuilder.registryExpression()); 059 addParameterMapping(CamelContext.class, ExpressionBuilder.camelContextExpression()); 060 } 061}