001/* 002 * Copyright 2002-2017 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * https://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.aop.aspectj; 018 019import org.aopalliance.aop.Advice; 020 021import org.springframework.aop.Pointcut; 022import org.springframework.aop.PointcutAdvisor; 023import org.springframework.core.Ordered; 024import org.springframework.util.Assert; 025 026/** 027 * AspectJPointcutAdvisor that adapts an {@link AbstractAspectJAdvice} 028 * to the {@link org.springframework.aop.PointcutAdvisor} interface. 029 * 030 * @author Adrian Colyer 031 * @author Juergen Hoeller 032 * @since 2.0 033 */ 034public class AspectJPointcutAdvisor implements PointcutAdvisor, Ordered { 035 036 private final AbstractAspectJAdvice advice; 037 038 private final Pointcut pointcut; 039 040 private Integer order; 041 042 043 /** 044 * Create a new AspectJPointcutAdvisor for the given advice 045 * @param advice the AbstractAspectJAdvice to wrap 046 */ 047 public AspectJPointcutAdvisor(AbstractAspectJAdvice advice) { 048 Assert.notNull(advice, "Advice must not be null"); 049 this.advice = advice; 050 this.pointcut = advice.buildSafePointcut(); 051 } 052 053 054 public void setOrder(int order) { 055 this.order = order; 056 } 057 058 @Override 059 public boolean isPerInstance() { 060 return true; 061 } 062 063 @Override 064 public Advice getAdvice() { 065 return this.advice; 066 } 067 068 @Override 069 public Pointcut getPointcut() { 070 return this.pointcut; 071 } 072 073 @Override 074 public int getOrder() { 075 if (this.order != null) { 076 return this.order; 077 } 078 else { 079 return this.advice.getOrder(); 080 } 081 } 082 083 084 @Override 085 public boolean equals(Object other) { 086 if (this == other) { 087 return true; 088 } 089 if (!(other instanceof AspectJPointcutAdvisor)) { 090 return false; 091 } 092 AspectJPointcutAdvisor otherAdvisor = (AspectJPointcutAdvisor) other; 093 return this.advice.equals(otherAdvisor.advice); 094 } 095 096 @Override 097 public int hashCode() { 098 return AspectJPointcutAdvisor.class.hashCode() * 29 + this.advice.hashCode(); 099 } 100 101}