All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.nlab.smtp.transport.strategy.ConnectionStrategyFactory Maven / Gradle / Ivy

The newest version!
package org.nlab.smtp.transport.strategy;

import jakarta.mail.MessagingException;
import jakarta.mail.Transport;

/**
 * {@link Transport} supports actually 4 types of connections which are handled by this connection strategy factory
 * 
    *
  1. {@link Transport#connect()} => {@link #newConnectionStrategy()}
  2. *
  3. {@link Transport#connect(String, String)} ()} => {@link #newConnectionStrategy(String, String)}
  4. *
  5. {@link Transport#connect(String, String, String)} ()} => {@link #newConnectionStrategy(String, String, String)}
  6. *
  7. {@link Transport#connect(String, int, String, String)} ()} => {@link #newConnectionStrategy(String, int, String, String)}
  8. *
*

* Created by nlabrot on 04/06/15. */ public class ConnectionStrategyFactory { public static ConnectionStrategy newConnectionStrategy() { return new ConnectionStrategy() { @Override public void connect(Transport transport) throws MessagingException { transport.connect(); } }; } public static ConnectionStrategy newConnectionStrategy(final String username, final String password) { return new ConnectionStrategy() { @Override public void connect(Transport transport) throws MessagingException { transport.connect(username, password); } @Override public String toString() { return "ConnectionStrategy{" + "username=" + username + '}'; } }; } public static ConnectionStrategy newConnectionStrategy(final String host, final String username, final String password) { return new ConnectionStrategy() { @Override public void connect(Transport transport) throws MessagingException { transport.connect(host, username, password); } @Override public String toString() { return "ConnectionStrategy{" + "host=" + host + ", username=" + username + '}'; } }; } public static ConnectionStrategy newConnectionStrategy(final String host, final int port, final String username, final String password) { return new ConnectionStrategy() { @Override public void connect(Transport transport) throws MessagingException { transport.connect(host, port, username, password); } @Override public String toString() { return "ConnectionStrategy{" + "host=" + host + ", port=" + port + ", username=" + username + '}'; } }; } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy