1 /* 2 * Copyright 2002-2006 the original author or authors. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package org.springframework.beans.factory.xml; 18 19 import org.w3c.dom.Node; 20 21 import org.springframework.beans.factory.config.BeanDefinitionHolder; 22 23 /** 24 * Interface used by the {@link org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader} 25 * to handle custom, nested (directly under a <code><bean></code>) tags. 26 * 27 * <p>Decoration may also occur based on custom attributes applied to the 28 * <code><bean></code> tag. Implementations are free to turn the metadata in the 29 * custom tag into as many 30 * {@link org.springframework.beans.factory.config.BeanDefinition BeanDefinitions} as 31 * required and to transform the 32 * {@link org.springframework.beans.factory.config.BeanDefinition} of the enclosing 33 * <code><bean></code> tag, potentially even returning a completely different 34 * {@link org.springframework.beans.factory.config.BeanDefinition} to replace the 35 * original. 36 * 37 * <p>{@link BeanDefinitionDecorator BeanDefinitionDecorators} should be aware that 38 * they may be part of a chain. In particular, a {@link BeanDefinitionDecorator} should 39 * be aware that a previous {@link BeanDefinitionDecorator} may have replaced the 40 * original {@link org.springframework.beans.factory.config.BeanDefinition} with a 41 * {@link org.springframework.aop.framework.ProxyFactoryBean} definition allowing for 42 * custom {@link org.aopalliance.intercept.MethodInterceptor interceptors} to be added. 43 * 44 * <p>{@link BeanDefinitionDecorator BeanDefinitionDecorators} that wish to add an 45 * interceptor to the enclosing bean should extend 46 * {@link org.springframework.aop.config.AbstractInterceptorDrivenBeanDefinitionDecorator} 47 * which handles the chaining ensuring that only one proxy is created and that it 48 * contains all interceptors from the chain. 49 * 50 * <p>The parser locates a {@link BeanDefinitionDecorator} from the 51 * {@link NamespaceHandler} for the namespace in which the custom tag resides. 52 * 53 * @author Rob Harrop 54 * @since 2.0 55 * @see NamespaceHandler 56 * @see BeanDefinitionParser 57 */ 58 public interface BeanDefinitionDecorator { 59 60 /** 61 * Parse the specified {@link Node} (either an element or an attribute) and decorate 62 * the supplied {@link org.springframework.beans.factory.config.BeanDefinition}, 63 * returning the decorated definition. 64 * <p>Implementations may choose to return a completely new definition, which will 65 * replace the original definition in the resulting 66 * {@link org.springframework.beans.factory.BeanFactory}. 67 * <p>The supplied {@link ParserContext} can be used to register any additional 68 * beans needed to support the main definition. 69 */ 70 BeanDefinitionHolder decorate(Node node, BeanDefinitionHolder definition, ParserContext parserContext); 71 72 } 73