KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tctest > spring > bean > CounterSaverMixin


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package com.tctest.spring.bean;
5
6 import org.aopalliance.intercept.MethodInvocation;
7 import org.springframework.aop.support.DelegatingIntroductionInterceptor;
8
9
10 public class CounterSaverMixin extends DelegatingIntroductionInterceptor implements CounterSaver {
11
12   private int savedCounter;
13
14   synchronized public void saveCounter() {
15     // counter is being saved by invoke() method
16
}
17   
18   public int getSavedCounter() {
19     return savedCounter;
20   }
21   
22   public Object JavaDoc invoke(MethodInvocation invocation) throws Throwable JavaDoc {
23       String JavaDoc name = invocation.getMethod().getName();
24       if ("saveCounter".equals(name)) {
25         synchronized(this) {
26           savedCounter = ((ISingleton) invocation.getThis()).getCounter();
27         }
28         return null;
29       } else {
30         return super.invoke(invocation);
31       }
32   }
33
34 }
35
36
Popular Tags