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.Pointcut; 024 025/** 026 * Convenient Pointcut-driven Advisor implementation. 027 * 028 * <p>This is the most commonly used Advisor implementation. It can be used 029 * with any pointcut and advice type, except for introductions. There is 030 * normally no need to subclass this class, or to implement custom Advisors. 031 * 032 * @author Rod Johnson 033 * @author Juergen Hoeller 034 * @see #setPointcut 035 * @see #setAdvice 036 */ 037@SuppressWarnings("serial") 038public class DefaultPointcutAdvisor extends AbstractGenericPointcutAdvisor implements Serializable { 039 040 private Pointcut pointcut = Pointcut.TRUE; 041 042 043 /** 044 * Create an empty DefaultPointcutAdvisor. 045 * <p>Advice must be set before use using setter methods. 046 * Pointcut will normally be set also, but defaults to {@code Pointcut.TRUE}. 047 */ 048 public DefaultPointcutAdvisor() { 049 } 050 051 /** 052 * Create a DefaultPointcutAdvisor that matches all methods. 053 * <p>{@code Pointcut.TRUE} will be used as Pointcut. 054 * @param advice the Advice to use 055 */ 056 public DefaultPointcutAdvisor(Advice advice) { 057 this(Pointcut.TRUE, advice); 058 } 059 060 /** 061 * Create a DefaultPointcutAdvisor, specifying Pointcut and Advice. 062 * @param pointcut the Pointcut targeting the Advice 063 * @param advice the Advice to run when Pointcut matches 064 */ 065 public DefaultPointcutAdvisor(Pointcut pointcut, Advice advice) { 066 this.pointcut = pointcut; 067 setAdvice(advice); 068 } 069 070 071 /** 072 * Specify the pointcut targeting the advice. 073 * <p>Default is {@code Pointcut.TRUE}. 074 * @see #setAdvice 075 */ 076 public void setPointcut(Pointcut pointcut) { 077 this.pointcut = (pointcut != null ? pointcut : Pointcut.TRUE); 078 } 079 080 @Override 081 public Pointcut getPointcut() { 082 return this.pointcut; 083 } 084 085 086 @Override 087 public String toString() { 088 return getClass().getName() + ": pointcut [" + getPointcut() + "]; advice [" + getAdvice() + "]"; 089 } 090 091}