001    /**
002     *
003     * Licensed to the Apache Software Foundation (ASF) under one or more
004     * contributor license agreements.  See the NOTICE file distributed with
005     * this work for additional information regarding copyright ownership.
006     * The ASF licenses this file to You under the Apache License, Version 2.0
007     * (the "License"); you may not use this file except in compliance with
008     * the License.  You may obtain a copy of the License at
009     *
010     * http://www.apache.org/licenses/LICENSE-2.0
011     *
012     * Unless required by applicable law or agreed to in writing, software
013     * distributed under the License is distributed on an "AS IS" BASIS,
014     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015     * See the License for the specific language governing permissions and
016     * limitations under the License.
017     */
018    package org.apache.camel.component.mail;
019    
020    import org.apache.camel.CamelContext;
021    import org.apache.camel.Exchange;
022    import org.apache.camel.impl.DefaultExchange;
023    
024    import javax.mail.Message;
025    
026    /**
027     * Represents an {@ilnk Exchange} for working with Mail
028     *
029     * @version $Revision:520964 $
030     */
031    public class MailExchange extends DefaultExchange {
032        private MailBinding binding;
033    
034        public MailExchange(CamelContext context, MailBinding binding) {
035            super(context);
036            this.binding = binding;
037        }
038    
039        public MailExchange(CamelContext context, MailBinding binding, Message message) {
040            this(context, binding);
041            setIn(new MailMessage(message));
042        }
043    
044        @Override
045        public MailMessage getIn() {
046            return (MailMessage) super.getIn();
047        }
048    
049        @Override
050        public MailMessage getOut() {
051            return (MailMessage) super.getOut();
052        }
053    
054        @Override
055        public MailMessage getOut(boolean lazyCreate) {
056            return (MailMessage) super.getOut(lazyCreate);
057        }
058    
059        @Override
060        public MailMessage getFault() {
061            return (MailMessage) super.getFault();
062        }
063    
064        public MailBinding getBinding() {
065            return binding;
066        }
067    
068        @Override
069        public Exchange newInstance() {
070            return new MailExchange(getContext(), binding);
071        }
072    
073        // Expose Email APIs
074        //-------------------------------------------------------------------------
075    
076        // Implementation methods
077        //-------------------------------------------------------------------------
078    
079        @Override
080        protected MailMessage createInMessage() {
081            return new MailMessage();
082        }
083    
084        @Override
085        protected MailMessage createOutMessage() {
086            return new MailMessage();
087        }
088    }