List of usage examples for org.springframework.util.xml DomUtils getChildElementByTagName
@Nullable public static Element getChildElementByTagName(Element ele, String childEleName)
From source file:org.springframework.data.gemfire.config.ParsingUtils.java
private static boolean parseCustomExpiration(Element rootElement, ParserContext parserContext, String elementName, String propertyName, BeanDefinitionBuilder regionAttributesBuilder) { Element expirationElement = DomUtils.getChildElementByTagName(rootElement, elementName); if (expirationElement != null) { Object customExpiry = parseRefOrSingleNestedBeanDeclaration(parserContext, expirationElement, regionAttributesBuilder); regionAttributesBuilder.addPropertyValue(propertyName, customExpiry); return true; }//from w w w . j a v a 2s . com return false; }
From source file:org.springframework.data.gemfire.config.ParsingUtils.java
public static void parseCompressor(ParserContext parserContext, Element element, BeanDefinitionBuilder regionAttributesBuilder) { Element compressorElement = DomUtils.getChildElementByTagName(element, "compressor"); if (compressorElement != null) { regionAttributesBuilder.addPropertyValue("compressor", parseRefOrSingleNestedBeanDeclaration( parserContext, compressorElement, regionAttributesBuilder)); }//from w w w . j av a 2s . c o m }
From source file:org.springframework.data.gemfire.config.xml.ParsingUtils.java
static void parseCompressor(ParserContext parserContext, Element element, BeanDefinitionBuilder regionAttributesBuilder) { Element compressorElement = DomUtils.getChildElementByTagName(element, "compressor"); if (compressorElement != null) { regionAttributesBuilder.addPropertyValue("compressor", parseRefOrSingleNestedBeanDeclaration( parserContext, compressorElement, regionAttributesBuilder)); }/*from w w w. j a v a2 s. c om*/ }
From source file:org.springframework.data.jdbc.config.oracle.PoolingDataSourceBeanDefinitionParser.java
protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) { //ToDo look for username-connection-proxy boolean useWrapper = false; String connectionContextProviderRef = null; Element usernameConnectionProxyElement = DomUtils.getChildElementByTagName(element, USERNAME_CONNECTION_PROXY);/*from ww w . j a v a 2 s . com*/ if (usernameConnectionProxyElement != null) { if (logger.isDebugEnabled()) { logger.debug("Using username-connection-proxy"); } if (usernameConnectionProxyElement.hasAttribute(CONNECTION_CONTEXT_PROVIDER)) { if (logger.isDebugEnabled()) { logger.debug(CONNECTION_CONTEXT_PROVIDER + ": " + usernameConnectionProxyElement.getAttribute(CONNECTION_CONTEXT_PROVIDER)); } connectionContextProviderRef = usernameConnectionProxyElement .getAttribute(CONNECTION_CONTEXT_PROVIDER); } useWrapper = true; //builder.addPropertyValue("connectionProperties", connProperties); } BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(); builder.getRawBeanDefinition().setBeanClassName(getBeanClassName(element)); builder.getRawBeanDefinition().setSource(parserContext.extractSource(element)); builder.getRawBeanDefinition().setDestroyMethodName("close"); if (parserContext.isNested()) { // Inner bean definition must receive same scope as containing bean. builder.setScope(parserContext.getContainingBeanDefinition().getScope()); } if (parserContext.isDefaultLazyInit()) { // Default-lazy-init applies to custom bean definitions as well. builder.setLazyInit(true); } doParse(element, parserContext, builder); if (useWrapper) { BeanDefinitionBuilder wrapper = BeanDefinitionBuilder.genericBeanDefinition(); wrapper.getRawBeanDefinition() .setBeanClassName("org.springframework.data.jdbc.support.oracle.ProxyDataSource"); wrapper.addConstructorArgValue(builder.getBeanDefinition()); if (connectionContextProviderRef == null) { wrapper.addConstructorArgValue(null); } else { wrapper.addConstructorArgReference(connectionContextProviderRef); } return wrapper.getBeanDefinition(); } else { return builder.getBeanDefinition(); } }
From source file:org.springframework.integration.config.xml.PointToPointChannelParser.java
@Override protected BeanDefinitionBuilder buildBeanDefinition(Element element, ParserContext parserContext) { BeanDefinitionBuilder builder = null; Element queueElement = null;/*from w w w .j av a2s. c o m*/ // configure a queue-based channel if any queue sub-element is defined if ((queueElement = DomUtils.getChildElementByTagName(element, "queue")) != null) { builder = BeanDefinitionBuilder.genericBeanDefinition(QueueChannel.class); boolean hasStoreRef = this.parseStoreRef(builder, queueElement, element.getAttribute(ID_ATTRIBUTE)); boolean hasQueueRef = this.parseQueueRef(builder, queueElement); if (!hasStoreRef) { boolean hasCapacity = this.parseQueueCapacity(builder, queueElement); if (hasCapacity && hasQueueRef) { parserContext.getReaderContext().error("The 'capacity' attribute is not allowed" + " when providing a 'ref' to a custom queue.", element); } } if (hasStoreRef && hasQueueRef) { parserContext.getReaderContext().error("The 'message-store' attribute is not allowed" + " when providing a 'ref' to a custom queue.", element); } } else if ((queueElement = DomUtils.getChildElementByTagName(element, "priority-queue")) != null) { builder = BeanDefinitionBuilder.genericBeanDefinition(PriorityChannel.class); this.parseQueueCapacity(builder, queueElement); String comparatorRef = queueElement.getAttribute("comparator"); if (StringUtils.hasText(comparatorRef)) { builder.addConstructorArgReference(comparatorRef); } } else if ((queueElement = DomUtils.getChildElementByTagName(element, "rendezvous-queue")) != null) { builder = BeanDefinitionBuilder.genericBeanDefinition(RendezvousChannel.class); } Element dispatcherElement = DomUtils.getChildElementByTagName(element, "dispatcher"); // check for the dispatcher attribute (deprecated) String dispatcherAttribute = element.getAttribute("dispatcher"); boolean hasDispatcherAttribute = StringUtils.hasText(dispatcherAttribute); if (hasDispatcherAttribute && logger.isWarnEnabled()) { logger.warn("The 'dispatcher' attribute on the 'channel' element is deprecated. " + "Please use the 'dispatcher' sub-element instead."); } // verify that a dispatcher is not provided if a queue sub-element exists if (queueElement != null && (dispatcherElement != null || hasDispatcherAttribute)) { parserContext.getReaderContext().error("The 'dispatcher' attribute or sub-element " + "and any queue sub-element are mutually exclusive.", element); return null; } if (queueElement != null) { return builder; } if (dispatcherElement != null && hasDispatcherAttribute) { parserContext.getReaderContext() .error("The 'dispatcher' attribute and 'dispatcher' " + "sub-element are mutually exclusive. NOTE: the attribute is DEPRECATED. " + "Please use the dispatcher sub-element instead.", element); return null; } if (hasDispatcherAttribute) { // this attribute is deprecated, but if set, we need to create a DirectChannel // without any LoadBalancerStrategy and the failover flag set to true (default). builder = BeanDefinitionBuilder.genericBeanDefinition(DirectChannel.class); if ("failover".equals(dispatcherAttribute)) { // round-robin dispatcher is used by default, the "failover" value simply disables it builder.addConstructorArgValue(null); } } else if (dispatcherElement == null) { // configure the default DirectChannel with a RoundRobinLoadBalancingStrategy builder = BeanDefinitionBuilder.genericBeanDefinition(DirectChannel.class); String maxSubscribers = this.getDefaultMaxSubscribers(parserContext, IntegrationNamespaceUtils.DEFAULT_MAX_UNICAST_SUBSCRIBERS_PROPERTY_NAME); if (maxSubscribers != null) { builder.addPropertyValue("maxSubscribers", maxSubscribers); } } else { // configure either an ExecutorChannel or DirectChannel based on existence of 'task-executor' String taskExecutor = dispatcherElement.getAttribute("task-executor"); if (StringUtils.hasText(taskExecutor)) { builder = BeanDefinitionBuilder.genericBeanDefinition(ExecutorChannel.class); builder.addConstructorArgReference(taskExecutor); } else { builder = BeanDefinitionBuilder.genericBeanDefinition(DirectChannel.class); } // unless the 'load-balancer' attribute is explicitly set to 'none', // configure the default RoundRobinLoadBalancingStrategy String loadBalancer = dispatcherElement.getAttribute("load-balancer"); if ("none".equals(loadBalancer)) { builder.addConstructorArgValue(null); } IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, dispatcherElement, "failover"); this.setMaxSubscribersProperty(parserContext, builder, dispatcherElement, IntegrationNamespaceUtils.DEFAULT_MAX_UNICAST_SUBSCRIBERS_PROPERTY_NAME); } return builder; }
From source file:org.springframework.integration.kafka.config.xml.KafkaProducerContextParser.java
@Override protected void doParse(final Element element, final ParserContext parserContext, final BeanDefinitionBuilder builder) { super.doParse(element, parserContext, builder); IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "phase"); IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "auto-startup"); final Element topics = DomUtils.getChildElementByTagName(element, "producer-configurations"); parseProducerConfigurations(topics, parserContext, builder, element); }
From source file:org.springframework.ldap.config.ContextSourceParser.java
private BeanDefinition applyPoolingIfApplicable(BeanDefinition targetContextSourceDefinition, Element element, boolean nativePooling) { Element poolingElement = DomUtils.getChildElementByTagName(element, Elements.POOLING); Element pooling2Element = DomUtils.getChildElementByTagName(element, Elements.POOLING2); if (pooling2Element != null && poolingElement != null) { throw new IllegalArgumentException( String.format("%s cannot be enabled together with %s.", Elements.POOLING2, Elements.POOLING)); } else if (poolingElement == null && pooling2Element == null) { return targetContextSourceDefinition; }/*from ww w.jav a 2 s . c o m*/ if (nativePooling) { throw new IllegalArgumentException( String.format("%s cannot be enabled together with %s", ATT_NATIVE_POOLING, Elements.POOLING)); } if (pooling2Element != null) { BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(PooledContextSource.class); builder.addPropertyValue("contextSource", targetContextSourceDefinition); populatePoolConfigProperties(builder, pooling2Element); boolean testOnBorrow = getBoolean(pooling2Element, ATT_TEST_ON_BORROW, false); boolean testOnReturn = getBoolean(pooling2Element, ATT_TEST_ON_RETURN, false); boolean testWhileIdle = getBoolean(pooling2Element, ATT_TEST_WHILE_IDLE, false); boolean testOnCreate = getBoolean(pooling2Element, ATT_TEST_ON_CREATE, false); if (testOnBorrow || testOnCreate || testWhileIdle || testOnReturn) { populatePoolValidationProperties(builder, pooling2Element); } return builder.getBeanDefinition(); } else { BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(PoolingContextSource.class); builder.addPropertyValue("contextSource", targetContextSourceDefinition); builder.addPropertyValue("maxActive", getString(poolingElement, ATT_MAX_ACTIVE, String.valueOf(DEFAULT_MAX_ACTIVE))); builder.addPropertyValue("maxTotal", getString(poolingElement, ATT_MAX_TOTAL, String.valueOf(DEFAULT_MAX_TOTAL))); builder.addPropertyValue("maxIdle", getString(poolingElement, ATT_MAX_IDLE, String.valueOf(DEFAULT_MAX_IDLE))); builder.addPropertyValue("minIdle", getString(poolingElement, ATT_MIN_IDLE, String.valueOf(DEFAULT_MIN_IDLE))); builder.addPropertyValue("maxWait", getString(poolingElement, ATT_MAX_WAIT, String.valueOf(DEFAULT_MAX_WAIT))); String whenExhausted = getString(poolingElement, ATT_WHEN_EXHAUSTED, PoolExhaustedAction.BLOCK.name()); builder.addPropertyValue("whenExhaustedAction", PoolExhaustedAction.valueOf(whenExhausted).getValue()); builder.addPropertyValue("timeBetweenEvictionRunsMillis", getString(poolingElement, ATT_EVICTION_RUN_MILLIS, String.valueOf(DEFAULT_EVICTION_RUN_MILLIS))); builder.addPropertyValue("minEvictableIdleTimeMillis", getString(poolingElement, ATT_EVICTABLE_TIME_MILLIS, String.valueOf(DEFAULT_EVICTABLE_MILLIS))); builder.addPropertyValue("numTestsPerEvictionRun", getString(poolingElement, ATT_TESTS_PER_EVICTION_RUN, String.valueOf(DEFAULT_TESTS_PER_EVICTION_RUN))); boolean testOnBorrow = getBoolean(poolingElement, ATT_TEST_ON_BORROW, false); boolean testOnReturn = getBoolean(poolingElement, ATT_TEST_ON_RETURN, false); boolean testWhileIdle = getBoolean(poolingElement, ATT_TEST_WHILE_IDLE, false); if (testOnBorrow || testOnReturn || testWhileIdle) { populatePoolValidationProperties(builder, poolingElement, testOnBorrow, testOnReturn, testWhileIdle); } return builder.getBeanDefinition(); } }
From source file:org.springframework.orm.jpa.persistenceunit.PersistenceUnitReader.java
/** * Parse the unit info DOM element./*www . ja v a 2 s .c o m*/ */ protected SpringPersistenceUnitInfo parsePersistenceUnitInfo(Element persistenceUnit, String version, @Nullable URL rootUrl) throws IOException { SpringPersistenceUnitInfo unitInfo = new SpringPersistenceUnitInfo(); // set JPA version (1.0 or 2.0) unitInfo.setPersistenceXMLSchemaVersion(version); // set persistence unit root URL unitInfo.setPersistenceUnitRootUrl(rootUrl); // set unit name unitInfo.setPersistenceUnitName(persistenceUnit.getAttribute(UNIT_NAME).trim()); // set transaction type String txType = persistenceUnit.getAttribute(TRANSACTION_TYPE).trim(); if (StringUtils.hasText(txType)) { unitInfo.setTransactionType(PersistenceUnitTransactionType.valueOf(txType)); } // evaluate data sources String jtaDataSource = DomUtils.getChildElementValueByTagName(persistenceUnit, JTA_DATA_SOURCE); if (StringUtils.hasText(jtaDataSource)) { unitInfo.setJtaDataSource(this.dataSourceLookup.getDataSource(jtaDataSource.trim())); } String nonJtaDataSource = DomUtils.getChildElementValueByTagName(persistenceUnit, NON_JTA_DATA_SOURCE); if (StringUtils.hasText(nonJtaDataSource)) { unitInfo.setNonJtaDataSource(this.dataSourceLookup.getDataSource(nonJtaDataSource.trim())); } // provider String provider = DomUtils.getChildElementValueByTagName(persistenceUnit, PROVIDER); if (StringUtils.hasText(provider)) { unitInfo.setPersistenceProviderClassName(provider.trim()); } // exclude unlisted classes Element excludeUnlistedClasses = DomUtils.getChildElementByTagName(persistenceUnit, EXCLUDE_UNLISTED_CLASSES); if (excludeUnlistedClasses != null) { String excludeText = DomUtils.getTextValue(excludeUnlistedClasses); unitInfo.setExcludeUnlistedClasses(!StringUtils.hasText(excludeText) || Boolean.valueOf(excludeText)); } // set JPA 2.0 shared cache mode String cacheMode = DomUtils.getChildElementValueByTagName(persistenceUnit, SHARED_CACHE_MODE); if (StringUtils.hasText(cacheMode)) { unitInfo.setSharedCacheMode(SharedCacheMode.valueOf(cacheMode)); } // set JPA 2.0 validation mode String validationMode = DomUtils.getChildElementValueByTagName(persistenceUnit, VALIDATION_MODE); if (StringUtils.hasText(validationMode)) { unitInfo.setValidationMode(ValidationMode.valueOf(validationMode)); } parseProperties(persistenceUnit, unitInfo); parseManagedClasses(persistenceUnit, unitInfo); parseMappingFiles(persistenceUnit, unitInfo); parseJarFiles(persistenceUnit, unitInfo); return unitInfo; }
From source file:org.springframework.orm.jpa.persistenceunit.PersistenceUnitReader.java
/** * Parse the {@code property} XML elements. *//*from w w w .j a va 2 s . co m*/ protected void parseProperties(Element persistenceUnit, SpringPersistenceUnitInfo unitInfo) { Element propRoot = DomUtils.getChildElementByTagName(persistenceUnit, PROPERTIES); if (propRoot == null) { return; } List<Element> properties = DomUtils.getChildElementsByTagName(propRoot, "property"); for (Element property : properties) { String name = property.getAttribute("name"); String value = property.getAttribute("value"); unitInfo.addProperty(name, value); } }
From source file:org.springframework.security.config.http.AuthenticationConfigBuilder.java
void createRememberMeFilter(BeanReference authenticationManager) { // Parse remember me before logout as RememberMeServices is also a LogoutHandler // implementation. Element rememberMeElt = DomUtils.getChildElementByTagName(httpElt, Elements.REMEMBER_ME); if (rememberMeElt != null) { String key = rememberMeElt.getAttribute(ATT_KEY); if (!StringUtils.hasText(key)) { key = createKey();//www . j av a 2s. c o m } RememberMeBeanDefinitionParser rememberMeParser = new RememberMeBeanDefinitionParser(key, authenticationManager); rememberMeFilter = rememberMeParser.parse(rememberMeElt, pc); rememberMeServicesId = rememberMeParser.getRememberMeServicesId(); createRememberMeProvider(key); } }