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.ConstructorSignature;
11 import org.codehaus.aspectwerkz.joinpoint.Rtti;
12 import org.codehaus.aspectwerkz.joinpoint.Signature;
13 import org.codehaus.aspectwerkz.joinpoint.impl.ConstructorRttiImpl;
14
15 /***
16 * Abstraction of a constructor join point.
17 *
18 * @author <a href="mailto:jboner@codehaus.org">Jonas Bonér </a>
19 */
20 class ConstructorJoinPoint extends JoinPointBase {
21 private final ConstructorSignature m_signature;
22
23 private transient ConstructorRttiImpl m_rtti;
24
25 /***
26 * Creates a new constructor 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 ConstructorJoinPoint(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 = (ConstructorSignature) signature;
47 m_rtti = (ConstructorRttiImpl) 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 final Object result = m_aroundAdviceExecutor.proceed(this);
59 m_rtti.setNewInstance(result);
60 this.getRtti().cloneFor(result, this.getRtti().getThis());
61 return result;
62 }
63
64 /***
65 * Returns the signature for the join point.
66 *
67 * @return the signature
68 */
69 public Signature getSignature() {
70 return m_signature;
71 }
72
73 /***
74 * Returns the RTTI for the join point.
75 *
76 * @return the RTTI
77 */
78 public Rtti getRtti() {
79 return m_rtti;
80 }
81
82 /***
83 * Returns a string representation of the join point.
84 *
85 * @return a string representation
86 * @TODO: implement toString to something meaningful
87 */
88 public String toString() {
89 return super.toString();
90 }
91
92 public Object[] extractArguments(int[] methodToArgIndexes) {
93
94 if (methodToArgIndexes.length <= 0) {
95 return new Object[]{this};
96 }
97
98 Object[] args = new Object[methodToArgIndexes.length];
99 for (int i = 0; i < args.length; i++) {
100 int argIndex = methodToArgIndexes[i];
101 if (argIndex != -1) {
102 args[i] = m_rtti.getParameterValues()[argIndex];
103 } else {
104
105 args[i] = this;
106 }
107 }
108 return args;
109 }
110
111 /***
112 * Allows to pass the RTTI to the JP. The JPBase implementation delegates getTarget to the RTTI.
113 * Since in 1.0 engine, JP are cached and shared, while the RTTI is not, we need to set the RTTI (AW-265).
114 * This method MUST not be called by the user.
115 *
116 * @param rtti
117 */
118 protected void setRtti(Rtti rtti) {
119 m_rtti = (ConstructorRttiImpl)rtti;
120 }
121
122 }