1 7 8 package org.jboss.cache.aop; 9 10 13 import org.jboss.aop.Advised; 14 import org.jboss.aop.InstanceAdvisor; 15 import org.jboss.aop.advice.Interceptor; 16 17 import java.io.NotSerializableException ; 18 import java.io.ObjectStreamException ; 19 20 23 24 public class WriteReplacer implements WriteReplaceable 25 { 26 27 52 54 Object obj; 55 56 public WriteReplacer(Object obj) 57 { 58 this.obj = obj; 59 } 60 61 public Object writeReplace() throws ObjectStreamException 62 { 63 if (obj instanceof Advised) { 64 InstanceAdvisor advisor = ((Advised) obj)._getInstanceAdvisor(); 65 org.jboss.aop.advice.Interceptor[] interceptors = advisor.getInterceptors(); 66 CacheInterceptor cacheInterceptor = null; 67 for (int i = 0; i < interceptors.length; i++) { 68 if (interceptors[i] instanceof CacheInterceptor) { 69 cacheInterceptor = (CacheInterceptor) interceptors[i]; 70 break; 71 } 72 } 73 if (cacheInterceptor != null) { 74 try { 75 cacheInterceptor.beforeSerialization(obj); 76 } catch (Exception e) { 77 e.printStackTrace(); 78 throw new NotSerializableException (e.getMessage()); 79 } 80 } 81 } 82 return obj; 83 } 84 85 } 86 | Popular Tags |