www.pudn.com > dangdang.zip > BeanFactory.java, change:2006-06-22,size:707b


package com.tarena.dangdang.util; 
 
import java.io.IOException; 
import java.io.InputStream; 
import java.util.Properties; 
 
public class BeanFactory { 
  private static Properties env = new Properties(); 
  static{ 
	  try { 
		InputStream is = BeanFactory.class.getResourceAsStream("/com/tarena/dangdang/res/beans.properties"); 
		env.load(is); 
		is.close(); 
	} catch (IOException e) { 
		e.printStackTrace(); 
	} 
  } 
   
  public static Object getBean(String name){ 
	  Object ret = null; 
	try { 
		String className = env.getProperty(name); 
		  Class c = Class.forName(className); 
		  ret = c.newInstance(); 
	} catch (Exception e) { 
		e.printStackTrace(); 
	} 
	 return ret; 
	   
  } 
   
}