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.xmpp;
018    
019    import org.apache.camel.CamelContext;
020    import org.apache.camel.Exchange;
021    import org.apache.camel.impl.DefaultExchange;
022    
023    import org.jivesoftware.smack.packet.Message;
024    
025    /**
026     * Represents an {@ilnk Exchange} for working with XMPP
027     *
028     * @version $Revision:520964 $
029     */
030    public class XmppExchange extends DefaultExchange {
031        private XmppBinding binding;
032    
033        public XmppExchange(CamelContext context, XmppBinding binding) {
034            super(context);
035            this.binding = binding;
036        }
037    
038        public XmppExchange(CamelContext context, XmppBinding binding, Message message) {
039            this(context, binding);
040            setIn(new XmppMessage(message));
041        }
042    
043        @Override
044        public XmppMessage getIn() {
045            return (XmppMessage) super.getIn();
046        }
047    
048        @Override
049        public XmppMessage getOut() {
050            return (XmppMessage) super.getOut();
051        }
052    
053        @Override
054        public XmppMessage getOut(boolean lazyCreate) {
055            return (XmppMessage) super.getOut(lazyCreate);
056        }
057    
058        @Override
059        public XmppMessage getFault() {
060            return (XmppMessage) super.getFault();
061        }
062    
063        public XmppBinding getBinding() {
064            return binding;
065        }
066    
067        @Override
068        public Exchange newInstance() {
069            return new XmppExchange(getContext(), binding);
070        }
071    
072        // Expose the underlying XMPP APIs
073        //-------------------------------------------------------------------------
074    
075        /**
076         * Return the underlying XMPP In message
077         *
078         * @return the XMPP In message
079         */
080        public Message getInMessage() {
081            return getIn().getXmppMessage();
082        }
083    
084        /**
085         * Return the underlying XMPP Out message
086         *
087         * @return the XMPP out message
088         */
089        public Message getOutMessage() {
090            return getOut().getXmppMessage();
091        }
092    
093        /**
094         * Return the underlying XMPP Fault message
095         *
096         * @return the XMPP fault message
097         */
098        public Message getFaultMessage() {
099            return getOut().getXmppMessage();
100        }
101    
102        // Implementation methods
103        //-------------------------------------------------------------------------
104    
105        @Override
106        protected XmppMessage createInMessage() {
107            return new XmppMessage();
108        }
109    
110        @Override
111        protected XmppMessage createOutMessage() {
112            return new XmppMessage();
113        }
114    }