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.NoTypeConversionAvailableException;
021 import org.apache.camel.Processor;
022 import org.apache.camel.util.CamelContextHelper;
023
024 /**
025 * A constant (singleton) bean implementation of {@link BeanHolder}
026 *
027 * @version $Revision: 698831 $
028 */
029 public class ConstantBeanHolder implements BeanHolder {
030 private final Object bean;
031 private Processor processor;
032 private BeanInfo beanInfo;
033
034 public ConstantBeanHolder(Object bean, BeanInfo beanInfo) {
035 this.bean = bean;
036 this.beanInfo = beanInfo;
037 try {
038 this.processor = CamelContextHelper.convertTo(beanInfo.getCamelContext(), Processor.class, bean);
039 } catch (NoTypeConversionAvailableException ex) {
040 this.processor = null;
041 }
042 }
043
044 public ConstantBeanHolder(Object bean, CamelContext context) {
045 this(bean, new BeanInfo(context, bean.getClass()));
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 return bean.toString();
054 }
055
056 public Object getBean() {
057 return bean;
058 }
059
060 public Processor getProcessor() {
061 return processor;
062 }
063
064 public BeanInfo getBeanInfo() {
065 return beanInfo;
066 }
067 }