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