KickJava   Java API By Example, From Geeks To Geeks.

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


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.Pointcut;
22 import org.springframework.aop.PointcutAdvisor;
23 import org.springframework.core.Ordered;
24 import org.springframework.util.Assert;
25 import org.springframework.util.ObjectUtils;
26
27 /**
28  * AspectJPointcutAdvisor that adapts an {@link AbstractAspectJAdvice}
29  * to the {@link org.springframework.aop.PointcutAdvisor} interface.
30  *
31  * @author Adrian Colyer
32  * @author Juergen Hoeller
33  * @since 2.0
34  */

35 public class AspectJPointcutAdvisor implements PointcutAdvisor, Ordered {
36
37     private final AbstractAspectJAdvice advice;
38
39     private final Pointcut pointcut;
40
41     private Integer JavaDoc order;
42
43
44     /**
45      * Create a new AspectJPointcutAdvisor for the given advice
46      * @param advice the AbstractAspectJAdvice to wrap
47      */

48     public AspectJPointcutAdvisor(AbstractAspectJAdvice advice) {
49         Assert.notNull(advice, "Advice must not be null");
50         this.advice = advice;
51         this.pointcut = advice.buildSafePointcut();
52     }
53
54     public void setOrder(int order) {
55         this.order = new Integer JavaDoc(order);
56     }
57
58
59     public boolean isPerInstance() {
60         return true;
61     }
62
63     public Advice getAdvice() {
64         return this.advice;
65     }
66
67     public Pointcut getPointcut() {
68         return this.pointcut;
69     }
70
71     public int getOrder() {
72         if (this.order != null) {
73             return this.order.intValue();
74         }
75         else {
76             return this.advice.getOrder();
77         }
78     }
79
80
81     public boolean equals(Object JavaDoc other) {
82         if (this == other) {
83             return true;
84         }
85         if (!(other instanceof AspectJPointcutAdvisor)) {
86             return false;
87         }
88         AspectJPointcutAdvisor otherAdvisor = (AspectJPointcutAdvisor) other;
89         return (ObjectUtils.nullSafeEquals(this.advice, otherAdvisor.advice));
90     }
91
92     public int hashCode() {
93         return AspectJPointcutAdvisor.class.hashCode();
94     }
95
96 }
97
Popular Tags