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
023 /**
024 * A constant (singleton) bean implementation of {@link BeanHolder}
025 *
026 * @version $Revision: 755890 $
027 */
028 public class ConstantBeanHolder implements BeanHolder {
029 private final Object bean;
030 private final BeanInfo beanInfo;
031 private final Processor processor;
032
033 public ConstantBeanHolder(Object bean, BeanInfo beanInfo) {
034 this.bean = bean;
035 this.beanInfo = beanInfo;
036 this.processor = CamelContextHelper.convertTo(beanInfo.getCamelContext(), Processor.class, bean);
037 }
038
039 public ConstantBeanHolder(Object bean, CamelContext context) {
040 this(bean, new BeanInfo(context, bean.getClass()));
041 }
042 public ConstantBeanHolder(Object bean, CamelContext context, ParameterMappingStrategy parameterMappingStrategy) {
043 this(bean, new BeanInfo(context, bean.getClass(), parameterMappingStrategy));
044 }
045
046 @Override
047 public String toString() {
048 return bean.toString();
049 }
050
051 public Object getBean() {
052 return bean;
053 }
054
055 public Processor getProcessor() {
056 return processor;
057 }
058
059 public BeanInfo getBeanInfo() {
060 return beanInfo;
061 }
062 }