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.servicemix.cxfse;
018    
019    import java.util.List;
020    
021    import org.apache.cxf.Bus;
022    import org.apache.cxf.BusFactory;
023    import org.apache.cxf.bus.spring.SpringBusFactory;
024    import org.apache.servicemix.common.BaseServiceUnitManager;
025    import org.apache.servicemix.common.DefaultComponent;
026    import org.apache.servicemix.common.Deployer;
027    
028    /**
029     * 
030     * @author gnodet
031    * @org.apache.xbean.XBean element="component"  description="a component for hosting JAX-WS pojos. It is based on the CXF runtime."
032     */
033    public class CxfSeComponent extends DefaultComponent {
034    
035        public static final String JBI_TRANSPORT_ID = "http://cxf.apache.org/transports/jbi";
036        
037        private CxfSeEndpoint[] endpoints;
038        private Bus bus;
039        
040        private CxfSeConfiguration configuration = new CxfSeConfiguration();
041        
042        public CxfSeComponent() {
043            
044        }
045        
046        /**
047         * @return the endpoints
048         */
049        public CxfSeEndpoint[] getEndpoints() {
050            return endpoints;
051        }
052    
053        /**
054         * @param endpoints the endpoints to set
055         * @org.apache.xbean.Property description="the endpoints hosted by a component"
056         */
057        public void setEndpoints(CxfSeEndpoint[] endpoints) {
058            this.endpoints = endpoints;
059        }
060    
061        @Override
062        protected List getConfiguredEndpoints() {
063            return asList(endpoints);
064        }
065    
066        @Override
067        protected Class[] getEndpointClasses() {
068            return new Class[] {CxfSeEndpoint.class };
069        }
070        
071        /* (non-Javadoc)
072         * @see org.servicemix.common.BaseComponent#createServiceUnitManager()
073         */
074        @Override
075        public BaseServiceUnitManager createServiceUnitManager() {
076            Deployer[] deployers = new Deployer[] {new CxfSeXBeanDeployer(this) };
077            return new BaseServiceUnitManager(this, deployers);
078        }
079    
080        
081        @Override
082        protected void doInit() throws Exception {
083            //Load configuration
084            configuration.setRootDir(context.getWorkspaceRoot());
085            configuration.setComponentName(context.getComponentName());
086            configuration.load();
087            if (configuration.getBusCfg() != null && configuration.getBusCfg().length() > 0) {
088                SpringBusFactory bf = new SpringBusFactory();
089                bus = bf.createBus(configuration.getBusCfg());
090            } else {
091                bus = BusFactory.getDefaultBus();
092            }
093            super.doInit();
094        }
095        
096        @Override
097        protected void doShutDown() throws Exception {
098            // Bus should no longer be the thread default since the component's threads will end now
099            if (bus != null) {
100                BusFactory.setThreadDefaultBus(null);
101            }
102            super.doShutDown();
103        }
104        
105        public Bus getBus() {
106            return bus;
107        }
108    
109    }