01: /*
02: * Copyright 2002-2007 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: package org.springframework.aop.aspectj;
18:
19: import org.aopalliance.aop.Advice;
20:
21: import org.springframework.aop.Advisor;
22: import org.springframework.aop.AfterAdvice;
23: import org.springframework.aop.BeforeAdvice;
24:
25: /**
26: * Utility methods for dealing with AspectJ advisors.
27: *
28: * @author Adrian Colyer
29: * @author Juergen Hoeller
30: * @since 2.0
31: */
32: public abstract class AspectJAopUtils {
33:
34: /**
35: * Return <code>true</code> if the advisor is a form of before advice.
36: */
37: public static boolean isBeforeAdvice(Advisor anAdvisor) {
38: AspectJPrecedenceInformation precedenceInfo = getAspectJPrecedenceInformationFor(anAdvisor);
39: if (precedenceInfo != null) {
40: return precedenceInfo.isBeforeAdvice();
41: }
42: return (anAdvisor.getAdvice() instanceof BeforeAdvice);
43: }
44:
45: /**
46: * Return <code>true</code> if the advisor is a form of after advice.
47: */
48: public static boolean isAfterAdvice(Advisor anAdvisor) {
49: AspectJPrecedenceInformation precedenceInfo = getAspectJPrecedenceInformationFor(anAdvisor);
50: if (precedenceInfo != null) {
51: return precedenceInfo.isAfterAdvice();
52: }
53: return (anAdvisor.getAdvice() instanceof AfterAdvice);
54: }
55:
56: /**
57: * Return the AspectJPrecedenceInformation provided by this advisor or its advice.
58: * If neither the advisor nor the advice have precedence information, this method
59: * will return <code>null</code>.
60: */
61: public static AspectJPrecedenceInformation getAspectJPrecedenceInformationFor(
62: Advisor anAdvisor) {
63: if (anAdvisor instanceof AspectJPrecedenceInformation) {
64: return (AspectJPrecedenceInformation) anAdvisor;
65: }
66: Advice advice = anAdvisor.getAdvice();
67: if (advice instanceof AspectJPrecedenceInformation) {
68: return (AspectJPrecedenceInformation) advice;
69: }
70: return null;
71: }
72:
73: }
|