001/*
002 * Copyright 2002-2014 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.aopalliance.aop.Advice;
020
021import org.springframework.aop.ClassFilter;
022import org.springframework.aop.Pointcut;
023
024/**
025 * Convenient class for name-match method pointcuts that hold an Advice,
026 * making them an Advisor.
027 *
028 * @author Juergen Hoeller
029 * @author Rob Harrop
030 * @see NameMatchMethodPointcut
031 */
032@SuppressWarnings("serial")
033public class NameMatchMethodPointcutAdvisor extends AbstractGenericPointcutAdvisor {
034
035        private final NameMatchMethodPointcut pointcut = new NameMatchMethodPointcut();
036
037
038        public NameMatchMethodPointcutAdvisor() {
039        }
040
041        public NameMatchMethodPointcutAdvisor(Advice advice) {
042                setAdvice(advice);
043        }
044
045
046        /**
047         * Set the {@link ClassFilter} to use for this pointcut.
048         * Default is {@link ClassFilter#TRUE}.
049         * @see NameMatchMethodPointcut#setClassFilter
050         */
051        public void setClassFilter(ClassFilter classFilter) {
052                this.pointcut.setClassFilter(classFilter);
053        }
054
055        /**
056         * Convenience method when we have only a single method name to match.
057         * Use either this method or {@code setMappedNames}, not both.
058         * @see #setMappedNames
059         * @see NameMatchMethodPointcut#setMappedName
060         */
061        public void setMappedName(String mappedName) {
062                this.pointcut.setMappedName(mappedName);
063        }
064
065        /**
066         * Set the method names defining methods to match.
067         * Matching will be the union of all these; if any match,
068         * the pointcut matches.
069         * @see NameMatchMethodPointcut#setMappedNames
070         */
071        public void setMappedNames(String... mappedNames) {
072                this.pointcut.setMappedNames(mappedNames);
073        }
074
075        /**
076         * Add another eligible method name, in addition to those already named.
077         * Like the set methods, this method is for use when configuring proxies,
078         * before a proxy is used.
079         * @param name the name of the additional method that will match
080         * @return this pointcut to allow for multiple additions in one line
081         * @see NameMatchMethodPointcut#addMethodName
082         */
083        public NameMatchMethodPointcut addMethodName(String name) {
084                return this.pointcut.addMethodName(name);
085        }
086
087
088        @Override
089        public Pointcut getPointcut() {
090                return this.pointcut;
091        }
092
093}