Example usage for org.springframework.beans.factory.xml XmlReaderContext getReader

List of usage examples for org.springframework.beans.factory.xml XmlReaderContext getReader

Introduction

In this page you can find the example usage for org.springframework.beans.factory.xml XmlReaderContext getReader.

Prototype

public final XmlBeanDefinitionReader getReader() 

Source Link

Document

Return the XML bean definition reader in use.

Usage

From source file:com.bstek.dorado.web.servlet.DefaultDoradoAppContextImporter.java

protected void importBeanDefinitionResource(String location, Element element, ParserContext parserContext)
        throws Exception {
    XmlReaderContext readerContext = parserContext.getReaderContext();
    try {//  www  . jav a 2  s  . c  om
        ResourceLoader resourceLoader = readerContext.getResourceLoader();
        Resource relativeResource = resourceLoader.getResource(location);

        int importCount = readerContext.getReader().loadBeanDefinitions(relativeResource);
        if (logger.isDebugEnabled()) {
            logger.debug(
                    "Imported " + importCount + " bean definitions from dorado-context [" + location + "]");
        }
    } catch (Exception ex) {
        readerContext.error("Invalid dorado-context [" + location + "] to import bean definitions from",
                element, null, ex);
    }

    readerContext.fireImportProcessed(location, readerContext.extractSource(element));
}

From source file:com.trigonic.utils.spring.beans.ImportBeanDefinitionParser.java

@Override
protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) {
    XmlReaderContext readerContext = parserContext.getReaderContext();
    String primaryLocation = element.getAttribute(RESOURCE_ATTRIBUTE);
    if (!StringUtils.hasText(primaryLocation)) {
        readerContext.error("Resource location must not be empty", element);
        return null;
    }/*from   w  ww  .j a v a2  s .co  m*/

    String alternateLocation = element.getAttribute(ALTERNATE_ATTRIBUTE);
    boolean optional = Boolean.parseBoolean(element.getAttribute(OPTIONAL_ATTRIBUTE));

    String currentLocation = primaryLocation;
    try {
        Set<Resource> actualResources = ImportHelper.importResource(readerContext.getReader(),
                readerContext.getResource(), currentLocation);

        if (actualResources.isEmpty() && StringUtils.hasLength(alternateLocation)) {
            currentLocation = alternateLocation;
            actualResources = ImportHelper.importResource(readerContext.getReader(),
                    readerContext.getResource(), currentLocation);
        }

        if (actualResources.isEmpty() && !optional) {
            readerContext.error("Primary location [" + primaryLocation + "]"
                    + (alternateLocation == null ? "" : " and alternate location [" + alternateLocation + "]")
                    + " are not optional", element);
            return null;
        }

        Resource[] actResArray = actualResources.toArray(new Resource[actualResources.size()]);
        readerContext.fireImportProcessed(primaryLocation, actResArray, readerContext.extractSource(element));
    } catch (BeanDefinitionStoreException ex) {
        readerContext.error("Failed to import bean definitions from location [" + currentLocation + "]",
                element, ex);
    }

    return null;
}