001/* 002 * Copyright 2002-2011 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.beans.factory.xml; 018 019import org.w3c.dom.Element; 020 021import org.springframework.beans.factory.config.BeanDefinition; 022import org.springframework.lang.Nullable; 023 024/** 025 * Interface used by the {@link DefaultBeanDefinitionDocumentReader} to handle custom, 026 * top-level (directly under {@code <beans/>}) tags. 027 * 028 * <p>Implementations are free to turn the metadata in the custom tag into as many 029 * {@link BeanDefinition BeanDefinitions} as required. 030 * 031 * <p>The parser locates a {@link BeanDefinitionParser} from the associated 032 * {@link NamespaceHandler} for the namespace in which the custom tag resides. 033 * 034 * @author Rob Harrop 035 * @since 2.0 036 * @see NamespaceHandler 037 * @see AbstractBeanDefinitionParser 038 */ 039public interface BeanDefinitionParser { 040 041 /** 042 * Parse the specified {@link Element} and register the resulting 043 * {@link BeanDefinition BeanDefinition(s)} with the 044 * {@link org.springframework.beans.factory.xml.ParserContext#getRegistry() BeanDefinitionRegistry} 045 * embedded in the supplied {@link ParserContext}. 046 * <p>Implementations must return the primary {@link BeanDefinition} that results 047 * from the parse if they will ever be used in a nested fashion (for example as 048 * an inner tag in a {@code <property/>} tag). Implementations may return 049 * {@code null} if they will <strong>not</strong> be used in a nested fashion. 050 * @param element the element that is to be parsed into one or more {@link BeanDefinition BeanDefinitions} 051 * @param parserContext the object encapsulating the current state of the parsing process; 052 * provides access to a {@link org.springframework.beans.factory.support.BeanDefinitionRegistry} 053 * @return the primary {@link BeanDefinition} 054 */ 055 @Nullable 056 BeanDefinition parse(Element element, ParserContext parserContext); 057 058}