1 16 17 package org.springframework.aop.aspectj; 18 19 import java.lang.reflect.Method ; 20 21 import org.aspectj.lang.JoinPoint; 22 import org.aspectj.lang.ProceedingJoinPoint; 23 import org.aspectj.lang.Signature; 24 import org.aspectj.lang.reflect.MethodSignature; 25 import org.aspectj.lang.reflect.SourceLocation; 26 import org.aspectj.runtime.internal.AroundClosure; 27 28 import org.springframework.aop.ProxyMethodInvocation; 29 import org.springframework.util.Assert; 30 31 48 public class MethodInvocationProceedingJoinPoint implements ProceedingJoinPoint, JoinPoint.StaticPart { 49 50 private final ProxyMethodInvocation methodInvocation; 51 52 private Object [] defensiveCopyOfArgs; 53 54 55 private Signature signature; 56 57 58 private SourceLocation sourceLocation; 59 60 61 66 public MethodInvocationProceedingJoinPoint(ProxyMethodInvocation methodInvocation) { 67 Assert.notNull(methodInvocation, "MethodInvocation must not be null"); 68 this.methodInvocation = methodInvocation; 69 } 70 71 public void set$AroundClosure(AroundClosure aroundClosure) { 72 throw new UnsupportedOperationException (); 73 } 74 75 public Object proceed() throws Throwable { 76 return this.methodInvocation.invocableClone().proceed(); 77 } 78 79 public Object proceed(Object [] arguments) throws Throwable { 80 return this.methodInvocation.invocableClone(arguments).proceed(); 81 } 82 83 86 public Object getThis() { 87 return this.methodInvocation.getProxy(); 88 } 89 90 93 public Object getTarget() { 94 return this.methodInvocation.getThis(); 95 } 96 97 public Object [] getArgs() { 98 if (this.defensiveCopyOfArgs == null) { 99 Object [] argsSource = this.methodInvocation.getArguments(); 100 this.defensiveCopyOfArgs = new Object [argsSource.length]; 101 System.arraycopy(argsSource, 0, this.defensiveCopyOfArgs, 0, argsSource.length); 102 } 103 return this.defensiveCopyOfArgs; 104 } 105 106 public Signature getSignature() { 107 if (this.signature == null) { 108 this.signature = new MethodSignatureImpl(); 109 } 110 return signature; 111 } 112 113 public SourceLocation getSourceLocation() { 114 if (this.sourceLocation == null) { 115 this.sourceLocation = new SourceLocationImpl(); 116 } 117 return this.sourceLocation; 118 } 119 120 public String getKind() { 121 return ProceedingJoinPoint.METHOD_EXECUTION; 122 } 123 124 public JoinPoint.StaticPart getStaticPart() { 125 return this; 126 } 127 128 129 public String toShortString() { 130 return "execution(" + this.methodInvocation.getMethod().getName() + ")"; 131 } 132 133 public String toLongString() { 134 return getClass().getName() + ": execution: [" + this.methodInvocation + "]"; 135 } 136 137 public String toString() { 138 return getClass().getName() + ": " + toShortString(); 139 } 140 141 142 145 private class MethodSignatureImpl implements Signature, MethodSignature { 146 147 public String toShortString() { 148 return methodInvocation.getMethod().getName(); 149 } 150 151 public String toLongString() { 152 return methodInvocation.getMethod().toString(); 153 } 154 155 public String getName() { 156 return methodInvocation.getMethod().getName(); 157 } 158 159 public int getModifiers() { 160 return methodInvocation.getMethod().getModifiers(); 161 } 162 163 public Class getDeclaringType() { 164 return methodInvocation.getMethod().getDeclaringClass(); 165 } 166 167 public String getDeclaringTypeName() { 168 return methodInvocation.getMethod().getDeclaringClass().getName(); 169 } 170 171 public Class getReturnType() { 172 return methodInvocation.getMethod().getReturnType(); 173 } 174 175 public Method getMethod() { 176 return methodInvocation.getMethod(); 177 } 178 179 public Class [] getParameterTypes() { 180 return methodInvocation.getMethod().getParameterTypes(); 181 } 182 183 public String [] getParameterNames() { 184 throw new UnsupportedOperationException ( 187 "Parameter names cannot be determined unless compiled by AspectJ compiler"); 188 } 189 190 public Class [] getExceptionTypes() { 191 return methodInvocation.getMethod().getExceptionTypes(); 192 } 193 } 194 195 196 199 private class SourceLocationImpl implements SourceLocation { 200 201 public Class getWithinType() { 202 if (methodInvocation.getThis() == null) { 203 throw new UnsupportedOperationException ("No source location joinpoint available: target is null"); 204 } 205 return methodInvocation.getThis().getClass(); 206 } 207 208 public String getFileName() { 209 throw new UnsupportedOperationException (); 210 } 211 212 public int getLine() { 213 throw new UnsupportedOperationException (); 214 } 215 216 public int getColumn() { 217 throw new UnsupportedOperationException (); 218 } 219 } 220 221 } 222 | Popular Tags |