1 /***************************************************************************************
2 * Copyright (c) Jonas Bonér, Alexandre Vasseur. All rights reserved. *
3 * http://aspectwerkz.codehaus.org *
4 * ---------------------------------------------------------------------------------- *
5 * The software in this package is published under the terms of the LGPL license *
6 * a copy of which has been included with this distribution in the license.txt file. *
7 **************************************************************************************/
8 package org.codehaus.aspectwerkz.joinpoint.management;
9
10 import org.codehaus.aspectwerkz.joinpoint.MethodSignature;
11 import org.codehaus.aspectwerkz.joinpoint.Rtti;
12 import org.codehaus.aspectwerkz.joinpoint.Signature;
13 import org.codehaus.aspectwerkz.joinpoint.impl.MethodRttiImpl;
14
15 /***
16 * Abstraction of a method join point.
17 *
18 * @author <a href="mailto:jboner@codehaus.org">Jonas Bonér </a>
19 */
20 class MethodJoinPoint extends JoinPointBase {
21 private MethodSignature m_signature;
22
23 private transient MethodRttiImpl m_rtti;
24
25 /***
26 * Creates a new join point.
27 *
28 * @param type
29 * @param targetClass
30 * @param signature
31 * @param rtti
32 * @param joinPointMetaData
33 * @param aroundAdviceExecutor
34 * @param beforeAdviceExecutor
35 * @param afterAdviceExecutor
36 */
37 public MethodJoinPoint(final int type,
38 final Class targetClass,
39 final Signature signature,
40 final Rtti rtti,
41 final JoinPointMetaData joinPointMetaData,
42 final AroundAdviceExecutor aroundAdviceExecutor,
43 final BeforeAdviceExecutor beforeAdviceExecutor,
44 final AfterAdviceExecutor afterAdviceExecutor) {
45 super(type, targetClass, joinPointMetaData, aroundAdviceExecutor, beforeAdviceExecutor, afterAdviceExecutor);
46 m_signature = (MethodSignature) signature;
47 m_rtti = (MethodRttiImpl) rtti;
48 }
49
50 /***
51 * Walks through the pointcuts and invokes all its advices. When the last advice of the last pointcut has been
52 * invoked, the original method is invoked. Is called recursively.
53 *
54 * @return the result from the next invocation
55 * @throws Throwable
56 */
57 public Object proceed() throws Throwable {
58 Object result = m_aroundAdviceExecutor.proceed(this);
59 m_rtti.setReturnValue(result);
60 return result;
61 }
62
63 /***
64 * Returns the signature for the join point.
65 *
66 * @return the signature
67 */
68 public Signature getSignature() {
69 return m_signature;
70 }
71
72 /***
73 * Returns the RTTI for the join point.
74 *
75 * @return the RTTI
76 */
77 public Rtti getRtti() {
78 return m_rtti;
79 }
80
81 /***
82 * Returns a string representation of the join puoint.
83 *
84 * @return a string representation
85 * @TODO: implement toString to something meaningful
86 */
87 public String toString() {
88 return super.toString();
89 }
90
91 public Object[] extractArguments(int[] methodToArgIndexes) {
92
93 if (methodToArgIndexes.length <= 0) {
94 return new Object[]{this};
95 }
96
97 Object[] args = new Object[methodToArgIndexes.length];
98 for (int i = 0; i < args.length; i++) {
99 int argIndex = methodToArgIndexes[i];
100 if (argIndex != -1) {
101 args[i] = m_rtti.getParameterValues()[argIndex];
102 } else {
103
104 args[i] = this;
105 }
106 }
107 return args;
108 }
109
110 /***
111 * Allows to pass the RTTI to the JP. The JPBase implementation delegates getTarget to the RTTI.
112 * Since in 1.0 engine, JP are cached and shared, while the RTTI is not, we need to set the RTTI (AW-265).
113 * This method MUST not be called by the user.
114 *
115 * @param rtti
116 */
117 protected void setRtti(Rtti rtti) {
118 m_rtti = (MethodRttiImpl)rtti;
119 }
120 }