Package org.springframework.beans.factory.xml

# Class XmlReaderContext

java.lang.Object
org.springframework.beans.factory.parsing.ReaderContext
org.springframework.beans.factory.xml.XmlReaderContext

public class XmlReaderContext extends ReaderContext
Extension of `ReaderContext`, specific to use with an `XmlBeanDefinitionReader`. Provides access to the `NamespaceHandlerResolver` configured in the `XmlBeanDefinitionReader`.

Since:
  2.0
Author:
  Rob Harrop, Juergen Hoeller

## Constructor Summary

Constructors
Constructor
Description
`XmlReaderContext(org.springframework.core.io.Resource resource, ProblemReporter problemReporter, ReaderEventListener eventListener, SourceExtractor sourceExtractor, XmlBeanDefinitionReader reader, NamespaceHandlerResolver namespaceHandlerResolver)`
Construct a new `XmlReaderContext`.

## Method Summary

Modifier and Type
Method
Description
`String`
`generateBeanName(BeanDefinition beanDefinition)`
Call the bean name generator for the given bean definition.
`final ClassLoader`
`getBeanClassLoader()`
Return the bean class loader to use, if any.
`final org.springframework.core.env.Environment`
`getEnvironment()`
Return the environment to use.
`final NamespaceHandlerResolver`
`getNamespaceHandlerResolver()`
Return the namespace resolver.
`final XmlBeanDefinitionReader`
`getReader()`
Return the XML bean definition reader in use.
`final BeanDefinitionRegistry`
`getRegistry()`
Return the bean definition registry to use.
`final org.springframework.core.io.ResourceLoader`
`getResourceLoader()`
Return the resource loader to use, if any.
`Document`
`readDocumentFromString(String documentContent)`
Read an XML document from the given String.
`String`
`registerWithGeneratedName(BeanDefinition beanDefinition)`
Call the bean name generator for the given bean definition and register the bean definition under the generated name.

### Methods inherited from class org.springframework.beans.factory.parsing.ReaderContext

`error, error, error, error, extractSource, fatal, fatal, fatal, fatal, fireAliasRegistered, fireComponentRegistered, fireDefaultsRegistered, fireImportProcessed, fireImportProcessed, getResource, getSourceExtractor, warning, warning, warning, warning`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### XmlReaderContext

public XmlReaderContext(org.springframework.core.io.Resource resource, ProblemReporter problemReporter, ReaderEventListener eventListener, SourceExtractor sourceExtractor, XmlBeanDefinitionReader reader, NamespaceHandlerResolver namespaceHandlerResolver)
Construct a new `XmlReaderContext`.

Parameters:
  `resource` - the XML bean definition resource
  `problemReporter` - the problem reporter in use
  `eventListener` - the event listener in use
  `sourceExtractor` - the source extractor in use
  `reader` - the XML bean definition reader in use
  `namespaceHandlerResolver` - the XML namespace resolver

## Method Details

### getReader

public final XmlBeanDefinitionReader getReader()
Return the XML bean definition reader in use.

### getRegistry

public final BeanDefinitionRegistry getRegistry()
Return the bean definition registry to use.

See Also:
  - `XmlBeanDefinitionReader(BeanDefinitionRegistry)`

### getResourceLoader

@Nullable public final org.springframework.core.io.ResourceLoader getResourceLoader()
Return the resource loader to use, if any.

This will be non-null in regular scenarios, also allowing access to the resource class loader.

See Also:
  - `AbstractBeanDefinitionReader.setResourceLoader(org.springframework.core.io.ResourceLoader)`
  - `ResourceLoader.getClassLoader()`

### getBeanClassLoader

@Nullable public final ClassLoader getBeanClassLoader()
Return the bean class loader to use, if any.

Note that this will be null in regular scenarios, as an indication to lazily resolve bean classes.

See Also:
  - `AbstractBeanDefinitionReader.setBeanClassLoader(java.lang.ClassLoader)`

### getEnvironment

public final org.springframework.core.env.Environment getEnvironment()
Return the environment to use.

See Also:
  - `AbstractBeanDefinitionReader.setEnvironment(org.springframework.core.env.Environment)`

### getNamespaceHandlerResolver

public final NamespaceHandlerResolver getNamespaceHandlerResolver()
Return the namespace resolver.

See Also:
  - `XmlBeanDefinitionReader.setNamespaceHandlerResolver(org.springframework.beans.factory.xml.NamespaceHandlerResolver)`

### generateBeanName

public String generateBeanName(BeanDefinition beanDefinition)
Call the bean name generator for the given bean definition.

See Also:
  - `AbstractBeanDefinitionReader.getBeanNameGenerator()`
  - `BeanNameGenerator.generateBeanName(org.springframework.beans.factory.config.BeanDefinition, org.springframework.beans.factory.support.BeanDefinitionRegistry)`

### registerWithGeneratedName

public String registerWithGeneratedName(BeanDefinition beanDefinition)
Call the bean name generator for the given bean definition and register the bean definition under the generated name.

See Also:
  - `AbstractBeanDefinitionReader.getBeanNameGenerator()`
  - `BeanNameGenerator.generateBeanName(org.springframework.beans.factory.config.BeanDefinition, org.springframework.beans.factory.support.BeanDefinitionRegistry)`
  - `BeanDefinitionRegistry.registerBeanDefinition(java.lang.String, org.springframework.beans.factory.config.BeanDefinition)`

### readDocumentFromString

public Document readDocumentFromString(String documentContent)
Read an XML document from the given String.

See Also:
  - `getReader()`