1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package net.sf.oness.common.model.dao;
17
18 import java.io.Serializable;
19 import java.lang.reflect.Method;
20
21 import net.sf.oness.common.model.bo.AuditableBusinessObject;
22
23 import org.aopalliance.intercept.MethodInterceptor;
24 import org.aopalliance.intercept.MethodInvocation;
25 import org.springframework.aop.support.StaticMethodMatcherPointcutAdvisor;
26
27 /***
28 * AOP Advisor implementing an auditing DAO
29 *
30 * @author Carlos Sanchez
31 * @version $Revision: 1.3 $
32 */
33 public class AuditableDaoAdvisor extends StaticMethodMatcherPointcutAdvisor
34 implements MethodInterceptor {
35
36 public AuditableDaoAdvisor() {
37 super();
38 setAdvice(this);
39 }
40
41 /***
42 * @see org.aopalliance.intercept.MethodInterceptor#invoke(org.aopalliance.intercept.MethodInvocation)
43 */
44 public Object invoke(MethodInvocation invocation) throws Throwable {
45 String name = invocation.getMethod().getName();
46 AuditableDao dao = (AuditableDao) invocation.getThis();
47
48
49 if (name.equals("create"))
50 return AuditingDaoHelper.create(dao,
51 (AuditableBusinessObject) invocation.getArguments()[0]);
52
53
54 if (name.equals("update"))
55 return AuditingDaoHelper.update(dao,
56 (AuditableBusinessObject) invocation.getArguments()[0]);
57
58
59 if (name.equals("delete")) {
60 AuditingDaoHelper.delete(dao, (Serializable) invocation
61 .getArguments()[0]);
62 return null;
63 }
64
65
66 return invocation.proceed();
67 }
68
69 /***
70 * @see org.springframework.aop.MethodMatcher#matches(java.lang.reflect.Method,
71 * java.lang.Class)
72 */
73 public boolean matches(Method m, Class targetClass) {
74 return AuditableDao.class.isAssignableFrom(targetClass);
75 }
76
77 }