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;
018    
019    import java.util.HashMap;
020    import java.util.Map;
021    
022    import org.apache.camel.CamelContext;
023    import org.apache.camel.Endpoint;
024    import org.apache.camel.component.cxf.spring.CxfEndpointBean;
025    import org.apache.camel.impl.HeaderFilterStrategyComponent;
026    import org.apache.camel.util.CamelContextHelper;
027    
028    /**
029     * Defines the <a href="http://camel.apache.org/cxf.html">CXF Component</a> 
030     * 
031     * @version $Revision: 16270 $
032     */
033    public class CxfComponent extends HeaderFilterStrategyComponent {
034            
035        public CxfComponent() {
036        }
037    
038        public CxfComponent(CamelContext context) {
039            super(context);
040        }
041        
042        /**
043         * Create a {@link CxfEndpoint} which, can be a Spring bean endpoint having 
044         * URI format cxf:bean:<i>beanId</i> or transport address endpoint having URI format
045         * cxf://<i>transportAddress</i>. 
046         */
047        @Override
048        protected Endpoint createEndpoint(String uri, String remaining, 
049                Map<String, Object> parameters) throws Exception {
050            
051            CxfEndpoint result = null;
052            
053            if (remaining.startsWith(CxfConstants.SPRING_CONTEXT_ENDPOINT)) {
054                // Get the bean from the Spring context
055                String beanId = remaining.substring(CxfConstants.SPRING_CONTEXT_ENDPOINT.length());
056                if (beanId.startsWith("//")) {
057                    beanId = beanId.substring(2);
058                }
059    
060                CxfEndpointBean bean = CamelContextHelper.mandatoryLookup(getCamelContext(), beanId, 
061                        CxfEndpointBean.class);
062    
063                result = new CxfSpringEndpoint(this, bean);
064               
065                // Apply Spring bean properties (including # notation referenced bean).  Note that the
066                // Spring bean properties values can be overridden by property defined in URI query.
067                // The super class (DefaultComponent) will invoke "setProperties" after this method 
068                // with to apply properties defined by URI query. 
069                if (bean.getProperties() != null) {
070                    Map<String, Object> copy = new HashMap<String, Object>();
071                    copy.putAll(bean.getProperties());     
072                    setProperties(result, copy);      
073                }
074                
075            } else {
076                // endpoint URI does not specify a bean
077                result = new CxfEndpoint(remaining, this);
078            }
079            
080            setEndpointHeaderFilterStrategy(result);
081            return result;
082        }
083            
084    }