1 17 18 package org.apache.avalon.fortress.impl.factory; 19 20 import org.apache.excalibur.mpool.ObjectFactory; 21 22 30 public final class WrapperObjectFactory extends AbstractObjectFactory 31 { 32 33 36 private final BCELWrapperGenerator m_wrapperGenerator; 37 38 48 public WrapperObjectFactory( final ObjectFactory objectFactory ) 49 throws IllegalArgumentException 50 { 51 super( objectFactory ); 52 m_wrapperGenerator = new BCELWrapperGenerator(); 53 } 54 55 58 public Object newInstance() throws Exception 59 { 60 final Object obj = m_delegateFactory.newInstance(); 61 62 final Class wrappedClass = 63 m_wrapperGenerator.createWrapper( obj.getClass() ); 64 65 return wrappedClass.getConstructor( 66 new Class []{obj.getClass()} ).newInstance( 67 new Object []{obj} ); 68 } 69 70 73 public void dispose( final Object object ) throws Exception 74 { 75 if ( object == null ) 76 { 77 final String error = "Supplied argument is <null>"; 78 throw new IllegalArgumentException ( error ); 79 } 80 if ( !( object instanceof WrapperClass ) ) 81 { 82 final String error = 83 "Supplied argument is no instance of \"" 84 + WrapperClass.class.getName() 85 + "\""; 86 throw new IllegalArgumentException ( error ); 87 } 88 89 final Object target = ( (WrapperClass) object ).getWrappedObject(); 90 91 m_delegateFactory.dispose( target ); 92 } 93 } 94 | Popular Tags |