1 22 package org.jboss.aspects.patterns.observable; 23 24 import org.jboss.aop.advice.Interceptor; 25 import org.jboss.aop.joinpoint.FieldInvocation; 26 import org.jboss.aop.joinpoint.Invocation; 27 28 35 public class SubjectInterceptor implements Interceptor 36 { 37 public String getName() 38 { 39 return "Observerable"; 40 } 41 42 public Object invoke(Invocation invocation) throws Throwable 43 { 44 FieldInvocation fi = (FieldInvocation) invocation; 45 Object before = fi.getField().get(fi.getTargetObject()); 46 Object result = invocation.invokeNext(); 47 Object after = fi.getField().get(fi.getTargetObject()); 48 if ((before == null && after != null) || (before != null && before.equals(after) == false)) 49 { 50 Subject observable = (Subject) fi.getTargetObject(); 51 observable.notifyObservers(); 52 } 53 return result; 54 } 55 } 56 | Popular Tags |