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.servicemix.soap.core;
018    
019    import java.util.HashMap;
020    import java.util.Map;
021    import java.util.Set;
022    
023    import javax.activation.DataHandler;
024    import javax.xml.namespace.QName;
025    
026    import org.apache.servicemix.soap.api.Message;
027    import org.w3c.dom.DocumentFragment;
028    
029    /**
030     * @author <a href="mailto:gnodet [at] gmail.com">Guillaume Nodet</a>
031     */
032    public class MessageImpl extends HashMap<String, Object> implements Message {
033        
034        /**
035         * Generated serial version UID 
036         */
037        private static final long serialVersionUID = 6062413098383260636L;
038        
039        private Map<String, DataHandler> attachments = new HashMap<String, DataHandler>();
040        private Map<Class<?>, Object> contents = new HashMap<Class<?>, Object>();
041        private Map<QName, DocumentFragment> soapHeaders = new HashMap<QName, DocumentFragment>();
042        private Map<String, String> transportHeaders = new HashMap<String, String>();
043        
044        public Map<String, DataHandler> getAttachments() {
045            return attachments;
046        }
047    
048        public String getAttachmentMimeType() {
049            //for sub class overriding
050            return null;
051        }
052        
053        public <T> T getContent(Class<T> format) {
054            return format.cast(contents.get(format));
055        }
056    
057        public <T> void setContent(Class<T> format, Object content) {
058            contents.put(format, content);
059        }
060    
061        public Set<Class<?>> getContentFormats() {
062            return contents.keySet();
063        }
064    
065        public <T> T get(Class<T> key) {
066            return key.cast(get(key.getName()));
067        }
068    
069        public <T> void put(Class<T> key, T value) {
070            put(key.getName(), value);
071        }
072    
073        public Map<QName, DocumentFragment> getSoapHeaders() {
074            return soapHeaders;
075        }
076    
077        public Map<String, String> getTransportHeaders() {
078            return transportHeaders;
079        }
080    }