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 org.springframework.aop.Pointcut;
020import org.springframework.lang.Nullable;
021
022/**
023 * Concrete BeanFactory-based PointcutAdvisor that allows for any Advice
024 * to be configured as reference to an Advice bean in the BeanFactory,
025 * as well as the Pointcut to be configured through a bean property.
026 *
027 * <p>Specifying the name of an advice bean instead of the advice object itself
028 * (if running within a BeanFactory) increases loose coupling at initialization time,
029 * in order to not initialize the advice object until the pointcut actually matches.
030 *
031 * @author Juergen Hoeller
032 * @since 2.0.2
033 * @see #setPointcut
034 * @see #setAdviceBeanName
035 */
036@SuppressWarnings("serial")
037public class DefaultBeanFactoryPointcutAdvisor extends AbstractBeanFactoryPointcutAdvisor {
038
039        private Pointcut pointcut = Pointcut.TRUE;
040
041
042        /**
043         * Specify the pointcut targeting the advice.
044         * <p>Default is {@code Pointcut.TRUE}.
045         * @see #setAdviceBeanName
046         */
047        public void setPointcut(@Nullable Pointcut pointcut) {
048                this.pointcut = (pointcut != null ? pointcut : Pointcut.TRUE);
049        }
050
051        @Override
052        public Pointcut getPointcut() {
053                return this.pointcut;
054        }
055
056
057        @Override
058        public String toString() {
059                return getClass().getName() + ": pointcut [" + getPointcut() + "]; advice bean '" + getAdviceBeanName() + "'";
060        }
061
062}