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