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