001/*
002 * Copyright 2002-2020 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.config;
018
019import org.springframework.aop.aspectj.AspectJExpressionPointcut;
020import org.springframework.beans.factory.xml.BeanDefinitionParser;
021import org.springframework.beans.factory.xml.NamespaceHandlerSupport;
022
023/**
024 * {@code NamespaceHandler} for the {@code aop} namespace.
025 *
026 * <p>Provides a {@link org.springframework.beans.factory.xml.BeanDefinitionParser} for the
027 * {@code <aop:config>} tag. A {@code config} tag can include nested
028 * {@code pointcut}, {@code advisor} and {@code aspect} tags.
029 *
030 * <p>The {@code pointcut} tag allows for creation of named
031 * {@link AspectJExpressionPointcut} beans using a simple syntax:
032 * <pre class="code">
033 * &lt;aop:pointcut id=&quot;getNameCalls&quot; expression=&quot;execution(* *..ITestBean.getName(..))&quot;/&gt;
034 * </pre>
035 *
036 * <p>Using the {@code advisor} tag you can configure an {@link org.springframework.aop.Advisor}
037 * and have it applied to all relevant beans in you {@link org.springframework.beans.factory.BeanFactory}
038 * automatically. The {@code advisor} tag supports both in-line and referenced
039 * {@link org.springframework.aop.Pointcut Pointcuts}:
040 *
041 * <pre class="code">
042 * &lt;aop:advisor id=&quot;getAgeAdvisor&quot;
043 *     pointcut=&quot;execution(* *..ITestBean.getAge(..))&quot;
044 *     advice-ref=&quot;getAgeCounter&quot;/&gt;
045 *
046 * &lt;aop:advisor id=&quot;getNameAdvisor&quot;
047 *     pointcut-ref=&quot;getNameCalls&quot;
048 *     advice-ref=&quot;getNameCounter&quot;/&gt;</pre>
049 *
050 * @author Rob Harrop
051 * @author Adrian Colyer
052 * @author Juergen Hoeller
053 * @since 2.0
054 */
055public class AopNamespaceHandler extends NamespaceHandlerSupport {
056
057        /**
058         * Register the {@link BeanDefinitionParser BeanDefinitionParsers} for the
059         * '{@code config}', '{@code spring-configured}', '{@code aspectj-autoproxy}'
060         * and '{@code scoped-proxy}' tags.
061         */
062        @Override
063        public void init() {
064                // In 2.0 XSD as well as in 2.5+ XSDs
065                registerBeanDefinitionParser("config", new ConfigBeanDefinitionParser());
066                registerBeanDefinitionParser("aspectj-autoproxy", new AspectJAutoProxyBeanDefinitionParser());
067                registerBeanDefinitionDecorator("scoped-proxy", new ScopedProxyBeanDefinitionDecorator());
068
069                // Only in 2.0 XSD: moved to context namespace in 2.5+
070                registerBeanDefinitionParser("spring-configured", new SpringConfiguredBeanDefinitionParser());
071        }
072
073}