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.script;
018    
019    import javax.jbi.component.ComponentContext;
020    import javax.jbi.messaging.DeliveryChannel;
021    import javax.jbi.messaging.MessageExchange;
022    import javax.jbi.messaging.MessageExchangeFactory;
023    import javax.jbi.messaging.MessagingException;
024    
025    /**
026     * This helper object can be injected into your scripts to allow to quick access
027     * to basic JBI operations
028     * 
029     * @org.apache.xbean.XBean element="exchangeHelper" description="ServiceMix
030     *                         Scripting Helper"
031     */
032    public class ScriptExchangeHelper implements ScriptHelper {
033    
034        protected ScriptExchangeProcessorEndpoint endpoint;
035    
036        /*
037         * (non-Javadoc)
038         * 
039         * @see org.apache.servicemix.script.ScriptHelper#setScriptExchangeProcessorEndpoint(
040         *          org.apache.servicemix.script.ScriptExchangeProcessorEndpoint)
041         */
042        public void setScriptExchangeProcessorEndpoint(ScriptExchangeProcessorEndpoint ep) {
043            this.endpoint = ep;
044        }
045    
046        public void doneExchange(MessageExchange exchange) throws MessagingException {
047            endpoint.done(exchange);
048        }
049    
050        public void failExchange(MessageExchange exchange, Exception exception) throws MessagingException {
051            endpoint.fail(exchange, exception);
052        }
053    
054        public void sendExchange(MessageExchange exchange) throws MessagingException {
055            endpoint.send(exchange);
056        }
057    
058        public void sendSyncExchange(MessageExchange exchange) throws MessagingException {
059            endpoint.sendSync(exchange);
060        }
061    
062        public DeliveryChannel getChannel() {
063            return endpoint.getChannel();
064        }
065    
066        public ComponentContext getContext() {
067            return endpoint.getContext();
068        }
069    
070        public MessageExchangeFactory getExchangeFactory() {
071            return endpoint.getExchangeFactory();
072        }
073    }