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