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.ExchangePattern;
024    import org.apache.camel.impl.DefaultExchange;
025    
026    /**
027     * Represents an {@link 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, ExchangePattern pattern, MailBinding binding) {
035            super(context, pattern);
036            this.binding = binding;
037        }
038    
039        public MailExchange(CamelContext context, ExchangePattern pattern, MailBinding binding, Message message) {
040            this(context, pattern, binding);
041            setIn(new MailMessage(message));
042        }
043    
044        public MailExchange(DefaultExchange parent, MailBinding binding) {
045            super(parent);
046            this.binding = binding;
047        }
048    
049        @Override
050        public MailMessage getIn() {
051            return (MailMessage) super.getIn();
052        }
053    
054        @Override
055        public MailMessage getOut() {
056            return (MailMessage) super.getOut();
057        }
058    
059        @Override
060        public MailMessage getOut(boolean lazyCreate) {
061            return (MailMessage) super.getOut(lazyCreate);
062        }
063    
064        @Override
065        public MailMessage getFault() {
066            return (MailMessage) super.getFault();
067        }
068    
069        public MailBinding getBinding() {
070            return binding;
071        }
072    
073        @Override
074        public Exchange newInstance() {
075            return new MailExchange(this, binding);
076        }
077    
078        // Expose Email APIs
079        //-------------------------------------------------------------------------
080    
081        // Implementation methods
082        //-------------------------------------------------------------------------
083    
084        @Override
085        protected MailMessage createInMessage() {
086            return new MailMessage();
087        }
088    
089        @Override
090        protected MailMessage createOutMessage() {
091            return new MailMessage();
092        }
093    }