001: /**************************************************************************************
002: * Copyright (c) Jonas BonŽr, Alexandre Vasseur. All rights reserved. *
003: * http://aspectwerkz.codehaus.org *
004: * ---------------------------------------------------------------------------------- *
005: * The software in this package is published under the terms of the LGPL license *
006: * a copy of which has been included with this distribution in the license.txt file. *
007: **************************************************************************************/package test.aspect;
008:
009: import test.StaticMethodAdviceTest;
010: import org.codehaus.aspectwerkz.definition.Pointcut;
011: import org.codehaus.aspectwerkz.definition.Pointcut;
012: import org.codehaus.aspectwerkz.joinpoint.JoinPoint;
013: import org.codehaus.aspectwerkz.joinpoint.MethodRtti;
014: import org.codehaus.aspectwerkz.joinpoint.Rtti;
015:
016: /**
017: * @author <a href="mailto:jboner@codehaus.org">Jonas BonŽr </a>
018: * @Aspect perJVM
019: */
020: public class StaticMethodTestAspect {
021: // ============ Pointcuts ============
022:
023: /**
024: * @Expression call(* test.StaticMethodAdviceTest.get*(..)) && within(test.StaticMethodAdviceTest)
025: */
026: Pointcut static_pc1;
027:
028: /**
029: * @Expression execution(* test.StaticMethodAdviceTest.*Param*(..))
030: */
031: Pointcut static_pc2;
032:
033: /**
034: * @Expression call(void test.StaticMethodAdviceTest.methodAdvicedMethod(..)) && within(test.StaticMethodAdviceTest)
035: */
036: Pointcut static_pc4;
037:
038: /**
039: * @Expression execution(* test.StaticMethodAdviceTest.methodAdvicedMethod(..))
040: */
041: Pointcut static_pc5;
042:
043: /**
044: * @Expression call(* test.StaticMethodAdviceTest.methodAdvicedMethodNewThread(..)) && within(test.StaticMethodAdviceTest)
045: */
046: Pointcut static_pc6;
047:
048: /**
049: * @Expression execution(* test.StaticMethodAdviceTest.multipleMethodAdvicedMethod(..))
050: */
051: Pointcut static_pc7;
052:
053: /**
054: * @Expression call(* test.StaticMethodAdviceTest.multipleChainedMethodAdvicedMethod(..)) && within(test.StaticMethodAdviceTest)
055: */
056: Pointcut static_pc8;
057:
058: /**
059: * @Expression execution(* test.StaticMethodAdviceTest.joinPointMetaData(..))
060: */
061: Pointcut static_pc9;
062:
063: /**
064: * @Expression call(void test.StaticMethodAdviceTest.multiplePointcutsMethod(..)) && within(test.StaticMethodAdviceTest)
065: */
066: Pointcut static_pc10;
067:
068: /**
069: * @Expression execution(void test.StaticMethodAdviceTest.multiplePointcutsMethod(..))
070: */
071: Pointcut static_pc11;
072:
073: /**
074: * @Expression call(* test.StaticMethodAdviceTest.takesArrayAsArgument(String[])) && within(test.StaticMethodAdviceTest)
075: */
076: Pointcut static_pc12;
077:
078: /**
079: * @Expression execution(long test.StaticMethodAdviceTest.getPrimitiveAndNullFromAdvice())
080: */
081: Pointcut static_pc13;
082:
083: // ============ Advices ============
084:
085: /**
086: * @Before static_pc1 || static_pc2 || static_pc5 || static_pc8 || static_pc12
087: */
088: public void before(final JoinPoint joinPoint) throws Throwable {
089: }
090:
091: /**
092: * @AfterFinally static_pc1 || static_pc2 || static_pc5 || static_pc8 || static_pc12
093: */
094: public void afterFinally(final JoinPoint joinPoint)
095: throws Throwable {
096: }
097:
098: /**
099: * @Around static_pc1 || static_pc2 || static_pc5 || static_pc8 || static_pc12
100: */
101: public Object advice1(final JoinPoint joinPoint) throws Throwable {
102: return joinPoint.proceed();
103: }
104:
105: /**
106: * @Around static_pc4 || static_pc7 || static_pc8 || static_pc10
107: */
108: public Object advice2(final JoinPoint joinPoint) throws Throwable {
109: StaticMethodAdviceTest.log("before1 ");
110: final Object result = joinPoint.proceed();
111: StaticMethodAdviceTest.log("after1 ");
112: return result;
113: }
114:
115: /**
116: * @Around static_pc7 || static_pc8 || static_pc11
117: */
118: public Object advice3(final JoinPoint joinPoint) throws Throwable {
119: StaticMethodAdviceTest.log("before2 ");
120: final Object result = joinPoint.proceed();
121: StaticMethodAdviceTest.log("after2 ");
122: return result;
123: }
124:
125: /**
126: * @Around static_pc9
127: */
128: public Object advice4(final JoinPoint joinPoint) throws Throwable {
129: final Object result = joinPoint.proceed();
130: MethodRtti mrtti = (MethodRtti) joinPoint.getRtti();
131: String metadata = joinPoint.getCalleeClass().getName()
132: + mrtti.getMethod().getName()
133: + mrtti.getParameterValues()[0]
134: + mrtti.getParameterTypes()[0].getName()
135: + mrtti.getReturnType().getName()
136: + mrtti.getReturnValue();
137: return metadata;
138: }
139:
140: /**
141: * @Around static_pc6
142: */
143: public Object advice5(final JoinPoint joinPoint) throws Throwable {
144: StaticMethodAdviceTest.log("before ");
145: final Object result = joinPoint.proceed();
146: StaticMethodAdviceTest.log("after ");
147: return result;
148: }
149:
150: /**
151: * @Around static_pc13
152: */
153: public Object advice7(final JoinPoint joinPoint) throws Throwable {
154: return null;
155: }
156: }
|