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.Component;
020 import org.apache.camel.ExchangePattern;
021 import org.apache.camel.Processor;
022 import org.apache.camel.impl.ProcessorEndpoint;
023
024 /**
025 * Endpoint for the bean component.
026 *
027 * @version $Revision: 662301 $
028 */
029 public class BeanEndpoint extends ProcessorEndpoint {
030 private boolean cache;
031 private String beanName;
032 private String method;
033 private BeanHolder beanHolder;
034
035 public BeanEndpoint() {
036 init();
037 }
038
039 public BeanEndpoint(String endpointUri) {
040 super(endpointUri);
041 init();
042 }
043
044 public BeanEndpoint(String endpointUri, BeanProcessor processor) {
045 super(endpointUri, processor);
046 init();
047 }
048
049 public BeanEndpoint(String endpointUri, Component component, BeanProcessor processor) {
050 super(endpointUri, component, processor);
051 init();
052 }
053
054 public BeanEndpoint(String endpointUri, Component component) {
055 super(endpointUri, component);
056 init();
057 }
058
059 // Properties
060 //-------------------------------------------------------------------------
061
062 public String getBeanName() {
063 return beanName;
064 }
065
066 public void setBeanName(String beanName) {
067 this.beanName = beanName;
068 }
069
070 public boolean isCache() {
071 return cache;
072 }
073
074 public void setCache(boolean cache) {
075 this.cache = cache;
076 }
077
078 public String getMethod() {
079 return method;
080 }
081
082 public void setMethod(String method) {
083 this.method = method;
084 }
085
086 public BeanHolder getBeanHolder() {
087 return beanHolder;
088 }
089
090 public void setBeanHolder(BeanHolder beanHolder) {
091 this.beanHolder = beanHolder;
092 }
093
094 // Implementation methods
095 //-------------------------------------------------------------------------
096
097 @Override
098 protected String createEndpointUri() {
099 return "bean:" + getBeanName() + (method != null ? "?method=" + method : "");
100 }
101
102 private void init() {
103 setExchangePattern(ExchangePattern.InOut);
104 }
105
106 @Override
107 protected Processor createProcessor() throws Exception {
108 BeanHolder holder = getBeanHolder();
109 if (holder == null) {
110 RegistryBean registryBean = new RegistryBean(getCamelContext(), beanName);
111 if (cache) {
112 holder = registryBean.createCacheHolder();
113 } else {
114 holder = registryBean;
115 }
116 }
117 BeanProcessor processor = new BeanProcessor(holder);
118 if (method != null) {
119 processor.setMethod(method);
120 }
121 return processor;
122 }
123 }