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;
}
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);
}
}
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);
}
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);
}
}
}
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);
}
Aggregations