1 4 package com.tctest.spring.bean; 5 6 import org.springframework.beans.factory.DisposableBean; 7 import org.springframework.beans.factory.InitializingBean; 8 import org.springframework.context.ApplicationContext; 9 import org.springframework.context.ApplicationContextAware; 10 import org.springframework.beans.factory.BeanNameAware; 11 import org.springframework.context.support.AbstractApplicationContext; 12 13 import com.tc.aspectwerkz.proxy.Uuid; 14 15 import java.util.ArrayList ; 16 import java.util.List ; 17 18 public class LifeCycleBean implements InitializingBean, ApplicationContextAware, 19 BeanNameAware, DisposableBean, ILifeCycle { 20 private transient long mSystemId; 21 22 private List mProp; 23 24 private List mInvocationRecords = new ArrayList (); 25 private transient ApplicationContext mAppCtx = null; 26 private transient String mBeanName = null; 27 28 public LifeCycleBean() { 29 mSystemId = System.identityHashCode(this) + Uuid.newUuid(); 30 } 31 32 public long getSystemId() { return mSystemId; } 33 34 synchronized public List getInvocationRecords() { 35 return mInvocationRecords; 36 } 37 38 41 public void afterPropertiesSet() { 42 mProp.add("" + mSystemId); 44 this.mInvocationRecords.add("afterPropertiesSet-" + mSystemId); 45 System.err.println("afterPropertiesSet-" + mSystemId); 46 } 47 48 51 public void setApplicationContext(ApplicationContext applicationContext) { 52 mAppCtx = applicationContext; 53 this.mInvocationRecords.add("setBeanName-" + mSystemId); 54 System.err.println("setBeanName-" + mSystemId); 55 } 56 57 60 public void setBeanName(String beanName) { 61 mBeanName = beanName; 62 mInvocationRecords.add("setApplicationContext-" + mSystemId); 63 System.err.println("setApplicationContext-" + mSystemId); 64 } 65 66 public void destroy() { 67 synchronized(this) { mInvocationRecords.add("destroy-" + mSystemId); 69 } 70 } 71 72 public void closeAppCtx() { 73 ((AbstractApplicationContext)mAppCtx).close(); 74 } 75 76 public List getProp() { 77 return mProp; 78 } 79 80 public void setProp(List prop) { 81 mProp = prop; 82 } 83 } 84 | Popular Tags |