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.camel;
018    
019    import javax.jbi.messaging.MessageExchange;
020    import javax.jbi.messaging.NormalizedMessage;
021    
022    import org.apache.camel.CamelContext;
023    import org.apache.camel.impl.DefaultExchange;
024    
025    /**
026     * An {@link org.apache.camel.Exchange} working with JBI which exposes the underlying JBI
027     * features such as the JBI {@link #getMessageExchange()},
028     * {@link #getInMessage()} and {@link #getOutMessage()}
029     *
030     * @version $Revision: 563665 $
031     */
032    @Deprecated
033    public class JbiExchange extends DefaultExchange {
034        
035        private final JbiBinding binding;
036    
037        public JbiExchange(CamelContext context, JbiBinding binding) {
038            super(context);
039            this.binding = binding;
040        }
041    
042        @Override
043        public JbiMessage getIn() {
044            return (JbiMessage) super.getIn();
045        }
046    
047        @Override
048        public JbiMessage getOut() {
049            return (JbiMessage) super.getOut();
050        }
051    
052        @Override
053        public JbiMessage getOut(boolean lazyCreate) {
054            return (JbiMessage) super.getOut(lazyCreate);
055        }
056    
057        @Override
058        public JbiMessage getFault() {
059            return (JbiMessage) super.getFault();
060        }
061    
062        @Override
063        public JbiMessage getFault(boolean lazyCreate) {
064            return (JbiMessage) super.getFault(lazyCreate);
065        }
066    
067        @Override
068        public org.apache.camel.Exchange newInstance() {    
069            return new JbiExchange(this.getContext(), this.getBinding());
070        }
071    
072        /**
073         * @return the Camel <-> JBI binding
074         */
075        public JbiBinding getBinding() {
076            return binding;
077        }
078    
079        // Expose JBI features
080        // -------------------------------------------------------------------------
081    
082        /**
083         * Returns the underlying JBI message exchange for an inbound exchange or
084         * null for outbound messages
085         *
086         * @return the inbound message exchange
087         */
088        public MessageExchange getMessageExchange() {
089            return JbiBinding.getMessageExchange(this);
090        }
091    
092        /**
093         * Returns the underlying In {@link NormalizedMessage}
094         *
095         * @return the In message
096         */
097        public NormalizedMessage getInMessage() {
098            return getIn().getNormalizedMessage();
099        }
100    
101        /**
102         * Returns the underlying Out {@link NormalizedMessage}
103         *
104         * @return the Out message
105         */
106        public NormalizedMessage getOutMessage() {
107            return getOut().getNormalizedMessage();
108        }
109    
110        /**
111         * Returns the underlying Fault {@link NormalizedMessage}
112         *
113         * @return the Fault message
114         */
115        public NormalizedMessage getFaultMessage() {
116            return getFault().getNormalizedMessage();
117        }
118    
119        // Implementation methods
120        // -------------------------------------------------------------------------
121    
122        @Override
123        protected JbiMessage createInMessage() {
124            return createMessage("in");
125        }
126    
127        @Override
128        protected JbiMessage createOutMessage() {
129            return createMessage("out");
130        }
131    
132        @Override
133        protected JbiMessage createFaultMessage() {
134            return createMessage("fault");
135        }
136        
137    
138        private JbiMessage createMessage(String name) {
139            return new JbiMessage(name);
140        }
141    }