dddd

来源:互联网 发布:小米网络音响vs潘多拉 编辑:程序博客网 时间:2024/05/02 01:26

public class ConnectionFactory {
 
 private static String conf=ConnectionFactory.class.getClassLoader().getResource(""). getPath()+"./conf/ldapconf";
 private static Properties properties = null;
 private static Hashtable env=null;
 private static Control[] connCtls = null;
 
 private static ConnectionFactory conn=null;
 
 
 public static ConnectionFactory getInitialize(){
  
  if(conn==null){
   conn=new ConnectionFactory();
  }
  
  return conn;
 }
 

 private ConnectionFactory()
 {
  try{
   
   properties = new Properties();
   env = new Hashtable();
   InputStream pin =  new   FileInputStream(conf+".properties") ;
   properties.load(pin);
   pin.close();
   Enumeration em =  properties.keys();
       while(em.hasMoreElements())
   {
    Object obj=    em.nextElement();
    
    if(obj.toString().substring(0,9).equals("keystore_")){
        System.setProperty(obj.toString().substring(9),properties.getProperty( obj.toString()));
    }else
    {  
          
     env.put(obj.toString(),properties.getProperty( obj.toString()));
    }
    
   }
  
   pin.close();
   }
   catch(Exception e)
   {
    e.printStackTrace();
   }
 }
 
 
 
 public static Hashtable getEnv()
 {
  return env;
 }
 public static LdapContext getConnection() throws Exception
 {
  LdapContext ctx= new InitialLdapContext(env,connCtls);
  return ctx;
 }

}

原创粉丝点击