001    /*
002     * Copyright 2010 the original author or authors.
003     * 
004     *  Licensed under the Apache License, Version 2.0 (the "License");
005     *  you may not use this file except in compliance with the License.
006     *  You may obtain a copy of the License at
007     *
008     *      http://www.apache.org/licenses/LICENSE-2.0
009     *
010     *  Unless required by applicable law or agreed to in writing, software
011     *  distributed under the License is distributed on an "AS IS" BASIS,
012     *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     *  See the License for the specific language governing permissions and
014     *  limitations under the License.
015     */
016    package com.hs.mail.smtp.processor;
017    
018    import java.util.Hashtable;
019    import java.util.Map;
020    
021    import com.hs.mail.exception.LookupException;
022    
023    /**
024     * 
025     * @author Won Chul Doh
026     * @since May 29, 2010
027     * 
028     */
029    public class SmtpProcessorFactory {
030            
031            public static SmtpProcessor createSmtpProcessor(String command) {
032                    SmtpProcessor processor = lookup(command);
033                    return processor;
034            }
035    
036            private static SmtpProcessor lookup(String command) {
037                    SmtpProcessor processor = processorMap.get(command.toLowerCase());
038                    if (null == processor)
039                            throw new LookupException("Class for '" + command + "' not found.");
040                    return processor;
041            }
042    
043            static private Map<String, SmtpProcessor> processorMap = new Hashtable<String, SmtpProcessor>();
044            static {
045                    processorMap
046                                    .put("auth", new com.hs.mail.smtp.processor.AuthProcessor());
047                    processorMap
048                                    .put("data", new com.hs.mail.smtp.processor.DataProcessor());
049                    processorMap
050                                    .put("ehlo", new com.hs.mail.smtp.processor.EhloProcessor());
051                    processorMap
052                                    .put("expn", new com.hs.mail.smtp.processor.ExpnProcessor());
053                    processorMap
054                                    .put("helo", new com.hs.mail.smtp.processor.HeloProcessor());
055                    processorMap
056                                    .put("help", new com.hs.mail.smtp.processor.HelpProcessor());
057                    processorMap
058                                    .put("mail", new com.hs.mail.smtp.processor.MailProcessor());
059                    processorMap
060                                    .put("noop", new com.hs.mail.smtp.processor.NoopProcessor());
061                    processorMap
062                                    .put("quit", new com.hs.mail.smtp.processor.QuitProcessor());
063                    processorMap
064                                    .put("rcpt", new com.hs.mail.smtp.processor.RcptProcessor());
065                    processorMap
066                                    .put("rset", new com.hs.mail.smtp.processor.RsetProcessor());
067                    processorMap
068                                    .put("vrfy", new com.hs.mail.smtp.processor.VrfyProcessor());
069            }
070    
071    }