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    import java.util.Set;
021    
022    import javax.activation.DataHandler;
023    
024    /**
025     * Implements the <a
026     * href="http://activemq.apache.org/camel/message.html">Message</a> pattern and
027     * represents an inbound or outbound message as part of an {@link Exchange}
028     *
029     * @version $Revision: 37863 $
030     */
031    public interface Message {
032    
033        /**
034         * Returns the id of the message
035         *
036         * @return the id of the message
037         */
038        String getMessageId();
039    
040        /**
041         * Sets the id of the message
042         *
043         * @param messageId
044         */
045        void setMessageId(String messageId);
046    
047        /**
048         * Returns the exchange this message is related to
049         */
050        Exchange getExchange();
051    
052        /**
053         * Accesses a specific header
054         *
055         * @param name  name of header
056         * @return object header associated with the name
057         */
058        Object getHeader(String name);
059    
060        /**
061         * Returns a header associated with this message by name and specifying the
062         * type required
063         *
064         * @param name the name of the header
065         * @param type the type of the header
066         * @return the value of the given header or null if there is no property for
067         *         the given name or it cannot be converted to the given type
068         */
069        <T> T getHeader(String name, Class<T> type);
070    
071        /**
072         * Sets a header on the message
073         *
074         * @param name of the header
075         * @param value to associate with the name
076         */
077        void setHeader(String name, Object value);
078    
079        /**
080         * Removes the named header from this message
081         *
082         * @param name
083         * @return the old value of the header
084         */
085        Object removeHeader(String name);
086    
087        /**
088         * Returns all of the headers associated with the message
089         *
090         * @return all the headers in a Map
091         */
092        Map<String, Object> getHeaders();
093    
094        /**
095         * Set all the headers associated with this message
096         *
097         * @param headers
098         */
099        void setHeaders(Map<String, Object> headers);
100    
101        /**
102         * Returns the body of the message as a POJO
103         *
104         * @return the body of the message
105         */
106        Object getBody();
107    
108        /**
109         * Returns the body as the specified type
110         *
111         * @param type the type that the body
112         * @return the body of the message as the specified type
113         */
114        <T> T getBody(Class<T> type);
115    
116        /**
117         * Sets the body of the message
118         */
119        void setBody(Object body);
120    
121        /**
122         * Sets the body of the message as a specific type
123         */
124        <T> void setBody(Object body, Class<T> type);
125    
126        /**
127         * Creates a copy of this message so that it can be used and possibly
128         * modified further in another exchange
129         *
130         * @return a new message instance copied from this message
131         */
132        Message copy();
133    
134        /**
135         * Copies the contents of the other message into this message
136         */
137        void copyFrom(Message message);
138        /**
139         * returns the attachment specified by the id
140         *
141         * @param id        the id under which the attachment is stored
142         * @return          the data handler for this attachment or null
143         */
144        DataHandler getAttachment(String id);
145    
146        /**
147         * returns a set of attachment names of the message
148         *
149         * @return  a set of attachment names
150         */
151        Set<String> getAttachmentNames();
152    
153        /**
154         * removes the attachment specified by the id
155         *
156         * @param id        the id of the attachment to remove
157         */
158        void removeAttachment(String id);
159    
160        /**
161         * adds an attachment to the message using the id
162         *
163         * @param id        the id to store the attachment under
164         * @param content   the data handler for the attachment
165         */
166        void addAttachment(String id, DataHandler content);
167    
168        /**
169         * returns all attachments of the message
170         *
171         * @return  the attachments in a map or null
172         */
173        Map<String, DataHandler> getAttachments();
174    
175        /**
176         * Set all the attachments associated with this message
177         *
178         * @param attachments
179         */
180        void setAttachments(Map<String, DataHandler> attachments);
181    }