Example usage for org.springframework.beans.factory.config ConstructorArgumentValues ConstructorArgumentValues

List of usage examples for org.springframework.beans.factory.config ConstructorArgumentValues ConstructorArgumentValues

Introduction

In this page you can find the example usage for org.springframework.beans.factory.config ConstructorArgumentValues ConstructorArgumentValues.

Prototype

public ConstructorArgumentValues() 

Source Link

Document

Create a new empty ConstructorArgumentValues object.

Usage

From source file:com.griddynamics.banshun.xml.ImportBeanDefinitionParser.java

@Override
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {

    String exportInterface = element.getAttribute(INTERFACE_ATTR);
    if (isBlank(exportInterface)) {
        return;//from w  w  w .  j  a v  a 2s. c  om
    }

    String externalName = element.getAttribute(ID_ATTR);
    if (isBlank(externalName)) {
        return;
    }

    String rootName = element.getAttribute(ROOT_ATTR);
    if (isBlank(rootName)) {
        rootName = DEFAULT_ROOT_FACTORY_NAME;
    }

    ConstructorArgumentValues constructorArgValues = new ConstructorArgumentValues();
    constructorArgValues.addGenericArgumentValue(externalName);
    constructorArgValues.addGenericArgumentValue(findClass(exportInterface, element.getAttribute(ID_ATTR),
            parserContext.getReaderContext().getResource().getDescription()));

    AbstractBeanDefinition beanDef = builder.getRawBeanDefinition();
    beanDef.setFactoryBeanName(rootName);
    beanDef.setFactoryMethodName("lookup");
    beanDef.setConstructorArgumentValues(constructorArgValues);
    beanDef.setLazyInit(true);
    beanDef.setScope(SCOPE_SINGLETON);
}

From source file:com.griddynamics.banshun.config.xml.ImportBeanDefinitionParser.java

/**
 * Creates arguments definition for the {@link Registry#lookup(String, Class) lookup()} method
 * of the registry bean.//from   www .j av a  2 s .  c  o m
 */
private ConstructorArgumentValues defineLookupMethodArgs(String serviceName, Class<?> serviceIface) {

    ConstructorArgumentValues holder = new ConstructorArgumentValues();
    holder.addIndexedArgumentValue(0, serviceName);
    holder.addIndexedArgumentValue(1, serviceIface);

    return holder;
}

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

/**
 * {@inheritDoc}//from   w  w  w .  j  a  v a2  s .co 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   w w  w.  j  a  va  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:com.griddynamics.banshun.xml.ExportBeanDefinitionParser.java

@Override
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
    BeanDefinitionRegistry registry = parserContext.getRegistry();

    String exportInterface = element.getAttribute(INTERFACE_ATTR);
    if (isBlank(exportInterface)) {
        return;//www.ja va 2s .c o  m
    }

    String exportBeanRef = element.getAttribute(REF_ATTR);
    if (isBlank(exportBeanRef)) {
        return;
    }

    String rootName = element.getAttribute(ROOT_ATTR);
    if (isBlank(rootName)) {
        rootName = DEFAULT_ROOT_FACTORY_NAME;
    }

    String exportName = element.getAttribute(NAME_ATTR);
    if (isBlank(exportName)) {
        exportName = exportBeanRef;
    }

    String exportRefName = exportName + BEAN_NAME_SUFFIX;
    if (registry.containsBeanDefinition(exportRefName)) {
        throw new BeanCreationException("Registry already contains bean with name: " + exportRefName);
    }

    ConstructorArgumentValues exportBeanConstructorArgValues = new ConstructorArgumentValues();
    exportBeanConstructorArgValues.addGenericArgumentValue(exportName);
    exportBeanConstructorArgValues.addGenericArgumentValue(findClass(exportInterface, exportBeanRef,
            parserContext.getReaderContext().getResource().getDescription()));

    AbstractBeanDefinition exportBeanDef = rootBeanDefinition(ExportRef.class).getRawBeanDefinition();
    exportBeanDef.setConstructorArgumentValues(exportBeanConstructorArgValues);

    ConstructorArgumentValues voidBeanConstructorArgValues = new ConstructorArgumentValues();
    voidBeanConstructorArgValues.addGenericArgumentValue(exportBeanDef, ExportRef.class.getName());

    AbstractBeanDefinition voidBeanDef = rootBeanDefinition(Void.class).getRawBeanDefinition();
    voidBeanDef.setFactoryBeanName(rootName);
    voidBeanDef.setFactoryMethodName("export");
    voidBeanDef.setLazyInit(false);
    voidBeanDef.setScope(SCOPE_SINGLETON);
    voidBeanDef.setConstructorArgumentValues(voidBeanConstructorArgValues);
    //        voidBeanDefinition.setDependsOn(new String[] { exportBeanRef }); TODO ?

    registry.registerBeanDefinition(exportRefName, voidBeanDef);
}

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

public void setProperty(String property, Object newValue) {
    if (PARENT.equals(property)) {
        setParent(newValue);/* ww w .ja va2s .  co  m*/
    } else {
        AbstractBeanDefinition bd = getBeanDefinition();
        if (AUTOWIRE.equals(property)) {
            if (BY_NAME.equals(newValue)) {
                bd.setAutowireMode(AutowireCapableBeanFactory.AUTOWIRE_BY_NAME);
            } else if (BY_TYPE.equals(newValue)) {
                bd.setAutowireMode(AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE);
            } else if (Boolean.TRUE.equals(newValue)) {
                bd.setAutowireMode(AutowireCapableBeanFactory.AUTOWIRE_BY_NAME);
            } else if (BY_CONSTRUCTOR.equals(newValue)) {
                bd.setAutowireMode(AutowireCapableBeanFactory.AUTOWIRE_CONSTRUCTOR);
            }
        }
        // constructorArgs
        else if (CONSTRUCTOR_ARGS.equals(property) && newValue instanceof List) {
            ConstructorArgumentValues cav = new ConstructorArgumentValues();
            List args = (List) newValue;
            for (Object e : args) {
                cav.addGenericArgumentValue(e);
            }
            bd.setConstructorArgumentValues(cav);
        }
        // destroyMethod
        else if (DESTROY_METHOD.equals(property)) {
            if (newValue != null)
                bd.setDestroyMethodName(newValue.toString());
        }
        // factoryBean
        else if (FACTORY_BEAN.equals(property)) {
            if (newValue != null)
                bd.setFactoryBeanName(newValue.toString());
        }
        // factoryMethod
        else if (FACTORY_METHOD.equals(property)) {
            if (newValue != null)
                bd.setFactoryMethodName(newValue.toString());
        }
        // initMethod
        else if (INIT_METHOD.equals(property)) {
            if (newValue != null)
                bd.setInitMethodName(newValue.toString());
        } else if (wrapper.isWritableProperty(property)) {

            wrapper.setPropertyValue(property, newValue);
        }
        // autowire
        else {
            super.setProperty(property, newValue);
        }
    }
}

From source file:com.griddynamics.banshun.config.xml.ExportBeanDefinitionParser.java

/**
 * Creates arguments definition for a constructor of the {@link ExportRef} class.
 *///from   w ww  . java2 s . c o  m
private ConstructorArgumentValues defineExportRefConstructorArgs(String serviceName, Class<?> serviceIface,
        String beanName) {

    ConstructorArgumentValues holder = new ConstructorArgumentValues();
    holder.addIndexedArgumentValue(0, serviceName);
    holder.addIndexedArgumentValue(1, serviceIface);
    holder.addIndexedArgumentValue(2, beanName);

    return holder;
}

From source file:org.jsr107.ri.annotations.spring.config.AnnotationDrivenJCacheBeanDefinitionParser.java

/**
 * Create a {@link CacheContextSourceImpl} bean that will be used by the advisor and interceptor
 *
 * @return Reference to the {@link CacheContextSourceImpl}. Should never be null.
 *///ww w  .j a  v a2s  .  c  o  m
protected RuntimeBeanReference setupCacheOperationSource(Element element, ParserContext parserContext,
        Object elementSource) {

    final RootBeanDefinition cacheAttributeSource = new RootBeanDefinition(CacheContextSourceImpl.class);
    cacheAttributeSource.setSource(elementSource);
    cacheAttributeSource.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);

    final RootBeanDefinition defaultCacheResolverFactory = new RootBeanDefinition(
            DefaultCacheResolverFactory.class);
    cacheAttributeSource.setSource(elementSource);
    cacheAttributeSource.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
    final String cacheManagerName = element.getAttribute(XSD_ATTR_CACHE_MANAGER);
    if (StringUtils.hasText(cacheManagerName)) {
        final RuntimeBeanReference cacheManagerReference = new RuntimeBeanReference(cacheManagerName);

        final ConstructorArgumentValues constructorArgumentValues = new ConstructorArgumentValues();
        constructorArgumentValues.addIndexedArgumentValue(0, cacheManagerReference);
        cacheAttributeSource.setConstructorArgumentValues(constructorArgumentValues);

    }

    final RootBeanDefinition defaultCacheKeyGenerator = new RootBeanDefinition(DefaultCacheKeyGenerator.class);
    cacheAttributeSource.setSource(elementSource);
    cacheAttributeSource.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);

    final MutablePropertyValues propertyValues = cacheAttributeSource.getPropertyValues();
    propertyValues.addPropertyValue("defaultCacheKeyGenerator", defaultCacheKeyGenerator);
    propertyValues.addPropertyValue("defaultCacheResolverFactory", defaultCacheResolverFactory);

    final BeanDefinitionRegistry registry = parserContext.getRegistry();
    registry.registerBeanDefinition(JCACHE_CACHE_OPERATION_SOURCE_BEAN_NAME, cacheAttributeSource);

    return new RuntimeBeanReference(JCACHE_CACHE_OPERATION_SOURCE_BEAN_NAME);
}

From source file:atunit.spring.SpringContainer.java

protected AbstractBeanDefinition defineInstanceHolderFactoryBean(Class<?> type, Object instance)
        throws Exception {
    ConstructorArgumentValues args = new ConstructorArgumentValues();
    args.addIndexedArgumentValue(0, type);
    args.addIndexedArgumentValue(1, instance);

    AbstractBeanDefinition beandef = BeanDefinitionReaderUtils.createBeanDefinition(null,
            InstanceHolderFactoryBean.class.getName(), getClass().getClassLoader());
    beandef.setConstructorArgumentValues(args);
    beandef.setAutowireCandidate(true);//from   w w w  .  j  a v a  2s  . c  o  m
    return beandef;
}

From source file:com.griddynamics.banshun.config.xml.ExportBeanDefinitionParser.java

/**
 * Creates arguments definition for the {@link Registry#export(ExportRef) export()} method
 * of the registry bean.//from   w  w  w .j  av  a 2 s.  co  m
 *
 * @param exportRef The definition of the {@link ExportRef} bean.
 */
private ConstructorArgumentValues defineExportMethodArgs(BeanDefinition exportRef) {

    ConstructorArgumentValues holder = new ConstructorArgumentValues();
    holder.addGenericArgumentValue(exportRef, ExportRef.class.getName());

    return holder;
}