01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */
04: package com.tctest.spring.bean;
05:
06: import org.aopalliance.intercept.MethodInvocation;
07: import org.springframework.aop.support.DelegatingIntroductionInterceptor;
08:
09: public class CounterSaverMixin extends
10: 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 invoke(MethodInvocation invocation) throws Throwable {
23: String name = invocation.getMethod().getName();
24: if ("saveCounter".equals(name)) {
25: synchronized (this ) {
26: savedCounter = ((ISingleton) invocation.getThis())
27: .getCounter();
28: }
29: return null;
30: } else {
31: return super.invoke(invocation);
32: }
33: }
34:
35: }
|