1 17 package org.apache.excalibur.mpool.test; 18 19 import java.util.HashMap ; 20 21 import org.apache.avalon.framework.activity.Disposable; 22 import org.apache.avalon.framework.logger.Logger; 23 import org.apache.excalibur.mpool.ObjectFactory; 24 25 30 public class ClassInstanceObjectFactory 31 implements ObjectFactory, org.apache.avalon.excalibur.pool.ObjectFactory 32 { 33 private HashMap m_instances = new HashMap (); 34 private Logger m_logger; 35 private Class m_clazz; 36 private int m_id; 37 38 41 44 public ClassInstanceObjectFactory( Class clazz, Logger logger ) 45 { 46 m_clazz = clazz; 47 m_logger = logger; 48 m_id = 1; 49 } 50 51 54 public Object newInstance() throws Exception  55 { 56 Object object = m_clazz.newInstance(); 57 Integer id = new Integer ( m_id++ ); 58 59 m_instances.put( object, id ); 60 61 if( m_logger.isDebugEnabled() ) 62 { 63 m_logger.debug( "ClassInstanceObjectFactory.newInstance() id:" + id ); 64 } 65 66 return object; 67 } 68 69 public Class getCreatedClass() 70 { 71 return m_clazz; 72 } 73 74 public void dispose( Object object ) throws Exception  75 { 76 if( object instanceof Disposable ) 77 { 78 ( (Disposable)object ).dispose(); 79 } 80 Integer id = (Integer )m_instances.remove( object ); 81 82 if( m_logger.isDebugEnabled() ) 83 { 84 m_logger.debug( "ClassInstanceObjectFactory.decommission(a " 85 + object.getClass().getName() + ") id:" + id ); 86 } 87 } 88 89 public void decommission( Object object ) throws Exception  90 { 91 dispose( object ); 92 } 93 } 94 95 | Popular Tags |