KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > beans > factory > support > ConfigurableBeanFactoryUtils


1 /*
2  * Copyright 2002-2005 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 java.io.InputStream JavaDoc;
20 import java.net.URL JavaDoc;
21
22 import org.springframework.beans.factory.config.ConfigurableBeanFactory;
23 import org.springframework.beans.propertyeditors.InputStreamEditor;
24 import org.springframework.beans.propertyeditors.URLEditor;
25 import org.springframework.core.io.Resource;
26 import org.springframework.core.io.ResourceEditor;
27 import org.springframework.core.io.ResourceLoader;
28 import org.springframework.core.io.support.ResourceArrayPropertyEditor;
29 import org.springframework.core.io.support.ResourcePatternResolver;
30
31 /**
32  * Helper methods to populate a ConfigurableBeanFactory with resource editors.
33  * Used by AbstractApplicationContext and XmlViewResolver.
34  *
35  * @author Juergen Hoeller
36  * @since 1.2
37  * @see org.springframework.context.support.AbstractApplicationContext#refresh
38  * @see org.springframework.web.servlet.view.XmlViewResolver#initFactory
39  */

40 public abstract class ConfigurableBeanFactoryUtils {
41
42     /**
43      * Populate the given bean factory with the following resource editors:
44      * ResourceEditor, URLEditor, InputStreamEditor.
45      * @param beanFactory the bean factory to populate
46      * @param resourceLoader the ResourceLoader to create editors for
47      * (usually an ApplicationContext)
48      * @see org.springframework.core.io.ResourceEditor
49      * @see org.springframework.beans.propertyeditors.URLEditor
50      * @see org.springframework.beans.propertyeditors.InputStreamEditor
51      * @see org.springframework.context.ApplicationContext
52      */

53     public static void registerResourceEditors(
54             ConfigurableBeanFactory beanFactory, ResourceLoader resourceLoader) {
55
56         ResourceEditor baseEditor = new ResourceEditor(resourceLoader);
57         beanFactory.registerCustomEditor(Resource.class, baseEditor);
58         beanFactory.registerCustomEditor(URL JavaDoc.class, new URLEditor(baseEditor));
59         beanFactory.registerCustomEditor(InputStream JavaDoc.class, new InputStreamEditor(baseEditor));
60     }
61
62     /**
63      * Populate the given bean factory with the following resource editors:
64      * ResourceEditor, URLEditor, InputStreamEditor, ResourceArrayPropertyEditor.
65      * @param beanFactory the bean factory to populate
66      * @param resourcePatternResolver the ResourcePatternResolver to create
67      * editors for (usually an ApplicationContext)
68      * @see org.springframework.core.io.ResourceEditor
69      * @see org.springframework.beans.propertyeditors.URLEditor
70      * @see org.springframework.beans.propertyeditors.InputStreamEditor
71      * @see org.springframework.core.io.support.ResourceArrayPropertyEditor
72      * @see org.springframework.context.ApplicationContext
73      */

74     public static void registerResourceEditors(
75             ConfigurableBeanFactory beanFactory, ResourcePatternResolver resourcePatternResolver) {
76
77         registerResourceEditors(beanFactory, (ResourceLoader) resourcePatternResolver);
78         beanFactory.registerCustomEditor(Resource[].class,
79                 new ResourceArrayPropertyEditor(resourcePatternResolver));
80     }
81
82 }
83
Popular Tags