KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > aop > aspectj > AspectJAopUtils


1 /*
2  * Copyright 2002-2007 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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(Advisor anAdvisor) {
62         if (anAdvisor instanceof AspectJPrecedenceInformation) {
63             return (AspectJPrecedenceInformation) anAdvisor;
64         }
65         Advice advice = anAdvisor.getAdvice();
66         if (advice instanceof AspectJPrecedenceInformation) {
67             return (AspectJPrecedenceInformation) advice;
68         }
69         return null;
70     }
71
72 }
73
Popular Tags