001 /**
002 *
003 * Licensed to the Apache Software Foundation (ASF) under one or more
004 * contributor license agreements. See the NOTICE file distributed with
005 * this work for additional information regarding copyright ownership.
006 * The ASF licenses this file to You under the Apache License, Version 2.0
007 * (the "License"); you may not use this file except in compliance with
008 * the License. You may obtain a copy of the License at
009 *
010 * http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018 package org.apache.camel.component.xmpp;
019
020 import org.apache.camel.impl.DefaultExchange;
021 import org.apache.camel.CamelContext;
022 import org.apache.camel.Exchange;
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 }