Search in sources :

Example 1 with NullSourceExtractor

use of org.springframework.beans.factory.parsing.NullSourceExtractor in project aries by apache.

the class BlueprintNamespaceHandler method createSpringParserContext.

private org.springframework.beans.factory.xml.ParserContext createSpringParserContext(final ParserContext parserContext, DefaultListableBeanFactory registry) {
    try {
        SpringVersionBridgeXmlBeanDefinitionReader xbdr = new SpringVersionBridgeXmlBeanDefinitionReader(registry);
        Resource resource = new UrlResource(parserContext.getSourceNode().getOwnerDocument().getDocumentURI());
        ProblemReporter problemReporter = new FailFastProblemReporter();
        ReaderEventListener listener = new EmptyReaderEventListener();
        SourceExtractor extractor = new NullSourceExtractor();
        NamespaceHandlerResolver resolver = new SpringNamespaceHandlerResolver(parserContext);
        xbdr.setProblemReporter(problemReporter);
        xbdr.setEventListener(listener);
        xbdr.setSourceExtractor(extractor);
        xbdr.setNamespaceHandlerResolver(resolver);
        xbdr.setEntityResolver(new EntityResolver() {

            @Override
            public InputSource resolveEntity(String publicId, String systemId) throws IOException {
                for (URI ns : parserContext.getNamespaces()) {
                    NamespaceHandler nh = parserContext.getNamespaceHandler(ns);
                    URL url = null;
                    if (publicId != null) {
                        url = nh.getSchemaLocation(publicId);
                    }
                    if (url == null && systemId != null) {
                        url = nh.getSchemaLocation(systemId);
                    }
                    if (url != null) {
                        InputSource is = new InputSource();
                        is.setPublicId(publicId);
                        is.setSystemId(systemId);
                        is.setByteStream(url.openStream());
                        return is;
                    }
                }
                return null;
            }
        });
        XmlReaderContext xmlReaderContext = xbdr.createReaderContext(resource);
        BeanDefinitionParserDelegate bdpd = new BeanDefinitionParserDelegate(xmlReaderContext);
        return new org.springframework.beans.factory.xml.ParserContext(xmlReaderContext, bdpd);
    } catch (Exception e) {
        throw new RuntimeException("Error creating spring parser context", e);
    }
}
Also used : EmptyReaderEventListener(org.springframework.beans.factory.parsing.EmptyReaderEventListener) InputSource(org.xml.sax.InputSource) NamespaceHandlerResolver(org.springframework.beans.factory.xml.NamespaceHandlerResolver) BeanDefinitionParserDelegate(org.springframework.beans.factory.xml.BeanDefinitionParserDelegate) XmlReaderContext(org.springframework.beans.factory.xml.XmlReaderContext) URI(java.net.URI) URL(java.net.URL) ProblemReporter(org.springframework.beans.factory.parsing.ProblemReporter) FailFastProblemReporter(org.springframework.beans.factory.parsing.FailFastProblemReporter) UrlResource(org.springframework.core.io.UrlResource) Resource(org.springframework.core.io.Resource) ReaderEventListener(org.springframework.beans.factory.parsing.ReaderEventListener) EmptyReaderEventListener(org.springframework.beans.factory.parsing.EmptyReaderEventListener) EntityResolver(org.xml.sax.EntityResolver) IOException(java.io.IOException) FailFastProblemReporter(org.springframework.beans.factory.parsing.FailFastProblemReporter) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException) UrlResource(org.springframework.core.io.UrlResource) NamespaceHandler(org.apache.aries.blueprint.NamespaceHandler) ParserContext(org.apache.aries.blueprint.ParserContext) NullSourceExtractor(org.springframework.beans.factory.parsing.NullSourceExtractor) SourceExtractor(org.springframework.beans.factory.parsing.SourceExtractor) NullSourceExtractor(org.springframework.beans.factory.parsing.NullSourceExtractor)

Example 2 with NullSourceExtractor

use of org.springframework.beans.factory.parsing.NullSourceExtractor in project grails-core by grails.

the class BeanBuilder method initializeBeanBuilderForClassLoader.

protected void initializeBeanBuilderForClassLoader(ClassLoader classLoader) {
    xmlBeanDefinitionReader.setBeanClassLoader(classLoader);
    namespaceHandlerResolver = new DefaultNamespaceHandlerResolver(this.classLoader);
    readerContext = new XmlReaderContext(beanBuildResource, new FailFastProblemReporter(), new EmptyReaderEventListener(), new NullSourceExtractor(), xmlBeanDefinitionReader, namespaceHandlerResolver);
}
Also used : EmptyReaderEventListener(org.springframework.beans.factory.parsing.EmptyReaderEventListener) XmlReaderContext(org.springframework.beans.factory.xml.XmlReaderContext) DefaultNamespaceHandlerResolver(org.springframework.beans.factory.xml.DefaultNamespaceHandlerResolver) NullSourceExtractor(org.springframework.beans.factory.parsing.NullSourceExtractor) FailFastProblemReporter(org.springframework.beans.factory.parsing.FailFastProblemReporter)

Aggregations

EmptyReaderEventListener (org.springframework.beans.factory.parsing.EmptyReaderEventListener)2 FailFastProblemReporter (org.springframework.beans.factory.parsing.FailFastProblemReporter)2 NullSourceExtractor (org.springframework.beans.factory.parsing.NullSourceExtractor)2 XmlReaderContext (org.springframework.beans.factory.xml.XmlReaderContext)2 IOException (java.io.IOException)1 URI (java.net.URI)1 URL (java.net.URL)1 NamespaceHandler (org.apache.aries.blueprint.NamespaceHandler)1 ParserContext (org.apache.aries.blueprint.ParserContext)1 ProblemReporter (org.springframework.beans.factory.parsing.ProblemReporter)1 ReaderEventListener (org.springframework.beans.factory.parsing.ReaderEventListener)1 SourceExtractor (org.springframework.beans.factory.parsing.SourceExtractor)1 BeanDefinitionParserDelegate (org.springframework.beans.factory.xml.BeanDefinitionParserDelegate)1 DefaultNamespaceHandlerResolver (org.springframework.beans.factory.xml.DefaultNamespaceHandlerResolver)1 NamespaceHandlerResolver (org.springframework.beans.factory.xml.NamespaceHandlerResolver)1 Resource (org.springframework.core.io.Resource)1 UrlResource (org.springframework.core.io.UrlResource)1 EntityResolver (org.xml.sax.EntityResolver)1 InputSource (org.xml.sax.InputSource)1 SAXException (org.xml.sax.SAXException)1