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:fr.xebia.management.config.ProfileAspectDefinitionParser.java

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

    // see http://static.springsource.org/spring/docs/3.1.x/spring-framework-reference/html/aop.html#aop-aj-configure
    builder.setFactoryMethod("aspectOf");

    // Mark as infrastructure bean and attach source location.
    builder.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
    builder.getRawBeanDefinition().setSource(parserContext.extractSource(element));

    String serverBeanName = element.getAttribute(SERVER_ATTRIBUTE);
    if (StringUtils.hasText(serverBeanName)) {
        builder.addPropertyReference("server", serverBeanName);
    } else {// w  w  w  .j  a v a2  s  .  c o  m
        AbstractBeanDefinition specialServer = findServerForSpecialEnvironment();
        if (specialServer != null) {
            builder.addPropertyValue("server", specialServer);
        }
    }

    String jmxDomain = element.getAttribute(JMX_DOMAIN_ATTRIBUTE);
    if (StringUtils.hasLength(jmxDomain)) {
        builder.addPropertyValue("jmxDomain", jmxDomain);
    }
    return builder.getBeanDefinition();
}

From source file:org.xmatthew.spy2servers.component.config.ActiveMQJmxSpyComponentParser.java

protected void doParse(Element element, BeanDefinitionBuilder builder) {
    super.doParse(element, builder);

    Set destinationNames = null;//from  w  ww .ja  va  2  s . c  om
    Set llegalIps = null;

    NodeList childNodes = element.getChildNodes();
    for (int i = 0; i < childNodes.getLength(); i++) {
        Node child = childNodes.item(i);
        if (child.getNodeType() == Node.ELEMENT_NODE) {
            String localName = child.getLocalName();
            if (DESTINATION_NAMES_TO_WATCH_PROPERTY.equals(localName)) {
                destinationNames = IntegrationNamespaceUtils.parseDestinationNamesToWatch((Element) child);
            } else if (LLEGAL_IP_PROPERTY.equals(localName)) {
                llegalIps = IntegrationNamespaceUtils.parseLegalIps((Element) child);
            }
        }
    }

    if (destinationNames != null) {
        builder.addPropertyValue(DESTINATION_NAMES_TO_WATCH_PROPERTY, destinationNames);
    }
    if (llegalIps != null) {
        builder.addPropertyValue(LLEGAL_IP_PROPERTY, llegalIps);
    }

    builder.setScope(BeanDefinition.SCOPE_SINGLETON);
}

From source file:org.xmatthew.spy2servers.component.config.TomcatJmxSpyComponentParser.java

protected void doParse(Element element, BeanDefinitionBuilder builder) {
    super.doParse(element, builder);

    DataSourcesSpy dataSourcesSpy = null;
    WebModuleSpy webModuleSpy = null;/*from   w  w  w.  ja  v a  2s. c o m*/

    NodeList childNodes = element.getChildNodes();
    for (int i = 0; i < childNodes.getLength(); i++) {
        Node child = childNodes.item(i);
        if (child.getNodeType() == Node.ELEMENT_NODE) {
            String localName = child.getLocalName();
            if (DATASOURCES_SPY_PROPERTY.equals(localName)) {
                dataSourcesSpy = IntegrationNamespaceUtils.parseDataSourcesSpy((Element) child);
            } else if (WEB_MODULES_PROPERTY.equals(localName)) {
                webModuleSpy = IntegrationNamespaceUtils.parseWebModuleSpy((Element) child);
            }
        }
    }

    if (dataSourcesSpy != null) {
        builder.addPropertyValue(DATASOURCES_SPY_PROPERTY, dataSourcesSpy);
    }
    if (webModuleSpy != null) {
        builder.addPropertyValue(WEB_MODULES_PROPERTY, webModuleSpy);
    }
    builder.setScope(BeanDefinition.SCOPE_SINGLETON);
}

From source file:edu.internet2.middleware.shibboleth.common.config.attribute.resolver.dataConnector.StoredIDDataConnectorBeanDefinitionParser.java

/**
 * Processes the connection management configuration.
 * //w w  w  .  j  a  v  a2  s.  c  o m
 * @param pluginId ID of this data connector
 * @param pluginConfig configuration element for this data connector
 * @param pluginConfigChildren configuration elements for this connector
 * @param pluginBuilder bean definition builder
 * @param parserContext current configuration parsing context
 */
protected void processConnectionManagement(String pluginId, Element pluginConfig,
        Map<QName, List<Element>> pluginConfigChildren, BeanDefinitionBuilder pluginBuilder,
        ParserContext parserContext) {
    DataSource datasource;

    List<Element> cmc = pluginConfigChildren
            .get(new QName(DataConnectorNamespaceHandler.NAMESPACE, "ContainerManagedConnection"));
    if (cmc != null && cmc.get(0) != null) {
        datasource = buildContainerManagedConnection(pluginId, cmc.get(0));
    } else {
        datasource = buildApplicationManagedConnection(pluginId,
                pluginConfigChildren
                        .get(new QName(DataConnectorNamespaceHandler.NAMESPACE, "ApplicationManagedConnection"))
                        .get(0));
    }

    pluginBuilder.addPropertyValue("datasource", datasource);
}

From source file:edu.internet2.middleware.shibboleth.common.config.security.AbstractBasicCredentialBeanDefinitionParser.java

/**
 * Parses the public key from the credential configuration.
 * /*from   w ww. ja va2  s. c o  m*/
 * @param configChildren children of the credential element
 * @param builder credential build
 */
protected void parsePublicKey(Map<QName, List<Element>> configChildren, BeanDefinitionBuilder builder) {
    List<Element> keyElems = configChildren.get(new QName(SecurityNamespaceHandler.NAMESPACE, "PublicKey"));
    if (keyElems == null || keyElems.isEmpty()) {
        return;
    }

    log.debug("Parsing credential public key");
    Element pubKeyElem = keyElems.get(0);
    byte[] encodedKey = getEncodedPublicKey(DatatypeHelper.safeTrimOrNullString(pubKeyElem.getTextContent()));
    String keyPassword = DatatypeHelper.safeTrimOrNullString(pubKeyElem.getAttributeNS(null, "password"));
    char[] keyPasswordCharArray = null;
    if (keyPassword != null) {
        keyPasswordCharArray = keyPassword.toCharArray();
    }
    try {
        PublicKey pubKey = SecurityHelper.decodePublicKey(encodedKey, keyPasswordCharArray);
        builder.addPropertyValue("publicKey", pubKey);
    } catch (KeyException e) {
        throw new FatalBeanException("Unable to create credential, unable to parse public key", e);
    }
}

From source file:edu.internet2.middleware.shibboleth.common.config.security.AbstractCredentialBeanDefinitionParser.java

/**
 * Parses the private key from the credential configuration.
 * //from w w w  .  ja  v a 2  s. com
 * @param configChildren children of the credential element
 * @param builder credential build
 */
protected void parsePrivateKey(Map<QName, List<Element>> configChildren, BeanDefinitionBuilder builder) {
    List<Element> keyElems = configChildren.get(new QName(SecurityNamespaceHandler.NAMESPACE, "PrivateKey"));
    if (keyElems == null || keyElems.isEmpty()) {
        return;
    }

    log.debug("Parsing credential private key");
    Element privKeyElem = keyElems.get(0);
    byte[] encodedKey = getEncodedPrivateKey(DatatypeHelper.safeTrimOrNullString(privKeyElem.getTextContent()));
    String keyPassword = DatatypeHelper.safeTrimOrNullString(privKeyElem.getAttributeNS(null, "password"));
    char[] keyPasswordCharArray = null;
    if (keyPassword != null) {
        keyPasswordCharArray = keyPassword.toCharArray();
    }
    try {
        PrivateKey privKey = SecurityHelper.decodePrivateKey(encodedKey, keyPasswordCharArray);
        builder.addPropertyValue("privateKey", privKey);
    } catch (KeyException e) {
        throw new FatalBeanException("Unable to create credential, unable to parse private key", e);
    }
}

From source file:edu.internet2.middleware.shibboleth.common.config.attribute.resolver.dataConnector.LdapDataConnectorBeanDefinitionParser.java

/**
 * Process the LDAP result handling configuration for the LDAP data connector.
 * //from ww  w .j  av a2  s.co  m
 * @param pluginId ID of the LDAP plugin
 * @param pluginConfig LDAP plugin configuration element
 * @param pluginConfigChildren child elements of the plugin
 * @param pluginBuilder plugin builder
 * @param parserContext current parsing context
 */
protected void processResultHandlingConfig(String pluginId, Element pluginConfig,
        Map<QName, List<Element>> pluginConfigChildren, BeanDefinitionBuilder pluginBuilder,
        ParserContext parserContext) {
    int searchTimeLimit = 3000;
    if (pluginConfig.hasAttributeNS(null, "searchTimeLimit")) {
        searchTimeLimit = (int) SpringConfigurationUtils.parseDurationToMillis(
                "'searchTimeLimit' on data connector " + pluginId,
                pluginConfig.getAttributeNS(null, "searchTimeLimit"), 0);
    }
    log.debug("Data connector {} search timeout: {}ms", pluginId, searchTimeLimit);
    pluginBuilder.addPropertyValue("searchTimeLimit", searchTimeLimit);

    int maxResultSize = 1;
    if (pluginConfig.hasAttributeNS(null, "maxResultSize")) {
        maxResultSize = Integer.parseInt(pluginConfig.getAttributeNS(null, "maxResultSize"));
    }
    log.debug("Data connector {} max search result size: {}", pluginId, maxResultSize);
    pluginBuilder.addPropertyValue("maxResultSize", maxResultSize);

    boolean mergeResults = false;
    if (pluginConfig.hasAttributeNS(null, "mergeResults")) {
        mergeResults = XMLHelper
                .getAttributeValueAsBoolean(pluginConfig.getAttributeNodeNS(null, "mergeResults"));
    }
    log.debug("Data connector {} merge results: {}", pluginId, mergeResults);
    pluginBuilder.addPropertyValue("mergeResults", mergeResults);

    boolean noResultsIsError = false;
    if (pluginConfig.hasAttributeNS(null, "noResultIsError")) {
        noResultsIsError = XMLHelper
                .getAttributeValueAsBoolean(pluginConfig.getAttributeNodeNS(null, "noResultIsError"));
    }
    log.debug("Data connector {} no results is error: {}", pluginId, noResultsIsError);
    pluginBuilder.addPropertyValue("noResultsIsError", noResultsIsError);

    boolean lowercaseAttributeNames = false;
    if (pluginConfig.hasAttributeNS(null, "lowercaseAttributeNames")) {
        lowercaseAttributeNames = XMLHelper
                .getAttributeValueAsBoolean(pluginConfig.getAttributeNodeNS(null, "lowercaseAttributeNames"));
    }
    log.debug("Data connector {} will lower case attribute IDs: {}", pluginId, lowercaseAttributeNames);
    pluginBuilder.addPropertyValue("lowercaseAttributeNames", lowercaseAttributeNames);
}

From source file:edu.internet2.middleware.shibboleth.common.config.attribute.resolver.dataConnector.StoredIDDataConnectorBeanDefinitionParser.java

/** {@inheritDoc} */
protected void doParse(String pluginId, Element pluginConfig, Map<QName, List<Element>> pluginConfigChildren,
        BeanDefinitionBuilder pluginBuilder, ParserContext parserContext) {
    super.doParse(pluginId, pluginConfig, pluginConfigChildren, pluginBuilder, parserContext);

    processConnectionManagement(pluginId, pluginConfig, pluginConfigChildren, pluginBuilder, parserContext);

    long queryTimeout = 5 * 1000;
    if (pluginConfig.hasAttributeNS(null, "queryTimeout")) {
        queryTimeout = SpringConfigurationUtils.parseDurationToMillis(
                "queryTimeout on relational database connector " + pluginId,
                pluginConfig.getAttributeNS(null, "queryTimeout"), 0);
    }//  w  ww .j  a v a 2s.com
    log.debug("Data connector {} SQL query timeout: {}ms", queryTimeout);
    pluginBuilder.addPropertyValue("queryTimeout", queryTimeout);

    String generatedAttributeId = "storedId";
    if (pluginConfig.hasAttributeNS(null, "generatedAttributeID")) {
        generatedAttributeId = DatatypeHelper
                .safeTrimOrNullString(pluginConfig.getAttributeNS(null, "generatedAttributeID"));
    }
    pluginBuilder.addPropertyValue("generatedAttribute", generatedAttributeId);
    log.debug("Data connector {} generated attribute ID: {}", pluginId, generatedAttributeId);

    String sourceAttribute = DatatypeHelper
            .safeTrimOrNullString(pluginConfig.getAttributeNS(null, "sourceAttributeID"));
    log.debug("Data connector {} source attribute ID: {}", pluginId, sourceAttribute);
    pluginBuilder.addPropertyValue("sourceAttribute", sourceAttribute);

    String salt = DatatypeHelper.safeTrimOrNullString(pluginConfig.getAttributeNS(null, "salt"));
    log.debug("Data connector {} salt: {}", pluginId, salt);
    pluginBuilder.addPropertyValue("salt", salt.getBytes());
}

From source file:edu.internet2.middleware.shibboleth.common.config.security.saml.IssueInstantRuleBeanDefinitionParser.java

/** {@inheritDoc} */
protected void doParse(Element element, BeanDefinitionBuilder builder) {
    long skew = 300;
    if (element.hasAttributeNS(null, "clockSkew")) {
        skew = SpringConfigurationUtils.parseDurationToMillis(
                "'clockSkew' on security rule of type " + XMLHelper.getXSIType(element),
                element.getAttributeNS(null, "clockSkew"), 1000) / 1000;
    }//w  w  w . j a  v  a 2  s. com
    builder.addConstructorArgValue(skew);

    long expirationThreshold = 60;
    if (element.hasAttributeNS(null, "expirationThreshold")) {
        expirationThreshold = SpringConfigurationUtils.parseDurationToMillis(
                "'expirationThreshold' on security rule of type " + XMLHelper.getXSIType(element),
                element.getAttributeNS(null, "expirationThreshold"), 1000) / 1000;
    }
    builder.addConstructorArgValue(expirationThreshold);

    if (element.hasAttributeNS(null, "required")) {
        builder.addPropertyValue("requiredRule",
                XMLHelper.getAttributeValueAsBoolean(element.getAttributeNodeNS(null, "required")));
    } else {
        builder.addPropertyValue("requiredRule", true);
    }
}

From source file:it.pronetics.madstore.common.configuration.spring.MadStoreConfigurationBeanDefinitionParser.java

private void parseJcrConfiguration(Element repositoryElement, BeanDefinitionBuilder beanDefinitionBuilder)
        throws DOMException {
    JcrConfiguration jcrConfiguration = new JcrConfiguration();
    String madStoreDir = MadStoreConfigurationManager.getInstance().getMadStoreHome();
    String jcrDir = new StringBuilder(madStoreDir).append(SEPARATOR).append(DEFAULT_JCR_FOLDER).toString();
    jcrConfiguration.setHomeDir(jcrDir);
    jcrConfiguration.setUsername("");
    jcrConfiguration.setPassword("".toCharArray());
    Integer maxHistory = Integer
            .valueOf(DomUtils.getChildElementByTagName(repositoryElement, JCR_MAX_HISTORY).getTextContent());
    jcrConfiguration.setMaxHistory(maxHistory);
    beanDefinitionBuilder.addPropertyValue(JCR_CONFIGURATION_BEAN_PROPERTY, jcrConfiguration);
}