Example usage for org.springframework.beans.factory.support ChildBeanDefinition ChildBeanDefinition

List of usage examples for org.springframework.beans.factory.support ChildBeanDefinition ChildBeanDefinition

Introduction

In this page you can find the example usage for org.springframework.beans.factory.support ChildBeanDefinition ChildBeanDefinition.

Prototype

public ChildBeanDefinition(String parentName, String beanClassName, ConstructorArgumentValues cargs,
        MutablePropertyValues pvs) 

Source Link

Document

Create a new ChildBeanDefinition for the given parent, providing constructor arguments and property values.

Usage

From source file:org.bigtester.ate.xmlschema.PageElementExistBeanDefinitionParser.java

/**
 * {@inheritDoc}// w  w w  .j  ava  2s  .c  o  m
 */
@Override
protected AbstractBeanDefinition parseInternal(@Nullable Element element,
        @Nullable ParserContext parserContext) {
    // Here we parse the Spring elements such as < property>
    if (parserContext == null || element == null)
        throw GlobalUtils.createNotInitializedException("element and parserContext");
    // Here we parse the Spring elements such as < property>
    BeanDefinitionHolder holder = parserContext.getDelegate().parseBeanDefinitionElement(element);
    BeanDefinition bDef = holder.getBeanDefinition();
    bDef.setBeanClassName(PageElementExistenceAsserter.class.getName());
    String resultPage = element
            .getAttribute(XsdElementConstants.ATTR_ABSTRACTEXPECTEDRESULTASSERTER_RESULTPAGE);
    if (StringUtils.hasText(resultPage)) {
        bDef.getConstructorArgumentValues().addGenericArgumentValue(new RuntimeBeanReference(resultPage));
    }
    String stepERValue = element
            .getAttribute(XsdElementConstants.ATTR_ABSTRACTEXPECTEDRESULTASSERTER_STEPERVALUE);

    if (StringUtils.hasText(stepERValue)) {
        ConstructorArgumentValues erValueDefConstrs = new ConstructorArgumentValues();
        erValueDefConstrs.addGenericArgumentValue(stepERValue);
        BeanDefinition erValueDef = new ChildBeanDefinition(XsdElementConstants.ELEMENT_ID_BASEERVALUE,
                StepErElementExistenceValue.class, erValueDefConstrs, null);

        parserContext.getRegistry()
                .registerBeanDefinition(element.getAttribute("id") + "_ASSERTER_STEPERVALUE_ID", erValueDef);

        bDef.getConstructorArgumentValues().addGenericArgumentValue(
                new RuntimeBeanReference(element.getAttribute("id") + "_ASSERTER_STEPERVALUE_ID"));
    }

    parserContext.getRegistry().registerBeanDefinition(element.getAttribute("id"), bDef);

    return (AbstractBeanDefinition) bDef;

}

From source file:org.bigtester.ate.xmlschema.PagePropertyCorrectBeanDefinitionParser.java

/**
 * {@inheritDoc}/*from   ww w  .j  a  v  a  2 s.c o m*/
 */
@Override
protected AbstractBeanDefinition parseInternal(@Nullable Element element,
        @Nullable ParserContext parserContext) {
    // Here we parse the Spring elements such as < property>
    if (parserContext == null || element == null)
        throw GlobalUtils.createNotInitializedException("element and parserContext");
    // Here we parse the Spring elements such as < property>
    BeanDefinitionHolder holder = parserContext.getDelegate().parseBeanDefinitionElement(element);
    BeanDefinition bDef = holder.getBeanDefinition();
    bDef.setBeanClassName(PagePropertyCorrectnessAsserter.class.getName());
    String resultPage = element
            .getAttribute(XsdElementConstants.ATTR_ABSTRACTEXPECTEDRESULTASSERTER_RESULTPAGE);
    if (StringUtils.hasText(resultPage)) {
        bDef.getConstructorArgumentValues().addGenericArgumentValue(new RuntimeBeanReference(resultPage));
    }
    String stepERValue = element
            .getAttribute(XsdElementConstants.ATTR_ABSTRACTEXPECTEDRESULTASSERTER_STEPERVALUE);
    if (StringUtils.hasText(stepERValue)) {
        ConstructorArgumentValues erValueDefConstrs = new ConstructorArgumentValues();
        erValueDefConstrs.addGenericArgumentValue(stepERValue);
        BeanDefinition erValueDef = new ChildBeanDefinition(XsdElementConstants.ELEMENT_ID_BASEERVALUE,
                StepErPagePropertyValue.class, erValueDefConstrs, null);

        parserContext.getRegistry()
                .registerBeanDefinition(element.getAttribute("id") + "_ASSERTER_STEPERVALUE_ID", erValueDef);

        bDef.getConstructorArgumentValues().addGenericArgumentValue(
                new RuntimeBeanReference(element.getAttribute("id") + "_ASSERTER_STEPERVALUE_ID"));
    }

    parserContext.getRegistry().registerBeanDefinition(element.getAttribute("id"), bDef);
    return (AbstractBeanDefinition) bDef;

}

From source file:hudson.util.spring.DefaultBeanConfiguration.java

protected AbstractBeanDefinition createBeanDefinition() {
    AbstractBeanDefinition bd;/*w w w .  java  2  s. co m*/
    if (constructorArgs.size() > 0) {
        ConstructorArgumentValues cav = new ConstructorArgumentValues();
        for (Object constructorArg : constructorArgs) {
            cav.addGenericArgumentValue(constructorArg);
        }
        if (StringUtils.isBlank(parentName)) {
            bd = new RootBeanDefinition(clazz, cav, null);
        } else {
            bd = new ChildBeanDefinition(parentName, clazz, cav, null);
        }
        bd.setSingleton(singleton);
    } else {
        if (StringUtils.isBlank(parentName)) {
            bd = new RootBeanDefinition(clazz, singleton);
        } else {
            bd = new ChildBeanDefinition(parentName, clazz, null, null);
            bd.setSingleton(singleton);
        }

    }
    wrapper = new BeanWrapperImpl(bd);
    return bd;
}

From source file:org.springframework.beans.factory.DefaultListableBeanFactoryTests.java

@Test
public void testGetTypeWorksAfterParentChildMerging() {
    RootBeanDefinition parentDefinition = new RootBeanDefinition(TestBean.class);
    ChildBeanDefinition childDefinition = new ChildBeanDefinition("parent", DerivedTestBean.class, null, null);

    DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
    factory.registerBeanDefinition("parent", parentDefinition);
    factory.registerBeanDefinition("child", childDefinition);
    factory.freezeConfiguration();/* ww w  .j ava2s.  co  m*/

    assertEquals(TestBean.class, factory.getType("parent"));
    assertEquals(DerivedTestBean.class, factory.getType("child"));
}