1 8 package org.apache.avalon.phoenix.components.application; 9 10 import org.apache.avalon.phoenix.metadata.BlockMetaData; 11 import org.apache.avalon.phoenix.metainfo.BlockInfo; 12 import org.apache.avalon.phoenix.metainfo.ServiceDescriptor; 13 14 19 class BlockEntry 20 { 21 private Object m_object; 22 23 private BlockMetaData m_blockMetaData; 24 25 private BlockInvocationHandler m_invocationHandler; 26 27 public BlockEntry( final BlockMetaData blockMetaData ) 28 { 29 invalidate(); 30 m_blockMetaData = blockMetaData; 31 } 32 33 public String getName() 34 { 35 return getMetaData().getName(); 36 } 37 38 public BlockMetaData getMetaData() 39 { 40 return m_blockMetaData; 41 } 42 43 public synchronized Object getObject() 44 { 45 return m_object; 46 } 47 48 public synchronized void setObject( final Object object ) 49 { 50 invalidate(); 51 52 if( null != object && ! getMetaData().isDisableProxy() ) 53 { 54 final BlockInfo blockInfo = getMetaData().getBlockInfo(); 55 final Class [] interfaces = getServiceClasses( object, blockInfo.getServices() ); 56 m_invocationHandler = new BlockInvocationHandler( object, interfaces ); 57 } 58 m_object = object; 59 } 60 61 public synchronized Object getProxy() 62 { 63 if ( getMetaData().isDisableProxy() ) 64 { 65 return m_object; 66 } 67 else 68 { 69 if( null != m_invocationHandler ) 70 { 71 return m_invocationHandler.getProxy(); 72 } 73 else 74 { 75 return null; 76 } 77 } 78 } 79 80 protected synchronized void invalidate() 81 { 82 if( null != m_invocationHandler ) 83 { 84 m_invocationHandler.invalidate(); 85 m_invocationHandler = null; 86 } 87 m_object = null; 88 } 89 90 private Class [] getServiceClasses( final Object block, final ServiceDescriptor[] services ) 91 { 92 final Class [] classes = new Class [ services.length + 1 ]; 93 final ClassLoader classLoader = block.getClass().getClassLoader(); 94 95 for( int i = 0; i < services.length; i++ ) 96 { 97 try 98 { 99 classes[ i ] = classLoader.loadClass( services[ i ].getName() ); 100 } 101 catch( final Throwable throwable ) 102 { 103 } 105 } 106 107 classes[ services.length ] = 115 org.apache.avalon.phoenix.Block.class; 116 return classes; 117 } 118 } 119
| Popular Tags
|