KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > dynaop > observer > SubjectInterceptor


1 package dynaop.observer;
2
3 import java.io.Serializable JavaDoc;
4
5 import dynaop.Interceptor;
6 import dynaop.Invocation;
7
8 /**
9  * Notifies observers after the method invocation completes.
10  * Does not notify in the event of an exception.
11  * Use in conjunction with <code>SubjectMixin</code>.
12  *
13  * @author Bob Lee (crazybob@crazybob.org)
14  */

15 public class SubjectInterceptor implements Interceptor, Serializable JavaDoc {
16
17     private Object JavaDoc argument;
18     
19     public SubjectInterceptor() {
20     }
21     
22     public SubjectInterceptor(Object JavaDoc argument) {
23         this.argument = argument;
24     }
25     
26     /**
27      * Creates argument that should be passed to observers. Default
28      * implementation returns <code>null</code>.
29      */

30     protected Object JavaDoc createArgument(Subject subject,
31             Invocation invocation, Object JavaDoc result) {
32         return this.argument;
33     }
34
35     public Object JavaDoc intercept(Invocation invocation) throws Throwable JavaDoc {
36         Object JavaDoc result = invocation.proceed();
37         
38         Subject subject = (Subject) invocation.getProxy();
39         subject.notifyObservers(createArgument(subject, invocation, result));
40         
41         return result;
42     }
43 }
44
Popular Tags