01: /*
02: * Copyright 2002-2007 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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: import org.springframework.core.io.ResourceLoader;
27:
28: /**
29: * Extension of {@link org.springframework.beans.factory.parsing.ReaderContext},
30: * specific to use with an {@link XmlBeanDefinitionReader}. Provides access to the
31: * {@link NamespaceHandlerResolver} configured in the {@link XmlBeanDefinitionReader}.
32: *
33: * @author Rob Harrop
34: * @author Juergen Hoeller
35: * @since 2.0
36: */
37: public class XmlReaderContext extends ReaderContext {
38:
39: private final XmlBeanDefinitionReader reader;
40:
41: private final NamespaceHandlerResolver namespaceHandlerResolver;
42:
43: public XmlReaderContext(Resource resource,
44: ProblemReporter problemReporter,
45: ReaderEventListener eventListener,
46: SourceExtractor sourceExtractor,
47: XmlBeanDefinitionReader reader,
48: NamespaceHandlerResolver namespaceHandlerResolver) {
49:
50: super (resource, problemReporter, eventListener, sourceExtractor);
51: this .reader = reader;
52: this .namespaceHandlerResolver = namespaceHandlerResolver;
53: }
54:
55: public final XmlBeanDefinitionReader getReader() {
56: return this .reader;
57: }
58:
59: public final BeanDefinitionRegistry getRegistry() {
60: return this .reader.getBeanFactory();
61: }
62:
63: public final ResourceLoader getResourceLoader() {
64: return this .reader.getResourceLoader();
65: }
66:
67: public final ClassLoader getBeanClassLoader() {
68: return this .reader.getBeanClassLoader();
69: }
70:
71: public final NamespaceHandlerResolver getNamespaceHandlerResolver() {
72: return this .namespaceHandlerResolver;
73: }
74:
75: public String generateBeanName(BeanDefinition beanDefinition) {
76: return this .reader.getBeanNameGenerator().generateBeanName(
77: beanDefinition, getRegistry());
78: }
79:
80: public String registerWithGeneratedName(
81: BeanDefinition beanDefinition) {
82: String generatedName = generateBeanName(beanDefinition);
83: getRegistry().registerBeanDefinition(generatedName,
84: beanDefinition);
85: return generatedName;
86: }
87:
88: }
|