View Javadoc

1   /*
2    * Copyright (c) 2004-2007 Creative Sphere Limited.
3    * All rights reserved. This program and the accompanying materials
4    * are made available under the terms of the Eclipse Public License v1.0
5    * which accompanies this distribution, and is available at
6    * http://www.eclipse.org/legal/epl-v10.html
7    *
8    * Contributors:
9    *
10   *   Creative Sphere - initial API and implementation
11   *
12   */
13  package org.abstracthorizon.mercury.smtp.command;
14  
15  import org.abstracthorizon.danube.connection.Connection;
16  import org.abstracthorizon.danube.connection.ConnectionHandler;
17  import org.abstracthorizon.danube.support.RuntimeIOException;
18  import org.abstracthorizon.mercury.common.command.CommandException;
19  import org.abstracthorizon.mercury.smtp.SMTPSession;
20  import org.abstracthorizon.mercury.smtp.exception.ParserException;
21  
22  import java.io.IOException;
23  
24  /**
25   * Base SMTP comamnd. It defines handling of exceptions from commands
26   *
27   * @author Daniel Sendula
28   */
29  public abstract class SMTPCommand implements ConnectionHandler {
30  
31      /**
32       * Constructor
33       */
34      public SMTPCommand() {
35      }
36  
37      /**
38       * Executed the command calling {@link #execute(SMTPSession)} method
39       * @param connection smtp session
40       */
41      public void handleConnection(Connection connection) {
42          SMTPSession smtpConnection = (SMTPSession)connection;
43          try {
44              execute(smtpConnection);
45          } catch (IOException e) {
46              throw new RuntimeIOException(e);
47          }
48      }
49  
50      /**
51       * Executed the command
52       * @param connection smtp session
53       * @throws CommandException
54       * @throws IOException
55       * @throws ParserException
56       */
57      protected abstract void execute(SMTPSession connection) throws CommandException, IOException, ParserException;
58  
59  }