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.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 order;
42:
43: /**
44: * Create a new AspectJPointcutAdvisor for the given advice
45: * @param advice the AbstractAspectJAdvice to wrap
46: */
47: public AspectJPointcutAdvisor(AbstractAspectJAdvice advice) {
48: Assert.notNull(advice, "Advice must not be null");
49: this .advice = advice;
50: this .pointcut = advice.buildSafePointcut();
51: }
52:
53: public void setOrder(int order) {
54: this .order = new Integer(order);
55: }
56:
57: public boolean isPerInstance() {
58: return true;
59: }
60:
61: public Advice getAdvice() {
62: return this .advice;
63: }
64:
65: public Pointcut getPointcut() {
66: return this .pointcut;
67: }
68:
69: public int getOrder() {
70: if (this .order != null) {
71: return this .order.intValue();
72: } else {
73: return this .advice.getOrder();
74: }
75: }
76:
77: public boolean equals(Object other) {
78: if (this == other) {
79: return true;
80: }
81: if (!(other instanceof AspectJPointcutAdvisor)) {
82: return false;
83: }
84: AspectJPointcutAdvisor otherAdvisor = (AspectJPointcutAdvisor) other;
85: return (ObjectUtils.nullSafeEquals(this .advice,
86: otherAdvisor.advice));
87: }
88:
89: public int hashCode() {
90: return AspectJPointcutAdvisor.class.hashCode();
91: }
92:
93: }
|