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: 787831 $
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 public Object getHeader(String name) {
072 if (siMessage != null) {
073 return siMessage.getHeaders().get(name);
074 } else {
075 return super.getHeader(name);
076 }
077 }
078
079 @Override
080 public Map<String, Object> getHeaders() {
081 if (siMessage != null) {
082 return siMessage.getHeaders();
083 } else {
084 return super.getHeaders();
085 }
086 }
087
088 @Override
089 public SpringIntegrationMessage newInstance() {
090 return new SpringIntegrationMessage();
091 }
092
093 @Override
094 protected Object createBody() {
095 return siMessage.getPayload();
096 }
097 }