Example usage for org.springframework.beans.factory.support BeanDefinitionBuilder getBeanDefinition

List of usage examples for org.springframework.beans.factory.support BeanDefinitionBuilder getBeanDefinition

Introduction

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

Prototype

public AbstractBeanDefinition getBeanDefinition() 

Source Link

Document

Validate and return the created BeanDefinition object.

Usage

From source file:org.urbantower.j4s.spring.HandlerCollectionParser.java

@Override
protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) {
    BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(HandlerCollection.class);

    List<Element> handlerElms = DomUtils.getChildElements(element);
    List<Object> handlerDefs = new ManagedList<>();
    for (Element elm : handlerElms) {
        if ("handler".equals(elm.getLocalName())) {
            RuntimeBeanReference reference = new RuntimeBeanReference(elm.getAttribute("ref"));
            handlerDefs.add(reference);/*  w w  w .  j  a va  2 s.  c  o  m*/
        } else {
            BeanDefinition handlerDef = parserContext.getDelegate().parseCustomElement(elm,
                    builder.getBeanDefinition());
            handlerDefs.add(handlerDef);
        }
    }

    builder.addPropertyValue("handlers", handlerDefs);
    return builder.getBeanDefinition();
}

From source file:com.cloudseal.spring.client.namespace.CloudSealBeanDefinitionParserInstance.java

private BeanDefinition registerBean(BeanDefinitionBuilder beanBuilder, String beanID) {
    return registerBean(beanBuilder.getBeanDefinition(), beanID);
}

From source file:net.shibboleth.idp.profile.spring.relyingparty.metadata.impl.AbstractDynamicHTTPMetadataProviderParser.java

/**
 * Build the POJO with the username and password.
 * /* www.  j  a v a  2 s. c  o  m*/
 * @param element the HTTPMetadataProvider parser.
 * @return the bean definition with the username and password.
 */
private BeanDefinition buildBasicCredentials(Element element) {
    BeanDefinitionBuilder builder = BeanDefinitionBuilder
            .genericBeanDefinition(UsernamePasswordCredentials.class);

    builder.setLazyInit(true);

    builder.addConstructorArgValue(StringSupport.trimOrNull(element.getAttributeNS(null, BASIC_AUTH_USER)));
    builder.addConstructorArgValue(StringSupport.trimOrNull(element.getAttributeNS(null, BASIC_AUTH_PASSWORD)));

    return builder.getBeanDefinition();
}

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

/**
 * {@inheritDoc}/* w w  w . j  a v a  2s  .  co m*/
 */
@Override
protected @Nullable 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");
    // this will never be null since the schema explicitly requires that a
    // value be supplied
    String testCaseName = element.getAttribute(XsdElementConstants.ATTR_TESTCASE_TESTCASENAME);
    BeanDefinitionBuilder factory = BeanDefinitionBuilder.rootBeanDefinition(TestCase.class);
    if (StringUtils.hasText(testCaseName))
        factory.addConstructorArgValue(testCaseName);

    List<Element> testStepElements = (List<Element>) DomUtils.getChildElements(element);

    if (testStepElements != null && !testStepElements.isEmpty()) {
        if (null == factory)
            throw GlobalUtils.createNotInitializedException("factory");
        parseTestStepComponents(testStepElements, factory, parserContext);
    }

    return factory.getBeanDefinition();
}

From source file:org.jdal.beans.DefaultsBeanDefinitionParser.java

/**
 * @return/*  w  ww .ja  v  a  2  s  .  c om*/
 */
private ComponentDefinition registerPropertyEditors(Element element, ParserContext parserContext) {
    BeanDefinitionBuilder bdb = BeanDefinitionBuilder.genericBeanDefinition(CustomEditorConfigurer.class);
    Map<String, String> map = new HashMap<String, String>();
    map.put("java.awt.Image", "org.jdal.beans.ImagePropertyEditor");
    map.put("javax.swing.Icon", "org.jdal.beans.IconPropertyEditor");
    bdb.addPropertyValue("customEditors", map);
    BeanComponentDefinition bcd = new BeanComponentDefinition(bdb.getBeanDefinition(),
            CUSTOM_EDITOR_CONFIGURER_BEAN_NAME);
    registerBeanComponentDefinition(element, parserContext, bcd);
    return bcd;
}

From source file:com.dangdang.ddframe.rdb.sharding.spring.namespace.parser.ShardingJdbcDataSourceBeanDefinitionParser.java

private List<BeanDefinition> parseBindingTablesConfig(final Element element) {
    Element bindingTableRulesElement = DomUtils.getChildElementByTagName(element,
            ShardingJdbcDataSourceBeanDefinitionParserTag.BINDING_TABLE_RULES_TAG);
    if (null == bindingTableRulesElement) {
        return Collections.emptyList();
    }//  w  w w  .j a  v  a2  s . c  o m
    List<Element> bindingTableRuleElements = DomUtils.getChildElementsByTagName(bindingTableRulesElement,
            ShardingJdbcDataSourceBeanDefinitionParserTag.BINDING_TABLE_RULE_TAG);
    BeanDefinitionBuilder bindingTableRuleFactory = BeanDefinitionBuilder
            .rootBeanDefinition(BindingTableRuleConfig.class);
    List<BeanDefinition> result = new ManagedList<>(bindingTableRuleElements.size());
    for (Element bindingTableRuleElement : bindingTableRuleElements) {
        bindingTableRuleFactory.addPropertyValue("tableNames", bindingTableRuleElement
                .getAttribute(ShardingJdbcDataSourceBeanDefinitionParserTag.LOGIC_TABLES_ATTRIBUTE));
        result.add(bindingTableRuleFactory.getBeanDefinition());
    }
    return result;
}

From source file:org.ff4j.spring.namespace.FF4jBeanDefinitionParser.java

/** {@inheritDoc} **/
protected void postProcess(final BeanDefinitionBuilder definitionBuilder, final Element ff4jTag) {
    super.postProcess(definitionBuilder, ff4jTag);
    logger.debug("Initialization from <ff4j:ff4j> TAG");
    // If filename is present ff4j will be initialized with both features and properties inmemory.
    if (StringUtils.hasLength(ff4jTag.getAttribute(ATT_FF4J_FILENAME))) {
        String fileName = ff4jTag.getAttribute(ATT_FF4J_FILENAME);
        InMemoryFeatureStore imfs = new InMemoryFeatureStore(fileName);
        InMemoryPropertyStore imps = new InMemoryPropertyStore(fileName);
        definitionBuilder.getBeanDefinition().getPropertyValues().addPropertyValue("featureStore", imfs);
        definitionBuilder.getBeanDefinition().getPropertyValues().addPropertyValue("propertiesStore", imps);
        logger.debug("... Setting in-memory stores : " + imfs.readAll().size() + " feature(s), "
                + imps.readAllProperties().size() + " propertie(s)");
    }/*w  w w .j  av a 2s  .  c o  m*/

    if (StringUtils.hasLength(ff4jTag.getAttribute(ATT_FF4J_AUTOCREATE))) {
        String autocreate = ff4jTag.getAttribute(ATT_FF4J_AUTOCREATE);
        logger.debug("... Setting autocreate property to '" + autocreate + "'");
    }

    if (StringUtils.hasLength(ff4jTag.getAttribute(ATT_FF4J_AUTH_MANAGER))) {
        String authManagerBeanId = ff4jTag.getAttribute(ATT_FF4J_AUTH_MANAGER);
        RuntimeBeanReference refSolution = new RuntimeBeanReference(authManagerBeanId);
        definitionBuilder.getBeanDefinition().getPropertyValues().addPropertyValue("authorizationsManager",
                refSolution);
        logger.debug("... Setting authorizationManager with " + authManagerBeanId);
    }

    logger.debug("... Initialization done");

}

From source file:org.smf4j.spring.RegistryNodeTemplateDefinitionParser.java

private String createUnboundedMutatorFactory(ParserContext context, Element element, CounterConfig config) {
    String mutatorFactoryClass;/*from   w ww  . j  a  v  a  2  s.c  o m*/
    // We need to create unbounded mutators
    switch (config.getCounterType()) {
    case ADD:
        mutatorFactoryClass = (config.getContentionType() == ContentionType.HIGH)
                ? HC_UNBOUNDED_ADD_MUTATOR_CLASS
                : LC_UNBOUNDED_ADD_MUTATOR_CLASS;
        break;
    case MIN:
        mutatorFactoryClass = (config.getContentionType() == ContentionType.HIGH)
                ? HC_UNBOUNDED_MIN_MUTATOR_CLASS
                : LC_UNBOUNDED_MIN_MUTATOR_CLASS;
        break;
    case MAX:
        mutatorFactoryClass = (config.getContentionType() == ContentionType.HIGH)
                ? HC_UNBOUNDED_MAX_MUTATOR_CLASS
                : LC_UNBOUNDED_MAX_MUTATOR_CLASS;
        break;
    default:
        context.getReaderContext().error("Unexpected counter type.", context.extractSource(element));
        return null;
    }
    BeanDefinitionBuilder mutatorFactoryBdb = getBdb(mutatorFactoryClass);
    return context.getReaderContext().registerWithGeneratedName(mutatorFactoryBdb.getBeanDefinition());
}

From source file:io.fabric8.spring.boot.AbstractServiceRegistar.java

private <S, T> BeanDefinitionHolder createConverterBean(Class type, String methodName, Class<S> sourceType,
        Class<T> targetType) {

    BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(FactoryConverter.class);

    String beanName = type.getName() + "." + methodName;
    builder.addPropertyValue("name", methodName);
    builder.addPropertyValue("type", type.getCanonicalName());
    builder.addPropertyValue("sourceType", sourceType.getCanonicalName());
    builder.addPropertyValue("targetType", targetType.getCanonicalName());

    builder.setAutowireMode(Autowire.BY_TYPE.value());
    return new BeanDefinitionHolder(builder.getBeanDefinition(), beanName);
}