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.component.mail;
018    
019    import javax.mail.Message;
020    
021    import org.apache.camel.CamelContext;
022    import org.apache.camel.Exchange;
023    import org.apache.camel.impl.DefaultExchange;
024    
025    /**
026     * Represents an {@ilnk Exchange} for working with Mail
027     *
028     * @version $Revision:520964 $
029     */
030    public class MailExchange extends DefaultExchange {
031        private MailBinding binding;
032    
033        public MailExchange(CamelContext context, MailBinding binding) {
034            super(context);
035            this.binding = binding;
036        }
037    
038        public MailExchange(CamelContext context, MailBinding binding, Message message) {
039            this(context, binding);
040            setIn(new MailMessage(message));
041        }
042    
043        @Override
044        public MailMessage getIn() {
045            return (MailMessage) super.getIn();
046        }
047    
048        @Override
049        public MailMessage getOut() {
050            return (MailMessage) super.getOut();
051        }
052    
053        @Override
054        public MailMessage getOut(boolean lazyCreate) {
055            return (MailMessage) super.getOut(lazyCreate);
056        }
057    
058        @Override
059        public MailMessage getFault() {
060            return (MailMessage) super.getFault();
061        }
062    
063        public MailBinding getBinding() {
064            return binding;
065        }
066    
067        @Override
068        public Exchange newInstance() {
069            return new MailExchange(getContext(), binding);
070        }
071    
072        // Expose Email APIs
073        //-------------------------------------------------------------------------
074    
075        // Implementation methods
076        //-------------------------------------------------------------------------
077    
078        @Override
079        protected MailMessage createInMessage() {
080            return new MailMessage();
081        }
082    
083        @Override
084        protected MailMessage createOutMessage() {
085            return new MailMessage();
086        }
087    }