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