KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * Copyright 2002-2006 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 java.util.Iterator JavaDoc;
20 import java.util.List JavaDoc;
21
22 import org.springframework.aop.Advisor;
23 import org.springframework.aop.interceptor.ExposeInvocationInterceptor;
24
25 /**
26  * Utility methods for working with AspectJ proxies.
27  *
28  * @author Rod Johnson
29  * @since 2.0
30  */

31 public abstract class AspectJProxyUtils {
32     
33     /**
34      * Add special advisors if necessary to work with a proxy chain that contains AspectJ advisors.
35      * This will expose the current Spring AOP invocation (necessary for some AspectJ pointcut matching)
36      * and make available the current AspectJ JoinPoint. The call will have no effect if there are no
37      * AspectJ advisors in the advisor chain.
38      * @param advisors Advisors available
39      * @return <code>true</code> if any special {@link Advisor Advisors} were added, otherwise <code>false</code>.
40      */

41     public static boolean makeAdvisorChainAspectJCapableIfNecessary(List JavaDoc advisors) {
42         // Don't add advisors to an empty list; may indicate that proxying is just not required
43
if (!advisors.isEmpty()) {
44             boolean foundAspectJAdvice = false;
45             for (Iterator JavaDoc it = advisors.iterator(); it.hasNext() && !foundAspectJAdvice; ) {
46                 Advisor advisor = (Advisor) it.next();
47                 // Be careful not to get the Advice without a guard, as
48
// this might eagerly instantiate a non-singleton AspectJ aspect
49
if (advisor instanceof InstantiationModelAwarePointcutAdvisor ||
50                         advisor.getAdvice() instanceof AbstractAspectJAdvice) {
51                     foundAspectJAdvice = true;
52                 }
53             }
54             if (foundAspectJAdvice && !advisors.contains(ExposeInvocationInterceptor.ADVISOR)) {
55                 advisors.add(0, ExposeInvocationInterceptor.ADVISOR);
56                 return true;
57             }
58         }
59         return false;
60     }
61
62 }
63
Popular Tags