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