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.spring;
018    
019    import org.apache.cxf.Bus;
020    import org.apache.cxf.bus.spring.SpringBusFactory;
021    import org.springframework.beans.BeansException;
022    import org.springframework.beans.factory.SmartFactoryBean;
023    import org.springframework.context.ApplicationContext;
024    import org.springframework.context.ApplicationContextAware;
025    
026    /** This factoryBean which can help user to choice CXF components that he wants bus to load 
027     *  without needing to import bunch of CXF packages in OSGi bundle, as the SpringBusFactory 
028     *  will try to load the bus extensions with the CXF bundle classloader.
029     *  You can set the CXF extensions files with ; as the separator to create a bus.
030     * */
031    
032    public class SpringBusFactoryBean implements SmartFactoryBean {
033        private String[] cfgFiles;
034        private boolean includeDefaultBus;
035        private SpringBusFactory bf;
036    
037        public Object getObject() throws Exception {
038            bf = new SpringBusFactory();
039            if (cfgFiles != null) {
040                return bf.createBus(cfgFiles, includeDefaultBus);
041            } else {
042                return bf.createBus();
043            }
044        }
045    
046        public Class getObjectType() {
047            return Bus.class;
048        }
049        
050        public void setCfgFiles(String cfgFiles) {
051            this.cfgFiles = cfgFiles.split(";");
052        }
053        
054        public void setIncludeDefaultBus(boolean includeDefaultBus) {
055            this.includeDefaultBus = includeDefaultBus;
056        }
057        
058        public boolean isSingleton() {
059            return true;
060        }
061       
062        public boolean isEagerInit() {
063            return true;
064        }
065    
066        public boolean isPrototype() {
067            return false;
068        }
069    
070    }