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.cxf.cxfbean;
018    
019    import java.util.HashMap;
020    import java.util.Map;
021    
022    import org.apache.camel.Endpoint;       
023    import org.apache.camel.impl.HeaderFilterStrategyComponent;
024    
025    /**
026     * CXF Bean component creates {@link CxfBeanEndpoint} which represents a
027     * bean.  <b>Currently, only JAXRS annotated beans are supported.  In the
028     * future, JAXwS annotated beans and POJO can be supported</b>.
029     * 
030     * @version $Revision: 15191 $
031     */
032    public class CxfBeanComponent extends HeaderFilterStrategyComponent {
033    
034        private Map<String, CxfBeanEndpoint> endpoints = new HashMap<String, CxfBeanEndpoint>();
035            
036        @SuppressWarnings("unchecked")
037        @Override
038        protected Endpoint createEndpoint(String uri, String remaining,
039                Map parameters) throws Exception {
040            CxfBeanEndpoint answer = new CxfBeanEndpoint(remaining, this);
041            setEndpointHeaderFilterStrategy(answer);
042            setProperties(answer, parameters);
043    
044            // add to the endpoints map before calling the endpoint's init() method to 
045            // make sure the the CxfBeanDestination activate() method can find the endpoint 
046            // from the map.
047            endpoints.put(answer.createEndpointUri(), answer);
048            answer.init();
049    
050            return answer;
051        }
052    
053        @Override
054        protected boolean useIntrospectionOnEndpoint() {
055            // we invoke setProperties ourselves so the bus is set for CxfBeanEndpoint.init()
056            return false;
057        }
058        
059        @Override
060        protected void doStart() throws Exception {
061            super.doStart();
062            for (CxfBeanEndpoint endpoint : endpoints.values()) {
063                endpoint.start();
064            }
065        }
066    
067        @Override
068        protected void doStop() throws Exception {
069            for (CxfBeanEndpoint endpoint : endpoints.values()) {
070                endpoint.stop();
071            }
072            super.doStop();
073        }
074        
075        public CxfBeanEndpoint getEndpoint(String endpointUri) {
076            return endpoints.get(endpointUri);
077        }
078       
079    }