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.AdviceInfo;
11
12 import java.io.Serializable;
13
14 /***
15 * Handles the execution of the after advices.
16 *
17 * @author <a href="mailto:jboner@codehaus.org">Jonas Bonér </a>
18 * @author <a href="mailto:alex@gnilux.com">Alexandre Vasseur </a>
19 */
20 public class AfterAdviceExecutor implements Serializable {
21 /***
22 * The advices indexes.
23 */
24 private final AdviceInfo[] m_adviceIndexes;
25
26 /***
27 * Creates a new advice executor.
28 *
29 * @param adviceIndexes
30 */
31 public AfterAdviceExecutor(final AdviceInfo[] adviceIndexes) {
32 m_adviceIndexes = adviceIndexes;
33 }
34
35 /***
36 * Executes its advices one by one. After the last advice has been executed, the original method is invoked.
37 *
38 * @param joinPoint the current join point
39 * @return null
40 */
41 public Object proceed(final JoinPointBase joinPoint) throws Throwable {
42 if (!joinPoint.isInCflow()) {
43 return null;
44 }
45 for (int i = m_adviceIndexes.length - 1; i >= 0; i--) {
46 AdviceInfo index = m_adviceIndexes[i];
47 int aspectIndex = index.getAspectIndex();
48 int methodIndex = index.getMethodIndex();
49 index.getAspectManager().getAspectContainer(aspectIndex).invokeAdvice(methodIndex, joinPoint, index.getMethodToArgIndexes());
50 }
51 return null;
52 }
53
54 /***
55 * Checks if the executor has any advices.
56 *
57 * @return true if it has advices
58 */
59 public boolean hasAdvices() {
60 return m_adviceIndexes.length != 0;
61 }
62 }