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