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.component.bean; 018 019 import org.apache.camel.CamelContext; 020 import org.apache.camel.Processor; 021 import org.apache.camel.util.CamelContextHelper; 022 import org.apache.camel.util.ObjectHelper; 023 024 /** 025 * A constant (singleton) bean implementation of {@link BeanHolder} 026 * 027 * @version 028 */ 029 public class ConstantBeanHolder implements BeanHolder { 030 private final Object bean; 031 private final BeanInfo beanInfo; 032 private final Processor processor; 033 034 public ConstantBeanHolder(Object bean, BeanInfo beanInfo) { 035 ObjectHelper.notNull(bean, "bean"); 036 ObjectHelper.notNull(beanInfo, "beanInfo"); 037 038 this.bean = bean; 039 this.beanInfo = beanInfo; 040 this.processor = CamelContextHelper.convertTo(beanInfo.getCamelContext(), Processor.class, bean); 041 } 042 043 public ConstantBeanHolder(Object bean, CamelContext context) { 044 this(bean, new BeanInfo(context, bean.getClass())); 045 } 046 047 public ConstantBeanHolder(Object bean, CamelContext context, ParameterMappingStrategy parameterMappingStrategy) { 048 this(bean, new BeanInfo(context, bean.getClass(), parameterMappingStrategy)); 049 } 050 051 @Override 052 public String toString() { 053 // avoid invoke toString on bean as it may be a remote proxy 054 return ObjectHelper.className(bean) + "(" + ObjectHelper.getIdentityHashCode(bean) + ")"; 055 } 056 057 public Object getBean() { 058 return bean; 059 } 060 061 public Processor getProcessor() { 062 return processor; 063 } 064 065 public BeanInfo getBeanInfo() { 066 return beanInfo; 067 } 068 069 public BeanInfo getBeanInfo(Object bean) { 070 return null; 071 } 072 }