1 8 package org.apache.avalon.excalibur.pool.test; 9 10 import java.util.HashMap ; 11 12 import org.apache.avalon.excalibur.pool.ObjectFactory; 13 import org.apache.avalon.framework.logger.Logger; 14 15 20 public class ClassInstanceObjectFactory 21 implements ObjectFactory 22 { 23 private HashMap m_instances = new HashMap (); 24 private Logger m_logger; 25 private Class m_clazz; 26 private int m_id; 27 28 31 34 public ClassInstanceObjectFactory( Class clazz, Logger logger ) 35 { 36 m_clazz = clazz; 37 m_logger = logger; 38 m_id = 1; 39 } 40 41 44 public Object newInstance() throws Exception 45 { 46 Object object = m_clazz.newInstance(); 47 Integer id = new Integer ( m_id++ ); 48 49 m_instances.put( object, id ); 50 m_logger.debug( "ClassInstanceObjectFactory.newInstance() id:" + id ); 51 52 return object; 53 } 54 55 public Class getCreatedClass() 56 { 57 return m_clazz; 58 } 59 60 public void decommission( Object object ) throws Exception 61 { 62 Integer id = (Integer )m_instances.remove( object ); 63 m_logger.debug( "ClassInstanceObjectFactory.decommission(a " 64 + object.getClass().getName() + ") id:" + id ); 65 } 66 } 67 68 | Popular Tags |