List of usage examples for org.springframework.beans.factory.support BeanDefinitionBuilder addPropertyValue
public BeanDefinitionBuilder addPropertyValue(String name, @Nullable Object value)
From source file:com.alibaba.citrus.service.form.impl.FormServiceDefinitionParser.java
@Override protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder formServiceBuilder) { // bean attributes parseBeanDefinitionAttributes(element, parserContext, formServiceBuilder); // injecting HttpServletRequest in constructor, required=true addConstructorArg(formServiceBuilder, true, HttpServletRequest.class); // new FormConfigImp() BeanDefinitionBuilder formConfigBuilder = BeanDefinitionBuilder.genericBeanDefinition(FormConfigImpl.class); attributesToProperties(element, formConfigBuilder, "converterQuiet", "postOnlyByDefault", "messageCodePrefix"); // import forms ElementSelector importSelector = and(sameNs(element), name("import")); List<Object> imports = createManagedList(element, parserContext); for (Element subElement : subElements(element, importSelector)) { String formRef = assertNotNull(trimToNull(subElement.getAttribute("form")), "import form is empty"); imports.add(new RuntimeBeanReference(formRef)); }/*from w ww. jav a 2s.c o m*/ formConfigBuilder.addPropertyValue("imports", imports); // registrars formConfigBuilder.addPropertyValue("propertyEditorRegistrars", parseRegistrars(element, parserContext, formConfigBuilder)); // groups List<Object> groups = createManagedList(element, parserContext); for (Element subElement : subElements(element, and(sameNs(element), name("group")))) { groups.add(parseGroup(subElement, parserContext, formConfigBuilder)); } formConfigBuilder.addPropertyValue("groupConfigImplList", groups); formServiceBuilder.addPropertyValue("formConfigImpl", formConfigBuilder.getBeanDefinition()); }
From source file:com.consol.citrus.selenium.xml.ExtractActionParser.java
/** * @param element//from ww w .j a v a 2 s .c o m * @param parserContext * @return */ @Override public BeanDefinition parse(Element element, ParserContext parserContext) { actionClass = ExtractAction.class; BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(actionClass); this.doParse(element, builder); String pageName = element.getAttribute("pageName"); BeanDefinitionParserUtils.setPropertyValue(builder, pageName, "pageName"); Map<By, ExtractDefinition.Element> elements = new LinkedHashMap<>(); List<Element> webElements = DomUtils.getChildElementsByTagName(element, "element"); for (Element webElement : webElements) { By by = getByFromElement(webElement); ExtractDefinition.Element el = new ExtractDefinition.Element(); el.setVariable(webElement.getAttribute("variable")); el.setAttribute(webElement.getAttribute("attribute")); elements.put(by, el); } builder.addPropertyValue("elements", elements); Map<String, String> pageActions = new LinkedHashMap<>(); List<Element> pageElements = DomUtils.getChildElementsByTagName(element, "page"); for (Element pageElement : pageElements) { String pageAction = pageElement.getAttribute("get"); String value = pageElement.getAttribute("variable"); pageActions.put(pageAction, value); } builder.addPropertyValue("pageActions", pageActions); return builder.getBeanDefinition(); }
From source file:de.itsvs.cwtrpc.controller.config.RemoteServiceGroupConfigBeanDefinitionParser.java
protected AbstractBeanDefinition createServiceConfigBeanDefinition(Element element, ParserContext parserContext) {/*w w w . j a v a2s .c o m*/ final String serviceName; final BeanDefinitionBuilder bdd; final String relativePath; serviceName = element.getAttribute(XmlNames.SERVICE_REF_ATTR); if (!StringUtils.hasText(serviceName)) { parserContext.getReaderContext().error("Service reference must not be empty", parserContext.extractSource(element)); } bdd = BeanDefinitionBuilder.rootBeanDefinition(RemoteServiceConfig.class); if (parserContext.isDefaultLazyInit()) { bdd.setLazyInit(true); } bdd.getRawBeanDefinition().setSource(parserContext.extractSource(element)); bdd.addConstructorArgValue(serviceName); if (element.hasAttribute(XmlNames.SERVICE_INTERFACE_ATTR)) { bdd.addPropertyValue("serviceInterface", element.getAttribute(XmlNames.SERVICE_INTERFACE_ATTR)); } if (element.hasAttribute(XmlNames.RELATIVE_PATH_ATTR)) { relativePath = element.getAttribute(XmlNames.RELATIVE_PATH_ATTR); if (!StringUtils.hasText(relativePath)) { parserContext.getReaderContext().error("Relative path must not be empty", parserContext.extractSource(element)); } bdd.addPropertyValue("relativePath", relativePath); } getBaseServiceConfigParser().update(element, parserContext, bdd); return bdd.getBeanDefinition(); }
From source file:it.pronetics.madstore.common.configuration.spring.MadStoreConfigurationBeanDefinitionParser.java
private void parseOsConfiguration(Element serverElement, BeanDefinitionBuilder beanDefinitionBuilder) throws DOMException { Element osConfigurationElement = DomUtils.getChildElementByTagName(serverElement, OS_CONFIGURATION_TAG); OpenSearchConfiguration openSearchConfiguration = new OpenSearchConfiguration(); openSearchConfiguration.setShortName( DomUtils.getChildElementByTagName(osConfigurationElement, SHORT_NAME).getTextContent()); openSearchConfiguration.setDescription( DomUtils.getChildElementByTagName(osConfigurationElement, DESCRIPTION).getTextContent()); beanDefinitionBuilder.addPropertyValue(OS_CONFIGURATION_BEAN_PROPERTY, openSearchConfiguration); }
From source file:org.xmatthew.spy2servers.component.config.EmailAlertComponentParser.java
protected void doParse(Element element, BeanDefinitionBuilder builder) { super.doParse(element, builder); EmailAccount emailAccount = null;/*w ww .j a va2s. c o m*/ Set emails = 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 (EMAIL_ACCOUNT_PROPERTY.equals(localName)) { emailAccount = IntegrationNamespaceUtils.parseEmailAccount((Element) child); } else if (EMAILS_PROPERTY.equals(localName)) { emails = IntegrationNamespaceUtils.parseEmails((Element) child); } } } if (emails != null) { builder.addPropertyValue(EMAILS_PROPERTY, emails); } if (emailAccount == null) { throw new RuntimeException("emailAccount must set in beans defination <emailAlert />"); } builder.addPropertyValue(EMAIL_ACCOUNT_PROPERTY, emailAccount); builder.setScope(BeanDefinition.SCOPE_SINGLETON); }
From source file:org.apache.smscserver.config.spring.MessageManagerBeanDefinitionParser.java
@Override protected void doParse(final Element element, final ParserContext parserContext, final BeanDefinitionBuilder builder) { Class<?> factoryClass = DBMessageManagerFactory.class; BeanDefinitionBuilder factoryBuilder = BeanDefinitionBuilder.genericBeanDefinition(factoryClass); Element dsElm = SpringUtil.getChildElement(element, SmscServerNamespaceHandler.SMSCSERVER_NS, "data-source"); if (dsElm != null) { // schema ensure we get the right type of element Element springElm = SpringUtil.getChildElement(dsElm, null, null); Object o;/* w ww.ja va 2 s. co m*/ if ("bean".equals(springElm.getLocalName())) { o = parserContext.getDelegate().parseBeanDefinitionElement(springElm, builder.getBeanDefinition()); } else { // ref o = parserContext.getDelegate().parsePropertySubElement(springElm, builder.getBeanDefinition()); } factoryBuilder.addPropertyValue("dataSource", o); } factoryBuilder.addPropertyValue("embeddedProfile", this.getChildElement(element, "embedded-profile")); factoryBuilder.addPropertyValue("URL", this.getChildElement(element, "url")); factoryBuilder.addPropertyValue("sqlCreateTable", this.getChildElement(element, "crate-table")); factoryBuilder.addPropertyValue("sqlInsertMessage", this.getChildElement(element, "insert-message")); factoryBuilder.addPropertyValue("sqlSelectMessage", this.getChildElement(element, "select-message")); factoryBuilder.addPropertyValue("sqlSelectUserMessage", this.getChildElement(element, "select-user-message")); factoryBuilder.addPropertyValue("sqlSelectLatestReplacableMessage", this.getChildElement(element, "select-replace")); factoryBuilder.addPropertyValue("sqlUpdateMessage", this.getChildElement(element, "update-message")); BeanDefinition factoryDefinition = factoryBuilder.getBeanDefinition(); String factoryId = parserContext.getReaderContext().generateBeanName(factoryDefinition); BeanDefinitionHolder factoryHolder = new BeanDefinitionHolder(factoryDefinition, factoryId); this.registerBeanDefinition(factoryHolder, parserContext.getRegistry()); // set the factory on the listener bean builder.getRawBeanDefinition().setFactoryBeanName(factoryId); builder.getRawBeanDefinition().setFactoryMethodName("createMessageManager"); }
From source file:com.ryantenney.metrics.spring.reporter.AbstractReporterElementParser.java
protected void addDefaultProperties(Element element, BeanDefinitionBuilder beanDefBuilder) { final Map<String, String> properties = new HashMap<String, String>(); final NamedNodeMap attributes = element.getAttributes(); for (int i = 0; i < attributes.getLength(); i++) { final Node attribute = attributes.item(i); final String name = attribute.getNodeName(); if (name.equals(METRIC_REGISTRY_REF) || name.equals(ID) || name.equals(TYPE)) { continue; }//from w w w . j a va 2 s. co m properties.put(name, attribute.getNodeValue()); } validate(properties); beanDefBuilder.addPropertyReference("metricRegistry", element.getAttribute(METRIC_REGISTRY_REF)); beanDefBuilder.addPropertyValue("properties", properties); }
From source file:com.googlecode.jsonrpc4j.spring.AutoJsonRpcServiceExporter.java
/** * Registers the new beans with the bean factory. *//*from ww w .j a v a2s. c o m*/ private void registerServiceProxy(DefaultListableBeanFactory dlbf, String servicePath, String serviceBeanName) { BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(JsonServiceExporter.class) .addPropertyReference("service", serviceBeanName); BeanDefinition serviceBeanDefinition = findBeanDefintion(dlbf, serviceBeanName); for (Class<?> iface : getBeanInterfaces(serviceBeanDefinition, dlbf.getBeanClassLoader())) { if (iface.isAnnotationPresent(JsonRpcService.class)) { String serviceInterface = iface.getName(); LOG.fine(format("Registering interface '%s' for JSON-RPC bean [%s].", serviceInterface, serviceBeanName)); builder.addPropertyValue("serviceInterface", serviceInterface); break; } } if (objectMapper != null) { builder.addPropertyValue("objectMapper", objectMapper); } if (errorResolver != null) { builder.addPropertyValue("errorResolver", errorResolver); } if (invocationListener != null) { builder.addPropertyValue("invocationListener", invocationListener); } if (registerTraceInterceptor != null) { builder.addPropertyValue("registerTraceInterceptor", registerTraceInterceptor); } builder.addPropertyValue("backwardsComaptible", Boolean.valueOf(backwardsComaptible)); builder.addPropertyValue("rethrowExceptions", Boolean.valueOf(rethrowExceptions)); builder.addPropertyValue("allowExtraParams", Boolean.valueOf(allowExtraParams)); builder.addPropertyValue("allowLessParams", Boolean.valueOf(allowLessParams)); builder.addPropertyValue("exceptionLogLevel", exceptionLogLevel); dlbf.registerBeanDefinition(servicePath, builder.getBeanDefinition()); }
From source file:edu.internet2.middleware.shibboleth.common.config.attribute.resolver.dataConnector.LdapDataConnectorBeanDefinitionParser.java
/** * Process the LDAP connection security configuration for the LDAP data connector. * /*from www. j a v a 2s .c o 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 processSecurityConfig(String pluginId, Element pluginConfig, Map<QName, List<Element>> pluginConfigChildren, BeanDefinitionBuilder pluginBuilder, ParserContext parserContext) { RuntimeBeanReference trustCredential = processCredential( pluginConfigChildren .get(new QName(DataConnectorNamespaceHandler.NAMESPACE, "StartTLSTrustCredential")), parserContext); if (trustCredential != null) { log.debug("Data connector {} using provided SSL/TLS trust material", pluginId); pluginBuilder.addPropertyValue("trustCredential", trustCredential); } RuntimeBeanReference connectionCredential = processCredential( pluginConfigChildren.get( new QName(DataConnectorNamespaceHandler.NAMESPACE, "StartTLSAuthenticationCredential")), parserContext); if (connectionCredential != null) { log.debug("Data connector {} using provided SSL/TLS client authentication material", pluginId); pluginBuilder.addPropertyValue("connectionCredential", connectionCredential); } boolean useStartTLS = false; if (pluginConfig.hasAttributeNS(null, "useStartTLS")) { useStartTLS = XMLHelper .getAttributeValueAsBoolean(pluginConfig.getAttributeNodeNS(null, "useStartTLS")); } log.debug("Data connector {} use startTLS: {}", pluginId, useStartTLS); pluginBuilder.addPropertyValue("useStartTLS", useStartTLS); }
From source file:edu.internet2.middleware.shibboleth.common.config.attribute.resolver.dataConnector.LdapDataConnectorBeanDefinitionParser.java
/** * Process the pooling configuration for the LDAP data connector. * /*from w w w. j a v a2 s .com*/ * @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 processPoolingConfig(String pluginId, Element pluginConfig, Map<QName, List<Element>> pluginConfigChildren, BeanDefinitionBuilder pluginBuilder, ParserContext parserContext) { List<Element> poolConfigElems = pluginConfigChildren .get(new QName(DataConnectorNamespaceHandler.NAMESPACE, "ConnectionPool")); if (poolConfigElems == null || poolConfigElems.size() == 0) { log.debug("Data connector {} is pooling connections: {}", pluginId, false); pluginBuilder.addPropertyValue("poolStrategy", new LdapPoolEmptyStrategy()); return; } Element poolConfigElem = poolConfigElems.get(0); LdapPoolConfig ldapPoolConfig = new LdapPoolConfig(); LdapPoolVTStrategy ldapPoolStrategy = new LdapPoolVTStrategy(); ldapPoolStrategy.setLdapPoolConfig(ldapPoolConfig); log.debug("Data connector {} is pooling connections: {}", pluginId, true); pluginBuilder.addPropertyValue("poolStrategy", ldapPoolStrategy); int poolMinSize = 0; if (pluginConfig.hasAttributeNS(null, "poolInitialSize")) { poolMinSize = Integer.parseInt(pluginConfig.getAttributeNS(null, "poolInitialSize")); log.warn( "Data connector {} using deprecated attribute poolInitialSize on <DataConnector> use minPoolSize on child <PoolConfig> instead"); } else if (poolConfigElem != null && poolConfigElem.hasAttributeNS(null, "minPoolSize")) { poolMinSize = Integer.parseInt(poolConfigElem.getAttributeNS(null, "minPoolSize")); } log.debug("Data connector {} pool minimum connections: {}", pluginId, poolMinSize); ldapPoolConfig.setMinPoolSize(poolMinSize); int poolMaxSize = 3; if (pluginConfig.hasAttributeNS(null, "poolMaxIdleSize")) { poolMaxSize = Integer.parseInt(pluginConfig.getAttributeNS(null, "poolMaxIdleSize")); log.warn( "Data connector {} using deprecated attribute poolMaxIdleSize on <DataConnector> use maxPoolSize on child <PoolConfig> instead"); } else if (poolConfigElem != null && poolConfigElem.hasAttributeNS(null, "maxPoolSize")) { poolMaxSize = Integer.parseInt(poolConfigElem.getAttributeNS(null, "maxPoolSize")); } log.debug("Data connector {} pool maximum connections: {}", pluginId, poolMaxSize); ldapPoolConfig.setMaxPoolSize(poolMaxSize); boolean blockWhenEmpty = true; if (poolConfigElem != null && poolConfigElem.hasAttributeNS(null, "blockWhenEmpty")) { blockWhenEmpty = XMLHelper .getAttributeValueAsBoolean(poolConfigElem.getAttributeNodeNS(null, "blockWhenEmpty")); } log.debug("Data connector {} pool block when empty: {}", pluginId, blockWhenEmpty); ldapPoolStrategy.setBlockWhenEmpty(blockWhenEmpty); int blockWaitTime = 0; if (poolConfigElem != null && poolConfigElem.hasAttributeNS(null, "blockWaitTime")) { blockWaitTime = (int) SpringConfigurationUtils.parseDurationToMillis("blockWaitTime", poolConfigElem.getAttributeNS(null, "blockWaitTime"), 0); } if (blockWaitTime == 0) { log.debug("Data connector {} pool block wait time: indefintely", pluginId); } else { log.debug("Data connector {} pool block wait time: {}ms", pluginId, blockWaitTime); } ldapPoolStrategy.setBlockWaitTime(blockWaitTime); boolean poolValidatePeriodically = false; if (poolConfigElem != null && poolConfigElem.hasAttributeNS(null, "validatePeriodically")) { poolValidatePeriodically = XMLHelper .getAttributeValueAsBoolean(poolConfigElem.getAttributeNodeNS(null, "validatePeriodically")); } log.debug("Data connector {} pool validate periodically: {}", pluginId, poolValidatePeriodically); ldapPoolConfig.setValidatePeriodically(poolValidatePeriodically); int poolValidateTimerPeriod = 1800000; if (poolConfigElem != null && poolConfigElem.hasAttributeNS(null, "validateTimerPeriod")) { poolValidateTimerPeriod = (int) SpringConfigurationUtils.parseDurationToMillis("validateTimerPeriod", poolConfigElem.getAttributeNS(null, "validateTimerPeriod"), 0); } log.debug("Data connector {} pool validate timer period: {}ms", pluginId, poolValidateTimerPeriod); ldapPoolConfig.setValidateTimerPeriod(poolValidateTimerPeriod); String poolValidateDn = ""; if (poolConfigElem != null && poolConfigElem.hasAttributeNS(null, "validateDN")) { poolValidateDn = poolConfigElem.getAttributeNS(null, "validateDN"); } String poolValidateFilter = "(objectClass=*)"; if (poolConfigElem != null && poolConfigElem.hasAttributeNS(null, "validateFilter")) { poolValidateFilter = poolConfigElem.getAttributeNS(null, "validateFilter"); } LdapValidator poolValidator = new CompareLdapValidator(poolValidateDn, new SearchFilter(poolValidateFilter)); log.debug("Data connector {} pool validation filter: {}", pluginId, poolValidateFilter); pluginBuilder.addPropertyValue("poolValidator", poolValidator); int poolExpirationTime = 600000; if (poolConfigElem != null && poolConfigElem.hasAttributeNS(null, "expirationTime")) { poolExpirationTime = (int) SpringConfigurationUtils.parseDurationToMillis("expirationTime", poolConfigElem.getAttributeNS(null, "expirationTime"), 0); } log.debug("Data connector {} pool expiration time: {}ms", pluginId, poolExpirationTime); ldapPoolConfig.setExpirationTime(poolExpirationTime); }