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.transport;
018    
019    import java.io.IOException;
020    import java.util.HashSet;
021    import java.util.Set;
022    
023    import javax.annotation.Resource;
024    
025    import org.apache.camel.CamelContext;
026    import org.apache.cxf.Bus;
027    import org.apache.cxf.configuration.Configurer;
028    import org.apache.cxf.service.model.EndpointInfo;
029    import org.apache.cxf.transport.AbstractTransportFactory;
030    import org.apache.cxf.transport.Conduit;
031    import org.apache.cxf.transport.ConduitInitiator;
032    import org.apache.cxf.transport.Destination;
033    import org.apache.cxf.transport.DestinationFactory;
034    import org.apache.cxf.ws.addressing.EndpointReferenceType;
035    
036    /**
037     * @version $Revision: 563665 $
038     */
039    public class CamelTransportFactory extends AbstractTransportFactory implements ConduitInitiator, DestinationFactory {
040        private static final Set<String> URI_PREFIXES = new HashSet<String>();
041    
042        static {
043            URI_PREFIXES.add("camel://");
044        }
045    
046        private Bus bus;
047        private CamelContext camelContext;
048    
049        @Resource
050        public void setBus(Bus b) {
051            bus = b;
052        }
053    
054        public Bus getBus() {
055            return bus;
056        }
057    
058        public CamelContext getCamelContext() {
059            return camelContext;
060        }
061    
062        @Resource
063        public void setCamelContext(CamelContext camelContext) {
064            this.camelContext = camelContext;
065        }
066    
067        public Conduit getConduit(EndpointInfo targetInfo) throws IOException {
068            return getConduit(targetInfo, null);
069        }
070    
071        public Conduit getConduit(EndpointInfo endpointInfo, EndpointReferenceType target) throws IOException {
072            return new CamelConduit(camelContext, bus, endpointInfo, target);
073        }
074    
075        public Destination getDestination(EndpointInfo endpointInfo) throws IOException {
076            CamelDestination destination = new CamelDestination(camelContext, bus, this, endpointInfo);
077            Configurer configurer = bus.getExtension(Configurer.class);
078            if (null != configurer) {
079                configurer.configureBean(destination);
080            }
081            return destination;
082        }
083    
084        public Set<String> getUriPrefixes() {
085            return URI_PREFIXES;
086        }
087    }
088