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.support; 018 019import java.io.Serializable; 020 021import org.aopalliance.aop.Advice; 022 023import org.springframework.aop.PointcutAdvisor; 024import org.springframework.core.Ordered; 025import org.springframework.lang.Nullable; 026import org.springframework.util.ObjectUtils; 027 028/** 029 * Abstract base class for {@link org.springframework.aop.PointcutAdvisor} 030 * implementations. Can be subclassed for returning a specific pointcut/advice 031 * or a freely configurable pointcut/advice. 032 * 033 * @author Rod Johnson 034 * @author Juergen Hoeller 035 * @since 1.1.2 036 * @see AbstractGenericPointcutAdvisor 037 */ 038@SuppressWarnings("serial") 039public abstract class AbstractPointcutAdvisor implements PointcutAdvisor, Ordered, Serializable { 040 041 @Nullable 042 private Integer order; 043 044 045 public void setOrder(int order) { 046 this.order = order; 047 } 048 049 @Override 050 public int getOrder() { 051 if (this.order != null) { 052 return this.order; 053 } 054 Advice advice = getAdvice(); 055 if (advice instanceof Ordered) { 056 return ((Ordered) advice).getOrder(); 057 } 058 return Ordered.LOWEST_PRECEDENCE; 059 } 060 061 @Override 062 public boolean isPerInstance() { 063 return true; 064 } 065 066 067 @Override 068 public boolean equals(@Nullable Object other) { 069 if (this == other) { 070 return true; 071 } 072 if (!(other instanceof PointcutAdvisor)) { 073 return false; 074 } 075 PointcutAdvisor otherAdvisor = (PointcutAdvisor) other; 076 return (ObjectUtils.nullSafeEquals(getAdvice(), otherAdvisor.getAdvice()) && 077 ObjectUtils.nullSafeEquals(getPointcut(), otherAdvisor.getPointcut())); 078 } 079 080 @Override 081 public int hashCode() { 082 return PointcutAdvisor.class.hashCode(); 083 } 084 085}