1
2
3 package org.virtualmock.aspect.aspectwerkz;
4
5 import org.apache.log4j.Logger;
6 import org.codehaus.aspectwerkz.joinpoint.MethodJoinPoint;
7 import org.virtualmock.aspect.AspectUtils;
8 import org.virtualmock.call.InvokedCall;
9 import org.virtualmock.call.Signature;
10
11
12 /***
13 * This class implements behavior specific to Aspectwerkz.
14 *
15 * @author Chad Woolley
16 * @version $Revision: 1.18 $
17 */
18 public class AspectwerkzAspectUtils {
19 /*** Log4j logger. */
20 private static Logger logger =
21 Logger.getLogger(AspectwerkzAspectUtils.class.getName());
22 private AspectUtils aspectUtils = null;
23
24 /***
25 * Creates a new AspectwerkzAspectUtils object.
26 *
27 * @param aspectUtils an AspectUtils which will be used internally
28 */
29 public AspectwerkzAspectUtils(AspectUtils aspectUtils) {
30 super();
31 this.aspectUtils = aspectUtils;
32 }
33
34 /***
35 * Determines if the joinpoint defined by the specified Class and Method
36 * has been dynamically excluded.
37 *
38 * @param targetClass the target class for this JoinPoint
39 *
40 * @return true if excluded, false if not
41 *
42 * @todo Expose some API on VM to allow user to dynamically define multiple
43 * class exclusion patterns.
44 */
45 public boolean isJoinPointExcluded(Class targetClass) {
46 boolean isExcluded = aspectUtils.isClassExcluded(targetClass);
47
48 return isExcluded;
49 }
50
51 /***
52 * Uses information obtained from a MethodJoinPoint to build an array of
53 * argument values.
54 *
55 * @param methodJoinPoint the MethodJoinPoint from which to obtain the
56 * argument values
57 *
58 * @return the array of argument values
59 */
60 protected Object[] getArgValuesFromMethodJoinPoint(
61 MethodJoinPoint methodJoinPoint) {
62 Object[] argValues = methodJoinPoint.getParameters();
63
64 return argValues;
65 }
66
67 /***
68 * Uses information obtained from a MethodJoinPoint to build an
69 * InvokedCall.
70 *
71 * @param methodJoinPoint the MethodJoinPoint from which to obtain an
72 * InvokedCall
73 *
74 * @return an InvokedCall instance, created from the information in the
75 * methodJoinPoint
76 *
77 * @todo write unit test for this
78 */
79 protected InvokedCall getInvokedCallFromMethodJoinPoint(
80 MethodJoinPoint methodJoinPoint) {
81 Signature signature = getSignatureFromMethodJoinPoint(methodJoinPoint);
82 Object[] argValues = getArgValuesFromMethodJoinPoint(methodJoinPoint);
83
84 InvokedCall invokedCall = new InvokedCall(signature, argValues);
85
86 return invokedCall;
87 }
88
89 /***
90 * Uses information obtained from a MethodJoinPoint to build a Signature.
91 *
92 * @param methodJoinPoint the MethodJoinPoint from which to obtain a
93 * Signature
94 *
95 * @return a Signature
96 *
97 * @todo Write unit test for this
98 */
99 protected Signature getSignatureFromMethodJoinPoint(
100 MethodJoinPoint methodJoinPoint) {
101
102 Class returnType = methodJoinPoint.getReturnType();
103 Class classType = methodJoinPoint.getTargetClass();
104 String methodName = methodJoinPoint.getMethodName();
105 Class[] argTypes = methodJoinPoint.getParameterTypes();
106
107 if (logger.isDebugEnabled()) {
108 logger.debug("Creating signature with returnType=" + returnType
109 + ", classType = " + classType + ", methodName = "
110 + methodName + ", argTypes = " + argTypes);
111 }
112
113 Signature signature =
114 new Signature(returnType, classType, methodName, argTypes);
115
116 return signature;
117 }
118 }