Example usage for org.springframework.beans.factory.xml BeanDefinitionParserDelegate parseBeanDefinitionElement

List of usage examples for org.springframework.beans.factory.xml BeanDefinitionParserDelegate parseBeanDefinitionElement

Introduction

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

Prototype

@Nullable
public BeanDefinitionHolder parseBeanDefinitionElement(Element ele) 

Source Link

Document

Parses the supplied element.

Usage

From source file:org.kuali.rice.krad.datadictionary.parse.CustomSchemaParser.java

/**
 * Parses a bean of the spring namespace.
 *
 * @param tag - The Element to be parsed.
 * @return The parsed bean.//from ww  w.j a va 2 s  . co  m
 */
protected Object parseSpringBean(Element tag, ParserContext parserContext) {
    if (tag.getLocalName().compareTo("ref") == 0) {
        // Create the referenced bean by creating a new bean and setting its parent to the referenced bean
        // then replace grand child with it
        Element temp = tag.getOwnerDocument().createElement("bean");
        temp.setAttribute("parent", tag.getAttribute("bean"));
        tag = temp;
        return new RuntimeBeanReference(tag.getAttribute("parent"));
    }

    //peel off p: properties an make them actual property nodes - p-namespace does not work properly (unknown cause)
    Document document = tag.getOwnerDocument();
    NamedNodeMap attributes = tag.getAttributes();
    for (int i = 0; i < attributes.getLength(); i++) {
        Node attribute = attributes.item(i);
        String name = attribute.getNodeName();
        if (name.startsWith("p:")) {
            Element property = document.createElement("property");
            property.setAttribute("name", StringUtils.removeStart(name, "p:"));
            property.setAttribute("value", attribute.getTextContent());

            if (tag.getFirstChild() != null) {
                tag.insertBefore(property, tag.getFirstChild());
            } else {
                tag.appendChild(property);
            }
        }
    }

    // Create the bean definition for the grandchild and return it.
    BeanDefinitionParserDelegate delegate = parserContext.getDelegate();
    BeanDefinitionHolder bean = delegate.parseBeanDefinitionElement(tag);

    // Creates a custom name for the new bean.
    String name = bean.getBeanDefinition().getParentName() + "$Customchild" + beanNumber;
    if (tag.getAttribute("id") != null && !StringUtils.isEmpty(tag.getAttribute("id"))) {
        name = tag.getAttribute("id");
    } else {
        beanNumber++;
    }

    return new BeanDefinitionHolder(bean.getBeanDefinition(), name);
}

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

/**
 * Process the given bean element, parsing the bean definition
 * and registering it with the registry.
 *//*from  www  .  j  a v a2 s . c  o  m*/
protected void processBeanDefinition(Element ele, BeanDefinitionParserDelegate delegate) {
    BeanDefinitionHolder bdHolder = delegate.parseBeanDefinitionElement(ele);
    if (bdHolder != null) {
        bdHolder = delegate.decorateBeanDefinitionIfRequired(ele, bdHolder);
        try {
            // Register the final decorated instance.
            BeanDefinitionReaderUtils.registerBeanDefinition(bdHolder, getReaderContext().getRegistry());
        } catch (BeanDefinitionStoreException ex) {
            getReaderContext().error(
                    "Failed to register bean definition with name '" + bdHolder.getBeanName() + "'", ele, ex);
        }
        // Send registration event.
        getReaderContext().fireComponentRegistered(new BeanComponentDefinition(bdHolder));
    }
}