KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > beans > factory > xml > XmlReaderContext


1 /*
2  * Copyright 2002-2007 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.springframework.beans.factory.config.BeanDefinition;
20 import org.springframework.beans.factory.parsing.ProblemReporter;
21 import org.springframework.beans.factory.parsing.ReaderContext;
22 import org.springframework.beans.factory.parsing.ReaderEventListener;
23 import org.springframework.beans.factory.parsing.SourceExtractor;
24 import org.springframework.beans.factory.support.BeanDefinitionRegistry;
25 import org.springframework.core.io.Resource;
26
27 /**
28  * Extension of {@link org.springframework.beans.factory.parsing.ReaderContext},
29  * specific to use with an {@link XmlBeanDefinitionReader}. Provides access to the
30  * {@link NamespaceHandlerResolver} configured in the {@link XmlBeanDefinitionReader}.
31  *
32  * @author Rob Harrop
33  * @author Juergen Hoeller
34  * @since 2.0
35  */

36 public class XmlReaderContext extends ReaderContext {
37
38     private final XmlBeanDefinitionReader reader;
39
40     private final NamespaceHandlerResolver namespaceHandlerResolver;
41
42
43     public XmlReaderContext(
44             Resource resource, ProblemReporter problemReporter,
45             ReaderEventListener eventListener, SourceExtractor sourceExtractor,
46             XmlBeanDefinitionReader reader, NamespaceHandlerResolver namespaceHandlerResolver) {
47
48         super(resource, problemReporter, eventListener, sourceExtractor);
49         this.reader = reader;
50         this.namespaceHandlerResolver = namespaceHandlerResolver;
51     }
52
53
54     public final XmlBeanDefinitionReader getReader() {
55         return this.reader;
56     }
57
58     public final BeanDefinitionRegistry getRegistry() {
59         return this.reader.getBeanFactory();
60     }
61
62     public final NamespaceHandlerResolver getNamespaceHandlerResolver() {
63         return this.namespaceHandlerResolver;
64     }
65
66
67     public String JavaDoc generateBeanName(BeanDefinition beanDefinition) {
68         return this.reader.getBeanNameGenerator().generateBeanName(beanDefinition, getRegistry());
69     }
70
71     public String JavaDoc registerWithGeneratedName(BeanDefinition beanDefinition) {
72         String JavaDoc generatedName = generateBeanName(beanDefinition);
73         getRegistry().registerBeanDefinition(generatedName, beanDefinition);
74         return generatedName;
75     }
76
77 }
78
Popular Tags