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