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.support; 18 19 import org.springframework.beans.factory.BeanDefinitionStoreException; 20 import org.springframework.core.io.Resource; 21 import org.springframework.core.io.ResourceLoader; 22 23 /** 24 * Simple interface for bean definition readers. 25 * Specifies load methods with Resource parameters. 26 * 27 * <p>Concrete bean definition readers can of course add additional 28 * load and register methods for bean definitions, specific to 29 * their bean definition format. 30 * 31 * <p>Note that a bean definition reader does not have to implement 32 * this interface. It only serves as suggestion for bean definition 33 * readers that want to follow standard naming conventions. 34 * 35 * @author Juergen Hoeller 36 * @since 1.1 37 * @see org.springframework.core.io.Resource 38 */ 39 public interface BeanDefinitionReader { 40 41 /** 42 * Return the bean factory to register the bean definitions with. 43 * <p>The factory is exposed through the BeanDefinitionRegistry interface, 44 * encapsulating the methods that are relevant for bean definition handling. 45 */ 46 BeanDefinitionRegistry getBeanFactory(); 47 48 /** 49 * Return the resource loader to use for resource locations. 50 * Can be checked for the <b>ResourcePatternResolver</b> interface and cast 51 * accordingly, for loading multiple resources for a given resource pattern. 52 * <p>Null suggests that absolute resource loading is not available 53 * for this bean definition reader. 54 * <p>This is mainly meant to be used for importing further resources 55 * from within a bean definition resource, for example via the "import" 56 * tag in XML bean definitions. It is recommended, however, to apply 57 * such imports relative to the defining resource; only explicit full 58 * resource locations will trigger absolute resource loading. 59 * <p>There is also a <code>loadBeanDefinitions(String)</code> method available, 60 * for loading bean definitions from a resource location (or location pattern). 61 * This is a convenience to avoid explicit ResourceLoader handling. 62 * @see #loadBeanDefinitions(String) 63 * @see org.springframework.core.io.support.ResourcePatternResolver 64 */ 65 ResourceLoader getResourceLoader(); 66 67 /** 68 * Return the class loader to use for bean classes. 69 * <p><code>null</code> suggests to not load bean classes eagerly 70 * but rather to just register bean definitions with class names, 71 * with the corresponding Classes to be resolved later (or never). 72 */ 73 ClassLoader getBeanClassLoader(); 74 75 76 /** 77 * Load bean definitions from the specified resource. 78 * @param resource the resource descriptor 79 * @return the number of bean definitions found 80 * @throws BeanDefinitionStoreException in case of loading or parsing errors 81 */ 82 int loadBeanDefinitions(Resource resource) throws BeanDefinitionStoreException; 83 84 /** 85 * Load bean definitions from the specified resources. 86 * @param resources the resource descriptors 87 * @return the number of bean definitions found 88 * @throws BeanDefinitionStoreException in case of loading or parsing errors 89 */ 90 int loadBeanDefinitions(Resource[] resources) throws BeanDefinitionStoreException; 91 92 /** 93 * Load bean definitions from the specified resource location. 94 * <p>The location can also be a location pattern, provided that the 95 * ResourceLoader of this bean definition reader is a ResourcePatternResolver. 96 * @param location the resource location, to be loaded with the ResourceLoader 97 * (or ResourcePatternResolver) of this bean definition reader 98 * @return the number of bean definitions found 99 * @throws BeanDefinitionStoreException in case of loading or parsing errors 100 * @see #getResourceLoader() 101 * @see #loadBeanDefinitions(org.springframework.core.io.Resource) 102 * @see #loadBeanDefinitions(org.springframework.core.io.Resource[]) 103 */ 104 int loadBeanDefinitions(String location) throws BeanDefinitionStoreException; 105 106 /** 107 * Load bean definitions from the specified resource locations. 108 * @param locations the resource locations, to be loaded with the ResourceLoader 109 * (or ResourcePatternResolver) of this bean definition reader 110 * @return the number of bean definitions found 111 * @throws BeanDefinitionStoreException in case of loading or parsing errors 112 */ 113 int loadBeanDefinitions(String[] locations) throws BeanDefinitionStoreException; 114 115 } 116