Search in sources :

Example 1 with NamespaceHandler

use of org.springframework.beans.factory.xml.NamespaceHandler in project grails-core by grails.

the class BeanBuilder method createDynamicElementReader.

protected DynamicElementReader createDynamicElementReader(String namespace, final boolean decorator) {
    NamespaceHandler handler = namespaceHandlers.get(namespace);
    ParserContext parserContext = new ParserContext(readerContext, new BeanDefinitionParserDelegate(readerContext));
    final DynamicElementReader dynamicElementReader = new DynamicElementReader(namespace, namespaces, handler, parserContext) {

        @Override
        protected void afterInvocation() {
            if (!decorator) {
                currentBeanConfig = null;
            }
        }
    };
    dynamicElementReader.setClassLoader(classLoader);
    if (currentBeanConfig != null) {
        dynamicElementReader.setBeanConfiguration(currentBeanConfig);
    } else if (!decorator) {
        currentBeanConfig = new DefaultBeanConfiguration(namespace);
        dynamicElementReader.setBeanConfiguration(currentBeanConfig);
    }
    dynamicElementReader.setBeanDecorator(decorator);
    return dynamicElementReader;
}
Also used : DefaultBeanConfiguration(org.grails.spring.DefaultBeanConfiguration) BeanDefinitionParserDelegate(org.springframework.beans.factory.xml.BeanDefinitionParserDelegate) NamespaceHandler(org.springframework.beans.factory.xml.NamespaceHandler) ParserContext(org.springframework.beans.factory.xml.ParserContext)

Example 2 with NamespaceHandler

use of org.springframework.beans.factory.xml.NamespaceHandler in project grails-core by grails.

the class BeanBuilder method xmlns.

/**
 * Defines a Spring namespace definition to use.
 *
 * @param definition The definition
 */
public void xmlns(Map<String, String> definition) {
    Assert.notNull(namespaceHandlerResolver, "You cannot define a Spring namespace without a [namespaceHandlerResolver] set");
    if (definition.isEmpty()) {
        return;
    }
    for (Map.Entry<String, String> entry : definition.entrySet()) {
        String namespace = entry.getKey();
        String uri = entry.getValue() == null ? null : entry.getValue();
        Assert.notNull(uri, "Namespace definition cannot supply a null URI");
        final NamespaceHandler namespaceHandler = namespaceHandlerResolver.resolve(uri);
        if (namespaceHandler == null) {
            throw new BeanDefinitionParsingException(new Problem("No namespace handler found for URI: " + uri, new Location(readerContext.getResource())));
        }
        namespaceHandlers.put(namespace, namespaceHandler);
        namespaces.put(namespace, uri);
    }
}
Also used : BeanDefinitionParsingException(org.springframework.beans.factory.parsing.BeanDefinitionParsingException) NamespaceHandler(org.springframework.beans.factory.xml.NamespaceHandler) Problem(org.springframework.beans.factory.parsing.Problem) GString(groovy.lang.GString) Map(java.util.Map) HashMap(java.util.HashMap) ManagedMap(org.springframework.beans.factory.support.ManagedMap) Location(org.springframework.beans.factory.parsing.Location)

Example 3 with NamespaceHandler

use of org.springframework.beans.factory.xml.NamespaceHandler in project spring-framework by spring-projects.

the class DefaultNamespaceHandlerResolverTests method testResolvedMappedHandlerWithNoArgCtor.

@Test
public void testResolvedMappedHandlerWithNoArgCtor() {
    DefaultNamespaceHandlerResolver resolver = new DefaultNamespaceHandlerResolver();
    NamespaceHandler handler = resolver.resolve("http://www.springframework.org/schema/util");
    assertThat(handler).as("Handler should not be null.").isNotNull();
    assertThat(handler.getClass()).as("Incorrect handler loaded").isEqualTo(UtilNamespaceHandler.class);
}
Also used : NamespaceHandler(org.springframework.beans.factory.xml.NamespaceHandler) UtilNamespaceHandler(org.springframework.beans.factory.xml.UtilNamespaceHandler) DefaultNamespaceHandlerResolver(org.springframework.beans.factory.xml.DefaultNamespaceHandlerResolver) Test(org.junit.jupiter.api.Test)

Example 4 with NamespaceHandler

use of org.springframework.beans.factory.xml.NamespaceHandler in project spring-framework by spring-projects.

the class GroovyBeanDefinitionReader method xmlns.

/**
	 * Define a Spring XML namespace definition to use.
	 * @param definition the namespace definition
	 */
public void xmlns(Map<String, String> definition) {
    if (!definition.isEmpty()) {
        for (Map.Entry<String, String> entry : definition.entrySet()) {
            String namespace = entry.getKey();
            String uri = entry.getValue();
            if (uri == null) {
                throw new IllegalArgumentException("Namespace definition must supply a non-null URI");
            }
            NamespaceHandler namespaceHandler = this.groovyDslXmlBeanDefinitionReader.getNamespaceHandlerResolver().resolve(uri);
            if (namespaceHandler == null) {
                throw new BeanDefinitionParsingException(new Problem("No namespace handler found for URI: " + uri, new Location(new DescriptiveResource(("Groovy")))));
            }
            this.namespaces.put(namespace, uri);
        }
    }
}
Also used : BeanDefinitionParsingException(org.springframework.beans.factory.parsing.BeanDefinitionParsingException) NamespaceHandler(org.springframework.beans.factory.xml.NamespaceHandler) DescriptiveResource(org.springframework.core.io.DescriptiveResource) Problem(org.springframework.beans.factory.parsing.Problem) GString(groovy.lang.GString) HashMap(java.util.HashMap) Map(java.util.Map) ManagedMap(org.springframework.beans.factory.support.ManagedMap) Location(org.springframework.beans.factory.parsing.Location)

Example 5 with NamespaceHandler

use of org.springframework.beans.factory.xml.NamespaceHandler in project spring-framework by spring-projects.

the class DefaultNamespaceHandlerResolverTests method testResolvedMappedHandler.

@Test
public void testResolvedMappedHandler() {
    DefaultNamespaceHandlerResolver resolver = new DefaultNamespaceHandlerResolver(getClass().getClassLoader());
    NamespaceHandler handler = resolver.resolve("http://www.springframework.org/schema/util");
    assertThat(handler).as("Handler should not be null.").isNotNull();
    assertThat(handler.getClass()).as("Incorrect handler loaded").isEqualTo(UtilNamespaceHandler.class);
}
Also used : NamespaceHandler(org.springframework.beans.factory.xml.NamespaceHandler) UtilNamespaceHandler(org.springframework.beans.factory.xml.UtilNamespaceHandler) DefaultNamespaceHandlerResolver(org.springframework.beans.factory.xml.DefaultNamespaceHandlerResolver) Test(org.junit.jupiter.api.Test)

Aggregations

NamespaceHandler (org.springframework.beans.factory.xml.NamespaceHandler)5 GString (groovy.lang.GString)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Test (org.junit.jupiter.api.Test)2 BeanDefinitionParsingException (org.springframework.beans.factory.parsing.BeanDefinitionParsingException)2 Location (org.springframework.beans.factory.parsing.Location)2 Problem (org.springframework.beans.factory.parsing.Problem)2 ManagedMap (org.springframework.beans.factory.support.ManagedMap)2 DefaultNamespaceHandlerResolver (org.springframework.beans.factory.xml.DefaultNamespaceHandlerResolver)2 UtilNamespaceHandler (org.springframework.beans.factory.xml.UtilNamespaceHandler)2 DefaultBeanConfiguration (org.grails.spring.DefaultBeanConfiguration)1 BeanDefinitionParserDelegate (org.springframework.beans.factory.xml.BeanDefinitionParserDelegate)1 ParserContext (org.springframework.beans.factory.xml.ParserContext)1 DescriptiveResource (org.springframework.core.io.DescriptiveResource)1