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.spring.integration;
018
019 import java.util.HashMap;
020 import java.util.Map;
021
022 import org.apache.camel.impl.DefaultMessage;
023 import org.springframework.integration.core.MessageHeaders;
024
025 /**
026 * The Message {@link DefaultMessage} implementation
027 * for accessing the SpringIntegrationMessage
028 *
029 * @version $Revision: 749629 $
030 */
031 public class SpringIntegrationMessage extends DefaultMessage {
032 private org.springframework.integration.core.Message siMessage;
033
034 public SpringIntegrationMessage(org.springframework.integration.core.Message message) {
035 siMessage = message;
036 }
037
038 public SpringIntegrationMessage() {
039
040 }
041
042 public void setMessage(org.springframework.integration.core.Message message) {
043 siMessage = message;
044 }
045
046 public org.springframework.integration.core.Message getMessage() {
047 return siMessage;
048 }
049
050 @Override
051 public void copyFrom(org.apache.camel.Message that) {
052 setMessageId(that.getMessageId());
053 setBody(that.getBody());
054 getHeaders().putAll(that.getHeaders());
055 if (that instanceof SpringIntegrationMessage) {
056 SpringIntegrationMessage orig = (SpringIntegrationMessage) that;
057 setMessage(orig.getMessage());
058 }
059 getAttachments().putAll(that.getAttachments());
060 }
061
062 @Override
063 public String toString() {
064 if (siMessage != null) {
065 return "SpringIntegrationMessage: " + siMessage;
066 } else {
067 return "SpringIntegrationMessage: " + getBody();
068 }
069 }
070
071 @Override
072 public SpringIntegrationExchange getExchange() {
073 return (SpringIntegrationExchange)super.getExchange();
074 }
075
076
077 public Object getHeader(String name) {
078 if (siMessage != null) {
079 return siMessage.getHeaders().get(name);
080 } else {
081 return super.getHeader(name);
082 }
083 }
084
085 @Override
086 public Map<String, Object> getHeaders() {
087 if (siMessage != null) {
088 return siMessage.getHeaders();
089 } else {
090 return super.getHeaders();
091 }
092 }
093
094 @Override
095 public SpringIntegrationMessage newInstance() {
096 return new SpringIntegrationMessage();
097 }
098
099 @Override
100 protected Object createBody() {
101 return siMessage.getPayload();
102 }
103
104 }