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;
018
019 import org.apache.camel.impl.MessageSupport;
020
021 import java.util.Map;
022
023 /**
024 * Implements the <a
025 * href="http://activemq.apache.org/camel/message.html">Message</a> pattern and
026 * represents an inbound or outbound message as part of an {@link Exchange}
027 *
028 * @version $Revision: 564677 $
029 */
030 public interface Message {
031
032 /**
033 * @return the id of the message
034 */
035 String getMessageId();
036
037 /**
038 * set the id of the message
039 *
040 * @param messageId
041 */
042 void setMessageId(String messageId);
043
044 /**
045 * Returns the exchange this message is related to
046 *
047 * @return
048 */
049 Exchange getExchange();
050
051 /**
052 * Accesses a specific header
053 *
054 * @param name
055 * @return object header associated with the name
056 */
057 Object getHeader(String name);
058
059 /**
060 * Returns a header associated with this message by name and specifying the
061 * type required
062 *
063 * @param name the name of the header
064 * @param type the type of the header
065 * @return the value of the given header or null if there is no property for
066 * the given name or it cannot be converted to the given type
067 */
068 <T> T getHeader(String name, Class<T> type);
069
070 /**
071 * Sets a header on the message
072 *
073 * @param name of the header
074 * @param value to associate with the name
075 */
076 void setHeader(String name, Object value);
077
078 /**
079 * Returns all of the headers associated with the message
080 *
081 * @return all the headers in a Map
082 */
083 Map<String, Object> getHeaders();
084
085 /**
086 * Set all the headers associated with this message
087 *
088 * @param headers
089 */
090 void setHeaders(Map<String, Object> headers);
091
092 /**
093 * Returns the body of the message as a POJO
094 *
095 * @return the body of the message
096 */
097 Object getBody();
098
099 /**
100 * Returns the body as the specified type
101 *
102 * @param type the type that the body
103 * @return the body of the message as the specified type
104 */
105 <T> T getBody(Class<T> type);
106
107 /**
108 * Sets the body of the message
109 */
110 void setBody(Object body);
111
112 /**
113 * Sets the body of the message as a specific type
114 */
115 <T> void setBody(Object body, Class<T> type);
116
117 /**
118 * Creates a copy of this message so that it can be used and possibly
119 * modified further in another exchange
120 *
121 * @return a new message instance copied from this message
122 */
123 Message copy();
124
125 /**
126 * Copies the contents of the other message into this message
127 */
128 void copyFrom(Message message);
129 }