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

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

Introduction

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

Prototype

public BeanDefinitionBuilder addPropertyValue(String name, @Nullable Object value) 

Source Link

Document

Add the supplied property value under the given property name.

Usage

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

private String createCounter(ParserContext context, Element element, CounterConfig config) {
    String name = getName(context, element);

    if (config.getContentionType() == ContentionType.UNKNOWN) {
        context.getReaderContext().error("Unknown concurrency type.", context.extractSource(element));
        return null;
    }/*from w w  w  .  j a va  2s  . c om*/
    if (config.getDurationType() == DurationType.UNKNOWN) {
        context.getReaderContext().error("Unknown duration type.", context.extractSource(element));
        return null;
    }
    if (config.getIntervalsType() == IntervalsType.UNKNOWN) {
        context.getReaderContext().error("Unknown intervals type.", context.extractSource(element));
        return null;
    }

    // Create bean definition for the mutator factory
    String mutatorFactoryId;
    switch (config.getDurationType()) {
    case NA:
    case UNBOUNDED:
        mutatorFactoryId = createUnboundedMutatorFactory(context, element, config);
        break;
    case WINDOWED:
        mutatorFactoryId = createWindowedMutatorFactory(context, element, config);
        break;
    default:
        context.getReaderContext().error("Unexpected duration type.", context.extractSource(element));
        return null;
    }

    if (mutatorFactoryId == null) {
        // Something went wrong creating the factory
        return null;
    }

    // Create bean definition for accumulator
    String accumulatorClass;
    switch (config.getContentionType()) {
    case HIGH:
    case NA:
        accumulatorClass = HC_ACCUMULATOR_CLASS;
        break;
    case LOW:
        accumulatorClass = LC_ACCUMULATOR_CLASS;
        break;
    default:
        context.getReaderContext().error("Unexpected concurrency type.", context.extractSource(element));
        return null;
    }
    BeanDefinitionBuilder accBdb = getBdb(accumulatorClass);
    accBdb.addConstructorArgReference(mutatorFactoryId);
    String accBeanId = context.getReaderContext().registerWithGeneratedName(accBdb.getBeanDefinition());

    // Create proxy that carries name
    BeanDefinitionBuilder accProxyBdb = getBdb(RegistryNodeChildProxy.class);
    accProxyBdb.addPropertyValue(NAME_ATTR, name);
    accProxyBdb.addPropertyValue(CHILD_ATTR, accBeanId);
    return context.getReaderContext().registerWithGeneratedName(accProxyBdb.getBeanDefinition());
}

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

private BeanDefinition createLogoutHandler() {
    BeanDefinitionBuilder builder = createBean(SecurityContextLogoutHandler.class);
    builder.addPropertyValue("invalidateHttpSession", "true");
    return builder.getBeanDefinition();
}

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

private BeanDefinition createAuthenticationProvider() {
    BeanDefinitionBuilder builder = createBean(SAMLAuthenticationProvider.class);
    builder.addPropertyValue("userDetails", parseUserDetailsService());
    builder.addPropertyValue("consumer", createProfileConsumer());
    builder.addPropertyValue("hokConsumer", createHokProfileConsumer());
    builder.addPropertyValue("samlLogger", logger);
    return builder.getBeanDefinition();
}

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

private BeanDefinition createLogoutSuccessHandler() {
    BeanDefinitionBuilder builder = createBean(SimpleUrlLogoutSuccessHandler.class);
    builder.addPropertyValue("defaultTargetUrl", "/");
    return builder.getBeanDefinition();
}

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

protected String parseCustom(ParserContext context, Element element, BeanDefinition containingBean) {
    String name = getName(context, element);
    String ref = element.getAttribute(REF_ATTR);

    String customBeanId = null;/*from w w w.ja  va2s  .  co m*/
    if (StringUtils.hasLength(ref)) {
        customBeanId = ref;
    } else {
        // Grab the single child element, that should define or point
        // to the custom Accumulator or Calcuation bean definition.
        NodeList childList = element.getChildNodes();
        Element child = null;
        for (int i = 0; i < childList.getLength(); i++) {
            Node childNode = childList.item(i);
            if (!(childNode instanceof Element)) {
                continue;
            }

            if (child != null) {
                context.getReaderContext()
                        .error("'custom' elements without a 'ref' attribute must "
                                + "have exactly one 'bean', 'ref', or 'idref' child" + " element.",
                                context.extractSource(element));
            }
            child = (Element) childNode;
        }

        if (child == null) {
            context.getReaderContext()
                    .error("'custom' elements must specify a 'ref' attribute or a "
                            + "single 'bean', 'ref', or 'idref' child element.",
                            context.extractSource(element));
        }

        // Parse the contents of the custom bean
        Object o = context.getDelegate().parsePropertySubElement(child, containingBean);

        if (o instanceof BeanDefinitionHolder) {
            BeanDefinitionHolder bdh = (BeanDefinitionHolder) o;
            customBeanId = bdh.getBeanName();
            if (!StringUtils.hasLength(customBeanId)) {
                // They didn't give their bean an id, so we'll need to
                // generate one for it now.
                customBeanId = context.getReaderContext().generateBeanName(bdh.getBeanDefinition());
            }

            // Register this bean
            context.getRegistry().registerBeanDefinition(customBeanId, bdh.getBeanDefinition());
        } else if (o instanceof RuntimeBeanReference) {
            RuntimeBeanReference rbr = (RuntimeBeanReference) o;
            customBeanId = rbr.getBeanName();
        } else if (o instanceof RuntimeBeanNameReference) {
            RuntimeBeanNameReference rbnr = (RuntimeBeanNameReference) o;
            customBeanId = rbnr.getBeanName();
        }
    }

    // Create proxy that associates the given name with this child
    BeanDefinitionBuilder accProxyBdb = getBdb(RegistryNodeChildProxy.class);
    accProxyBdb.addPropertyValue(NAME_ATTR, name);
    accProxyBdb.addPropertyValue(CHILD_ATTR, customBeanId);
    accProxyBdb.getRawBeanDefinition().setSource(element);

    return context.getReaderContext().registerWithGeneratedName(accProxyBdb.getBeanDefinition());
}

From source file:com.frank.search.solr.repository.config.SolrRepositoryConfigExtension.java

@Override
public void postProcess(BeanDefinitionBuilder builder, AnnotationRepositoryConfigurationSource config) {

    AnnotationAttributes attributes = config.getAttributes();
    if (!attributes.getBoolean("multicoreSupport")) {
        builder.addPropertyReference(BeanDefinition.SOLR_OPERATIONS.getBeanName(),
                attributes.getString("solrTemplateRef"));
    } else {/*from   w w w  .j  a va2 s.  c o  m*/
        builder.addPropertyReference(BeanDefinition.SOLR_CLIENT.getBeanName(),
                attributes.getString("solrClientRef"));
    }
    builder.addPropertyValue("schemaCreationSupport", attributes.getBoolean("schemaCreationSupport"));
    builder.addPropertyReference(BeanDefinition.SOLR_MAPPTING_CONTEXT.getBeanName(), "solrMappingContext");
}

From source file:edu.internet2.middleware.shibboleth.idp.config.profile.authn.AbstractLoginHandlerBeanDefinitionParser.java

/** {@inheritDoc} */
protected void doParse(Element config, BeanDefinitionBuilder builder) {
    log.debug("Parsing configuration for {} authentication handler.",
            XMLHelper.getXSIType(config).getLocalPart());

    long duration = 30 * 60 * 1000;
    if (config.hasAttributeNS(null, "authenticationDuration")) {
        duration = SpringConfigurationUtils.parseDurationToMillis(
                "'authenticationDuration' on LoginHandler of type " + XMLHelper.getXSIType(config),
                config.getAttributeNS(null, "authenticationDuration"), 1000 * 60);
    }//from  w  w w  .jav a 2s .  com
    log.debug("Authentication duration: {}ms", duration);
    builder.addPropertyValue("authenticationDuration", duration);

    String authnMethod;
    ArrayList<String> authnMethods = new ArrayList<String>();
    List<Element> authnMethodElems = XMLHelper.getChildElementsByTagNameNS(config,
            ProfileHandlerNamespaceHandler.NAMESPACE, "AuthenticationMethod");
    for (Element authnMethodElem : authnMethodElems) {
        authnMethod = DatatypeHelper.safeTrimOrNullString(authnMethodElem.getTextContent());
        log.debug("Authentication handler declared support for authentication method {}", authnMethod);
        authnMethods.add(authnMethod);
    }
    builder.addPropertyValue("authenticationMethods", authnMethods);
}

From source file:org.drools.container.spring.namespace.ResourceDefinitionParser.java

@SuppressWarnings("unchecked")
@Override/*from   w w w.j  a  va  2  s .  co  m*/
protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) {
    BeanDefinitionBuilder factory = BeanDefinitionBuilder.rootBeanDefinition(DroolsResourceAdapter.class);

    if (StringUtils.hasText(element.getAttribute(REF))) {
        String ref = element.getAttribute(REF);
        emptyAttributeCheck(element.getLocalName(), REF, ref);
        return (AbstractBeanDefinition) parserContext.getRegistry().getBeanDefinition(ref);
    }

    String source = element.getAttribute(SOURCE_ATTRIBUTE);
    emptyAttributeCheck(element.getLocalName(), SOURCE_ATTRIBUTE, source);
    factory.addPropertyValue("resource", source);

    String type = element.getAttribute(TYPE_ATTRIBUTE);

    String resourceType = type == null || type.length() == 0 ? ResourceType.DRL.getName() : type;

    factory.addPropertyValue("resourceType", resourceType);

    boolean basicAuthenticationEnabled = element.getAttribute(BASIC_AUTHENTICATION_ATTRIBUTE) != null
            && element.getAttribute(BASIC_AUTHENTICATION_ATTRIBUTE).equalsIgnoreCase("enabled");
    factory.addPropertyValue("basicAuthenticationEnabled", basicAuthenticationEnabled);

    if (basicAuthenticationEnabled) {
        String username = element.getAttribute(USERNAME_ATTRIBUTE);
        factory.addPropertyValue("basicAuthenticationUsername", username);

        String password = element.getAttribute(PASSWORD_ATTRIBUTE);
        factory.addPropertyValue("basicAuthenticationPassword", password);
    }

    String name = element.getAttribute(NAME);
    factory.addPropertyValue("name", org.drools.core.util.StringUtils.isEmpty(name) ? null : name);

    String description = element.getAttribute(DESCRIPTION);
    factory.addPropertyValue("description",
            org.drools.core.util.StringUtils.isEmpty(description) ? null : description);

    if ("xsd".equals(resourceType.toLowerCase())) {
        XsdParser.parse(element, parserContext, factory);
    } else if ("dtable".equals(resourceType.toLowerCase())) {
        List<Element> childElements = DomUtils.getChildElementsByTagName(element, "decisiontable-conf");
        if (!childElements.isEmpty()) {
            Element conf = childElements.get(0);
            DecisionTableConfigurationImpl dtableConf = new DecisionTableConfigurationImpl();

            String inputType = conf.getAttribute(INPUT_TYPE_ATTRIBUTE);
            emptyAttributeCheck(conf.getLocalName(), INPUT_TYPE_ATTRIBUTE, inputType);
            dtableConf.setInputType(DecisionTableInputType.valueOf(inputType));

            String worksheetName = conf.getAttribute(WORKSHEET_NAME_ATTRIBUTE);
            emptyAttributeCheck(conf.getLocalName(), WORKSHEET_NAME_ATTRIBUTE, worksheetName);
            dtableConf.setWorksheetName(worksheetName);

            factory.addPropertyValue("resourceConfiguration", dtableConf);
        }
    }

    return factory.getBeanDefinition();
}

From source file:edu.internet2.middleware.shibboleth.common.config.service.AbstractReloadableServiceBeanDefinitionParser.java

/** {@inheritDoc} */
protected void doParse(Element configElement, ParserContext parserContext, BeanDefinitionBuilder builder) {
    super.doParse(configElement, parserContext, builder);

    if (configElement.hasAttributeNS(null, "configurationResourcePollingFrequency")) {
        builder.addPropertyReference("pollingTimer", configElement.getAttributeNS(null, "timerId"));

        long frequency = SpringConfigurationUtils.parseDurationToMillis(
                "'configurationResourcePollingFrequency' on service "
                        + configElement.getAttributeNS(null, "id"),
                configElement.getAttributeNS(null, "configurationResourcePollingFrequency"), 1);
        builder.addPropertyValue("pollingFrequency", frequency);
        log.debug("{} service configuration polling frequency: {}ms", getServiceId(configElement), frequency);

        int retryAttempts = 0;
        if (configElement.hasAttributeNS(null, "configurationResourcePollingRetryAttempts")) {
            retryAttempts = Integer.parseInt(DatatypeHelper.safeTrimOrNullString(
                    configElement.getAttributeNS(null, "configurationResourcePollingRetryAttempts")));
        }/*  w  w  w . j a va2s. c  o  m*/
        if (retryAttempts < 1) {
            retryAttempts = 3;
        }
        builder.addPropertyValue("pollingRetryAttempts", retryAttempts);
        log.debug("{} service configuration polling retry attempts: {}", getServiceId(configElement),
                retryAttempts);
    }
}

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

private BeanDefinition createAuthenticationManager(BeanDefinition authenticationProvider) {
    List<BeanDefinition> list = new ManagedList<BeanDefinition>();
    list.add(authenticationProvider);/* w  w  w  .  j  a  va2 s.c om*/
    BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(ProviderManager.class);
    builder.addPropertyValue("providers", list);
    return registerBean(builder, SPRING_AUTH_MANAGER_ID);
}