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