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