001    /*
002     * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE
003     * file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file
004     * to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the
005     * License. You may obtain a copy of the License at
006     * 
007     * http://www.apache.org/licenses/LICENSE-2.0
008     * 
009     * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
010     * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
011     * specific language governing permissions and limitations under the License.
012     */
013    package org.apache.camel.component.jbi;
014    
015    import org.apache.camel.Endpoint;
016    import org.apache.camel.Processor;
017    import org.apache.camel.Exchange;
018    import org.apache.commons.logging.Log;
019    import org.apache.commons.logging.LogFactory;
020    import org.apache.servicemix.common.ServiceUnit;
021    import org.apache.servicemix.common.endpoints.ProviderEndpoint;
022    
023    import javax.jbi.messaging.MessageExchange;
024    import javax.jbi.messaging.NormalizedMessage;
025    import javax.xml.namespace.QName;
026    
027    /**
028     * A JBI endpoint which when invoked will delegate to a Camel endpoint
029     *
030     * @version $Revision: 426415 $
031     */
032    public class CamelJbiEndpoint extends ProviderEndpoint {
033        private static final transient Log log = LogFactory.getLog(CamelJbiEndpoint.class);
034        private static final QName SERVICE_NAME = new QName("http://camel.apache.org/service", "CamelEndpointComponent");
035        private Endpoint camelEndpoint;
036        private JbiBinding binding;
037        private Processor processor;
038    
039        public CamelJbiEndpoint(ServiceUnit serviceUnit, QName service, String endpoint, Endpoint camelEndpoint, JbiBinding binding, Processor processor) {
040            super(serviceUnit, service, endpoint);
041            this.processor = processor;
042            this.camelEndpoint = camelEndpoint;
043            this.binding = binding;
044        }
045    
046        public CamelJbiEndpoint(ServiceUnit serviceUnit, Endpoint camelEndpoint, JbiBinding binding, Processor processor) {
047            this(serviceUnit, SERVICE_NAME, camelEndpoint.getEndpointUri(), camelEndpoint, binding, processor);
048        }
049    
050        protected void processInOnly(MessageExchange exchange, NormalizedMessage in) throws Exception {
051            if (log.isDebugEnabled()) {
052                log.debug("Received exchange: " + exchange);
053            }
054            JbiExchange camelExchange = new JbiExchange(camelEndpoint.getContext(), binding, exchange);
055            processor.process(camelExchange);
056        }
057    
058        protected void processInOut(MessageExchange exchange, NormalizedMessage in, NormalizedMessage out) throws Exception {
059            if (log.isDebugEnabled()) {
060                log.debug("Received exchange: " + exchange);
061            }
062            /*
063             * ToDo
064             */
065        }
066    }