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