001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 * 019 */ 020 021package org.apache.directory.ldap.client.api; 022 023 024/** 025 * A LdapConnection factory. 026 * 027 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 028 */ 029public final class LdapConnectionFactory 030{ 031 032 /** 033 * Private constructor. 034 * 035 */ 036 private LdapConnectionFactory() 037 { 038 } 039 040 041 /** 042 * Gets the core session connection. 043 * 044 * @return a connection based on the the CoreSession 045 */ 046 public static LdapConnection getCoreSessionConnection() 047 { 048 try 049 { 050 Class<?> cl = Class.forName( "org.apache.directory.server.core.LdapCoreSessionConnection" ); 051 return ( LdapConnection ) cl.newInstance(); 052 } 053 catch ( Exception e ) 054 { 055 throw new RuntimeException( e ); 056 } 057 } 058 059 060 /** 061 * Gets the network connection. 062 * 063 * @param host the host 064 * @param port the port 065 * @return the LdapNetworkConnection 066 */ 067 public static LdapAsyncConnection getNetworkConnection( String host, int port ) 068 { 069 try 070 { 071 Class<?> cl = Class.forName( "org.apache.directory.ldap.client.api.LdapNetworkConnection" ); 072 073 LdapAsyncConnection networkConnection = ( LdapAsyncConnection ) cl.newInstance(); 074 networkConnection.getConfig().setLdapHost( host ); 075 networkConnection.getConfig().setLdapPort( port ); 076 077 return networkConnection; 078 } 079 catch ( Exception e ) 080 { 081 throw new RuntimeException( e ); 082 } 083 } 084}