Java Code Examples for org.springframework.util.xml.DomUtils#getChildElementValueByTagName()

The following examples show how to use org.springframework.util.xml.DomUtils#getChildElementValueByTagName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractJndiLocatingBeanDefinitionParser.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Override
protected void postProcess(BeanDefinitionBuilder definitionBuilder, Element element) {
	Object envValue = DomUtils.getChildElementValueByTagName(element, ENVIRONMENT);
	if (envValue != null) {
		// Specific environment settings defined, overriding any shared properties.
		definitionBuilder.addPropertyValue(JNDI_ENVIRONMENT, envValue);
	}
	else {
		// Check whether there is a reference to shared environment properties...
		String envRef = element.getAttribute(ENVIRONMENT_REF);
		if (StringUtils.hasLength(envRef)) {
			definitionBuilder.addPropertyValue(JNDI_ENVIRONMENT, new RuntimeBeanReference(envRef));
		}
	}

	String lazyInit = element.getAttribute(LAZY_INIT_ATTRIBUTE);
	if (StringUtils.hasText(lazyInit) && !DEFAULT_VALUE.equals(lazyInit)) {
		definitionBuilder.setLazyInit(TRUE_VALUE.equals(lazyInit));
	}
}
 
Example 2
Source File: AbstractJndiLocatingBeanDefinitionParser.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Override
protected void postProcess(BeanDefinitionBuilder definitionBuilder, Element element) {
	Object envValue = DomUtils.getChildElementValueByTagName(element, ENVIRONMENT);
	if (envValue != null) {
		// Specific environment settings defined, overriding any shared properties.
		definitionBuilder.addPropertyValue(JNDI_ENVIRONMENT, envValue);
	}
	else {
		// Check whether there is a reference to shared environment properties...
		String envRef = element.getAttribute(ENVIRONMENT_REF);
		if (StringUtils.hasLength(envRef)) {
			definitionBuilder.addPropertyValue(JNDI_ENVIRONMENT, new RuntimeBeanReference(envRef));
		}
	}

	String lazyInit = element.getAttribute(LAZY_INIT_ATTRIBUTE);
	if (StringUtils.hasText(lazyInit) && !DEFAULT_VALUE.equals(lazyInit)) {
		definitionBuilder.setLazyInit(TRUE_VALUE.equals(lazyInit));
	}
}
 
Example 3
Source File: AbstractJndiLocatingBeanDefinitionParser.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected void postProcess(BeanDefinitionBuilder definitionBuilder, Element element) {
	Object envValue = DomUtils.getChildElementValueByTagName(element, ENVIRONMENT);
	if (envValue != null) {
		// Specific environment settings defined, overriding any shared properties.
		definitionBuilder.addPropertyValue(JNDI_ENVIRONMENT, envValue);
	}
	else {
		// Check whether there is a reference to shared environment properties...
		String envRef = element.getAttribute(ENVIRONMENT_REF);
		if (StringUtils.hasLength(envRef)) {
			definitionBuilder.addPropertyValue(JNDI_ENVIRONMENT, new RuntimeBeanReference(envRef));
		}
	}

	String lazyInit = element.getAttribute(LAZY_INIT_ATTRIBUTE);
	if (StringUtils.hasText(lazyInit) && !DEFAULT_VALUE.equals(lazyInit)) {
		definitionBuilder.setLazyInit(TRUE_VALUE.equals(lazyInit));
	}
}
 
Example 4
Source File: AbstractJndiLocatingBeanDefinitionParser.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Override
protected void postProcess(BeanDefinitionBuilder definitionBuilder, Element element) {
	Object envValue = DomUtils.getChildElementValueByTagName(element, ENVIRONMENT);
	if (envValue != null) {
		// Specific environment settings defined, overriding any shared properties.
		definitionBuilder.addPropertyValue(JNDI_ENVIRONMENT, envValue);
	}
	else {
		// Check whether there is a reference to shared environment properties...
		String envRef = element.getAttribute(ENVIRONMENT_REF);
		if (StringUtils.hasLength(envRef)) {
			definitionBuilder.addPropertyValue(JNDI_ENVIRONMENT, new RuntimeBeanReference(envRef));
		}
	}

	String lazyInit = element.getAttribute(LAZY_INIT_ATTRIBUTE);
	if (StringUtils.hasText(lazyInit) && !DEFAULT_VALUE.equals(lazyInit)) {
		definitionBuilder.setLazyInit(TRUE_VALUE.equals(lazyInit));
	}
}
 
Example 5
Source File: PersistenceUnitReader.java    From spring-analysis-note with MIT License 4 votes vote down vote up
/**
 * Parse the unit info DOM element.
 */
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;
}
 
Example 6
Source File: PersistenceUnitReader.java    From java-technology-stack with MIT License 4 votes vote down vote up
/**
 * Parse the unit info DOM element.
 */
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;
}
 
Example 7
Source File: PersistenceUnitReader.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Parse the unit info DOM element.
 */
protected SpringPersistenceUnitInfo parsePersistenceUnitInfo(Element persistenceUnit, String version, 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;
}
 
Example 8
Source File: PersistenceUnitReader.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
/**
 * Parse the unit info DOM element.
 */
protected SpringPersistenceUnitInfo parsePersistenceUnitInfo(Element persistenceUnit, String version, 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;
}