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: 653092 $
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        /**
140         * Returns the attachment specified by the id
141         *
142         * @param id        the id under which the attachment is stored
143         * @return          the data handler for this attachment or null
144         */
145        DataHandler getAttachment(String id);
146    
147        /**
148         * Returns a set of attachment names of the message
149         *
150         * @return  a set of attachment names
151         */
152        Set<String> getAttachmentNames();
153    
154        /**
155         * Removes the attachment specified by the id
156         *
157         * @param id        the id of the attachment to remove
158         */
159        void removeAttachment(String id);
160    
161        /**
162         * Adds an attachment to the message using the id
163         *
164         * @param id        the id to store the attachment under
165         * @param content   the data handler for the attachment
166         */
167        void addAttachment(String id, DataHandler content);
168    
169        /**
170         * Returns all attachments of the message
171         *
172         * @return  the attachments in a map or null
173         */
174        Map<String, DataHandler> getAttachments();
175    
176        /**
177         * Set all the attachments associated with this message
178         *
179         * @param attachments
180         */
181        void setAttachments(Map<String, DataHandler> attachments);
182    
183        /**
184         * Returns <tt>true</tt> if this message has any attachments.
185         */
186        boolean hasAttachments();
187    }