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