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.annotation;
008:
009: import org.codehaus.aspectwerkz.definition.Pointcut;
010: import org.codehaus.aspectwerkz.definition.Pointcut;
011: import org.codehaus.aspectwerkz.joinpoint.JoinPoint;
012:
013: /**
014: * @author <a href="mailto:jboner@codehaus.org">Jonas BonŽr </a>
015: * @Aspect perJVM
016: */
017: public class TestAspect {
018: // ============ Pointcuts ============
019:
020: /**
021: * @Expression call(@AnnotationPrivateMethod * test.annotation.*.*(..)) &&
022: * within(test.annotation.*)
023: */
024: Pointcut call_privateMethod;
025:
026: /**
027: * @Expression execution(@AnnotationPrivateMethod * test.annotation.*.*(..))
028: */
029: Pointcut execution_privateMethod;
030:
031: /**
032: * @Expression call(@AnnotationProtectedMethod * test.annotation.*.*(..)) &&
033: * within(test.annotation.*)
034: */
035: Pointcut call_protectedMethod;
036:
037: /**
038: * @Expression execution(@AnnotationProtectedMethod * test.annotation.*.*(..))
039: */
040: Pointcut execution_protectedMethod;
041:
042: /**
043: * @Expression call(@AnnotationPackagePrivateMethod * test.annotation.*.*(..)) &&
044: * within(test.annotation.*)
045: */
046: Pointcut call_packagePrivateMethod;
047:
048: /**
049: * @Expression execution(@AnnotationPackagePrivateMethod * test.annotation.*.*(..))
050: */
051: Pointcut execution_packagePrivateMethod;
052:
053: /**
054: * @Expression call(@AnnotationPublicMethod * test.annotation.*.*(..)) &&
055: * within(test.annotation.*)
056: */
057: Pointcut call_publicMethod;
058:
059: /**
060: * @Expression execution(@AnnotationPublicMethod * test.annotation.*.*(..))
061: */
062: Pointcut execution_publicMethod;
063:
064: /**
065: * @Expression execution(@AnnotationPublicMethod2 * test.annotation.*.*(..))
066: */
067: Pointcut execution_publicMethod2;
068:
069: /**
070: * @Expression get(@AnnotationPrivateField * test.annotation.*.*) && within(test.annotation.*)
071: */
072: Pointcut get_privateField;
073:
074: /**
075: * @Expression set(@AnnotationPrivateField * test.annotation.*.*) && within(test.annotation.*)
076: */
077: Pointcut set_privateField;
078:
079: /**
080: * @Expression get(@AnnotationProtectedField * test.annotation.*.*) && within(test.annotation.*)
081: */
082: Pointcut get_protectedField;
083:
084: /**
085: * @Expression set(@AnnotationProtectedField * test.annotation.*.*) && within(test.annotation.*)
086: */
087: Pointcut set_protectedField;
088:
089: /**
090: * @Expression get(@AnnotationPackagePrivateField * test.annotation.*.*) && within(test.annotation.*)
091: */
092: Pointcut get_packagePrivateField;
093:
094: /**
095: * @Expression set(@AnnotationPackagePrivateField * test.annotation.*.*) && within(test.annotation.*)
096: */
097: Pointcut set_packagePrivateField;
098:
099: /**
100: * @Expression get(@AnnotationPublicField * test.annotation.*.*) && within(test.annotation.*)
101: */
102: Pointcut get_publicField;
103:
104: /**
105: * @Expression set(@AnnotationPublicField * test.annotation.*.*) && within(test.annotation.*)
106: */
107: Pointcut set_publicField;
108:
109: // ============ Advices ============
110:
111: /**
112: * @Around call_privateMethod || call_protectedMethod || call_packagePrivateMethod ||
113: * call_publicMethod
114: */
115: public Object advice_CALL(final JoinPoint joinPoint)
116: throws Throwable {
117: AnnotationTest.log("call ");
118: Object result = joinPoint.proceed();
119: AnnotationTest.log("call ");
120: return result;
121: }
122:
123: /**
124: * @Around execution_privateMethod || execution_protectedMethod ||
125: * execution_packagePrivateMethod || execution_publicMethod
126: */
127: public Object advice_EXECUTION(final JoinPoint joinPoint)
128: throws Throwable {
129: AnnotationTest.log("execution ");
130: Object result = joinPoint.proceed();
131: AnnotationTest.log("execution ");
132: return result;
133: }
134:
135: /**
136: * @Around execution_publicMethod2
137: */
138: public Object advice_EXECUTION2(final JoinPoint joinPoint)
139: throws Throwable {
140: AnnotationTest.log("execution2 ");
141: Object result = joinPoint.proceed();
142: AnnotationTest.log("execution2 ");
143: return result;
144: }
145:
146: /**
147: * @Around set_privateField || set_protectedField || set_packagePrivateField || set_publicField
148: */
149: public Object advice_SET(final JoinPoint joinPoint)
150: throws Throwable {
151: AnnotationTest.log("set ");
152: Object result = joinPoint.proceed();
153: AnnotationTest.log("set ");
154: return result;
155: }
156:
157: /**
158: * @Around get_privateField || get_protectedField || get_packagePrivateField || get_publicField
159: */
160: public Object advice_GET(final JoinPoint joinPoint)
161: throws Throwable {
162: AnnotationTest.log("get ");
163: Object result = joinPoint.proceed();
164: AnnotationTest.log("get ");
165: return result;
166: }
167: }
|