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