|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| package org.acegisecurity.intercept.method; |
|
17 |
| |
|
18 |
| import org.acegisecurity.ConfigAttributeDefinition; |
|
19 |
| |
|
20 |
| import org.aopalliance.intercept.MethodInvocation; |
|
21 |
| |
|
22 |
| import org.apache.commons.logging.Log; |
|
23 |
| import org.apache.commons.logging.LogFactory; |
|
24 |
| |
|
25 |
| import org.aspectj.lang.JoinPoint; |
|
26 |
| import org.aspectj.lang.reflect.CodeSignature; |
|
27 |
| import org.springframework.util.Assert; |
|
28 |
| |
|
29 |
| import java.lang.reflect.Method; |
|
30 |
| |
|
31 |
| |
|
32 |
| |
|
33 |
| |
|
34 |
| |
|
35 |
| |
|
36 |
| |
|
37 |
| |
|
38 |
| public abstract class AbstractMethodDefinitionSource |
|
39 |
| implements MethodDefinitionSource { |
|
40 |
| |
|
41 |
| |
|
42 |
| private static final Log logger = LogFactory.getLog(AbstractMethodDefinitionSource.class); |
|
43 |
| |
|
44 |
| |
|
45 |
| |
|
46 |
36
| public ConfigAttributeDefinition getAttributes(Object object)
|
|
47 |
| throws IllegalArgumentException { |
|
48 |
36
| Assert.notNull(object, "Object cannot be null");
|
|
49 |
| |
|
50 |
35
| if (object instanceof MethodInvocation) {
|
|
51 |
31
| return this.lookupAttributes(((MethodInvocation) object).getMethod());
|
|
52 |
| } |
|
53 |
| |
|
54 |
4
| if (object instanceof JoinPoint) {
|
|
55 |
3
| JoinPoint jp = (JoinPoint) object;
|
|
56 |
3
| Class targetClazz = jp.getTarget().getClass();
|
|
57 |
3
| String targetMethodName = jp.getStaticPart().getSignature().getName();
|
|
58 |
3
| Class[] types = ((CodeSignature) jp.getStaticPart().getSignature())
|
|
59 |
| .getParameterTypes(); |
|
60 |
| |
|
61 |
3
| if (logger.isDebugEnabled()) {
|
|
62 |
0
| logger.debug("Target Class: " + targetClazz);
|
|
63 |
0
| logger.debug("Target Method Name: " + targetMethodName);
|
|
64 |
| |
|
65 |
0
| for (int i = 0; i < types.length; i++) {
|
|
66 |
0
| if (logger.isDebugEnabled()) {
|
|
67 |
0
| logger.debug("Target Method Arg #" + i + ": "
|
|
68 |
| + types[i]); |
|
69 |
| } |
|
70 |
| } |
|
71 |
| } |
|
72 |
| |
|
73 |
3
| try {
|
|
74 |
3
| return this.lookupAttributes(targetClazz.getMethod(targetMethodName, types));
|
|
75 |
| } catch (NoSuchMethodException nsme) { |
|
76 |
0
| throw new IllegalArgumentException("Could not obtain target method from JoinPoint: " + jp);
|
|
77 |
| } |
|
78 |
| } |
|
79 |
| |
|
80 |
1
| throw new IllegalArgumentException("Object must be a MethodInvocation or JoinPoint");
|
|
81 |
| } |
|
82 |
| |
|
83 |
21
| public boolean supports(Class clazz) {
|
|
84 |
21
| return (MethodInvocation.class.isAssignableFrom(clazz)
|
|
85 |
| || JoinPoint.class.isAssignableFrom(clazz)); |
|
86 |
| } |
|
87 |
| |
|
88 |
| |
|
89 |
| |
|
90 |
| |
|
91 |
| |
|
92 |
| |
|
93 |
| |
|
94 |
| |
|
95 |
| |
|
96 |
| |
|
97 |
| |
|
98 |
| |
|
99 |
| |
|
100 |
| |
|
101 |
| |
|
102 |
| |
|
103 |
| |
|
104 |
| |
|
105 |
| |
|
106 |
| |
|
107 |
| |
|
108 |
| |
|
109 |
| protected abstract ConfigAttributeDefinition lookupAttributes(Method method); |
|
110 |
| } |