Example usage for org.springframework.beans.factory.xml NamespaceHandler init

List of usage examples for org.springframework.beans.factory.xml NamespaceHandler init

Introduction

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

Prototype

void init();

Source Link

Document

Invoked by the DefaultBeanDefinitionDocumentReader after construction but before any custom elements are parsed.

Usage

From source file:org.springframework.beans.factory.xml.DefaultNamespaceHandlerResolver.java

/**
 * Locate the {@link NamespaceHandler} for the supplied namespace URI
 * from the configured mappings./*from www .java 2  s  .  c  om*/
 * @param namespaceUri the relevant namespace URI
 * @return the located {@link NamespaceHandler}, or {@code null} if none found
 */
@Override
@Nullable
public NamespaceHandler resolve(String namespaceUri) {
    Map<String, Object> handlerMappings = getHandlerMappings();
    Object handlerOrClassName = handlerMappings.get(namespaceUri);
    if (handlerOrClassName == null) {
        return null;
    } else if (handlerOrClassName instanceof NamespaceHandler) {
        return (NamespaceHandler) handlerOrClassName;
    } else {
        String className = (String) handlerOrClassName;
        try {
            Class<?> handlerClass = ClassUtils.forName(className, this.classLoader);
            if (!NamespaceHandler.class.isAssignableFrom(handlerClass)) {
                throw new FatalBeanException("Class [" + className + "] for namespace [" + namespaceUri
                        + "] does not implement the [" + NamespaceHandler.class.getName() + "] interface");
            }
            NamespaceHandler namespaceHandler = (NamespaceHandler) BeanUtils.instantiateClass(handlerClass);
            namespaceHandler.init();
            handlerMappings.put(namespaceUri, namespaceHandler);
            return namespaceHandler;
        } catch (ClassNotFoundException ex) {
            throw new FatalBeanException("Could not find NamespaceHandler class [" + className
                    + "] for namespace [" + namespaceUri + "]", ex);
        } catch (LinkageError err) {
            throw new FatalBeanException("Unresolvable class definition for NamespaceHandler class ["
                    + className + "] for namespace [" + namespaceUri + "]", err);
        }
    }
}