| | |
| | | |
| | | package org.forgerock.opendj.ldap; |
| | | |
| | | import static com.forgerock.opendj.util.StaticUtils.getProvider; |
| | | |
| | | import java.net.InetAddress; |
| | | import java.net.InetSocketAddress; |
| | | import java.net.SocketAddress; |
| | | |
| | | import com.forgerock.opendj.ldap.LDAPConnectionFactoryImpl; |
| | | import org.forgerock.opendj.ldap.spi.LDAPConnectionFactoryImpl; |
| | | import org.forgerock.opendj.ldap.spi.TransportProvider; |
| | | |
| | | import com.forgerock.opendj.util.Validator; |
| | | |
| | | /** |
| | |
| | | */ |
| | | private final LDAPConnectionFactoryImpl impl; |
| | | |
| | | /* |
| | | * Transport provider that provides the implementation of this factory. |
| | | */ |
| | | private TransportProvider provider; |
| | | |
| | | /** |
| | | * Creates a new LDAP connection factory which can be used to create LDAP |
| | | * connections to the Directory Server at the provided address. |
| | |
| | | * The address of the Directory Server. |
| | | * @throws NullPointerException |
| | | * If {@code address} was {@code null}. |
| | | * @throws ProviderNotFoundException if no provider is available or if the |
| | | * provider requested using options is not found. |
| | | */ |
| | | public LDAPConnectionFactory(final SocketAddress address) { |
| | | this(address, new LDAPOptions()); |
| | |
| | | * The LDAP options to use when creating connections. |
| | | * @throws NullPointerException |
| | | * If {@code address} or {@code options} was {@code null}. |
| | | * @throws ProviderNotFoundException if no provider is available or if the |
| | | * provider requested using options is not found. |
| | | */ |
| | | public LDAPConnectionFactory(final SocketAddress address, final LDAPOptions options) { |
| | | Validator.ensureNotNull(address, options); |
| | | this.impl = new LDAPConnectionFactoryImpl(address, options); |
| | | this.provider = getProvider(TransportProvider.class, options.getTransportProvider(), |
| | | options.getProviderClassLoader()); |
| | | this.impl = provider.getLDAPConnectionFactory(address, options); |
| | | } |
| | | |
| | | /** |
| | |
| | | * The port number. |
| | | * @throws NullPointerException |
| | | * If {@code host} was {@code null}. |
| | | * @throws ProviderNotFoundException if no provider is available or if the |
| | | * provider requested using options is not found. |
| | | */ |
| | | public LDAPConnectionFactory(final String host, final int port) { |
| | | this(host, port, new LDAPOptions()); |
| | |
| | | * The LDAP options to use when creating connections. |
| | | * @throws NullPointerException |
| | | * If {@code host} or {@code options} was {@code null}. |
| | | * @throws ProviderNotFoundException if no provider is available or if the |
| | | * provider requested using options is not found. |
| | | */ |
| | | public LDAPConnectionFactory(final String host, final int port, final LDAPOptions options) { |
| | | Validator.ensureNotNull(host, options); |
| | | final SocketAddress address = new InetSocketAddress(host, port); |
| | | this.impl = new LDAPConnectionFactoryImpl(address, options); |
| | | this.provider = getProvider(TransportProvider.class, options.getTransportProvider(), |
| | | options.getProviderClassLoader()); |
| | | this.impl = provider.getLDAPConnectionFactory(address, options); |
| | | } |
| | | |
| | | /** |
| | |
| | | } |
| | | |
| | | /** |
| | | * Returns the address that this LDAP listener is listening on. |
| | | * Returns the address used by the connections created by this factory. |
| | | * |
| | | * @return The address that this LDAP listener is listening on. |
| | | * @return The address used by the connections. |
| | | */ |
| | | public SocketAddress getSocketAddress() { |
| | | return impl.getSocketAddress(); |
| | | } |
| | | |
| | | /** |
| | | * Returns the name of the transport provider, which provides the implementation |
| | | * of this factory. |
| | | * |
| | | * @return The name of actual transport provider. |
| | | */ |
| | | public String getProviderName() { |
| | | return provider.getName(); |
| | | } |
| | | |
| | | @Override |
| | | public String toString() { |
| | | return impl.toString(); |