Java Code Examples for org.springframework.core.convert.converter.ConditionalConverter

The following examples show how to use org.springframework.core.convert.converter.ConditionalConverter. These examples are extracted from open source projects. 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 Project: spring-analysis-note   Source File: GenericConversionService.java    License: MIT License 6 votes vote down vote up
@Nullable
private GenericConverter getRegisteredConverter(TypeDescriptor sourceType,
		TypeDescriptor targetType, ConvertiblePair convertiblePair) {

	// Check specifically registered converters
	ConvertersForPair convertersForPair = this.converters.get(convertiblePair);
	if (convertersForPair != null) {
		GenericConverter converter = convertersForPair.getConverter(sourceType, targetType);
		if (converter != null) {
			return converter;
		}
	}
	// Check ConditionalConverters for a dynamic match
	for (GenericConverter globalConverter : this.globalConverters) {
		if (((ConditionalConverter) globalConverter).matches(sourceType, targetType)) {
			return globalConverter;
		}
	}
	return null;
}
 
Example 2
Source Project: java-technology-stack   Source File: GenericConversionService.java    License: MIT License 6 votes vote down vote up
@Nullable
private GenericConverter getRegisteredConverter(TypeDescriptor sourceType,
		TypeDescriptor targetType, ConvertiblePair convertiblePair) {

	// Check specifically registered converters
	ConvertersForPair convertersForPair = this.converters.get(convertiblePair);
	if (convertersForPair != null) {
		GenericConverter converter = convertersForPair.getConverter(sourceType, targetType);
		if (converter != null) {
			return converter;
		}
	}
	// Check ConditionalConverters for a dynamic match
	for (GenericConverter globalConverter : this.globalConverters) {
		if (((ConditionalConverter) globalConverter).matches(sourceType, targetType)) {
			return globalConverter;
		}
	}
	return null;
}
 
Example 3
private GenericConverter getRegisteredConverter(TypeDescriptor sourceType,
		TypeDescriptor targetType, ConvertiblePair convertiblePair) {

	// Check specifically registered converters
	ConvertersForPair convertersForPair = this.converters.get(convertiblePair);
	if (convertersForPair != null) {
		GenericConverter converter = convertersForPair.getConverter(sourceType, targetType);
		if (converter != null) {
			return converter;
		}
	}
	// Check ConditionalConverters for a dynamic match
	for (GenericConverter globalConverter : this.globalConverters) {
		if (((ConditionalConverter) globalConverter).matches(sourceType, targetType)) {
			return globalConverter;
		}
	}
	return null;
}
 
Example 4
private GenericConverter getRegisteredConverter(TypeDescriptor sourceType,
		TypeDescriptor targetType, ConvertiblePair convertiblePair) {

	// Check specifically registered converters
	ConvertersForPair convertersForPair = this.converters.get(convertiblePair);
	if (convertersForPair != null) {
		GenericConverter converter = convertersForPair.getConverter(sourceType, targetType);
		if (converter != null) {
			return converter;
		}
	}
	// Check ConditionalConverters for a dynamic match
	for (GenericConverter globalConverter : this.globalConverters) {
		if (((ConditionalConverter) globalConverter).matches(sourceType, targetType)) {
			return globalConverter;
		}
	}
	return null;
}
 
Example 5
Source Project: spring-analysis-note   Source File: GenericConversionService.java    License: MIT License 5 votes vote down vote up
@Override
public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) {
	// Check raw type first...
	if (this.typeInfo.getTargetType() != targetType.getObjectType()) {
		return false;
	}
	// Full check for complex generic type match required?
	ResolvableType rt = targetType.getResolvableType();
	if (!(rt.getType() instanceof Class) && !rt.isAssignableFrom(this.targetType) &&
			!this.targetType.hasUnresolvableGenerics()) {
		return false;
	}
	return !(this.converter instanceof ConditionalConverter) ||
			((ConditionalConverter) this.converter).matches(sourceType, targetType);
}
 
Example 6
Source Project: spring-analysis-note   Source File: GenericConversionService.java    License: MIT License 5 votes vote down vote up
public void add(GenericConverter converter) {
	Set<ConvertiblePair> convertibleTypes = converter.getConvertibleTypes();
	if (convertibleTypes == null) {
		Assert.state(converter instanceof ConditionalConverter,
				"Only conditional converters may return null convertible types");
		this.globalConverters.add(converter);
	}
	else {
		for (ConvertiblePair convertiblePair : convertibleTypes) {
			ConvertersForPair convertersForPair = getMatchableConverters(convertiblePair);
			convertersForPair.add(converter);
		}
	}
}
 
Example 7
Source Project: java-technology-stack   Source File: GenericConversionService.java    License: MIT License 5 votes vote down vote up
@Override
public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) {
	// Check raw type first...
	if (this.typeInfo.getTargetType() != targetType.getObjectType()) {
		return false;
	}
	// Full check for complex generic type match required?
	ResolvableType rt = targetType.getResolvableType();
	if (!(rt.getType() instanceof Class) && !rt.isAssignableFrom(this.targetType) &&
			!this.targetType.hasUnresolvableGenerics()) {
		return false;
	}
	return !(this.converter instanceof ConditionalConverter) ||
			((ConditionalConverter) this.converter).matches(sourceType, targetType);
}
 
Example 8
Source Project: java-technology-stack   Source File: GenericConversionService.java    License: MIT License 5 votes vote down vote up
public void add(GenericConverter converter) {
	Set<ConvertiblePair> convertibleTypes = converter.getConvertibleTypes();
	if (convertibleTypes == null) {
		Assert.state(converter instanceof ConditionalConverter,
				"Only conditional converters may return null convertible types");
		this.globalConverters.add(converter);
	}
	else {
		for (ConvertiblePair convertiblePair : convertibleTypes) {
			ConvertersForPair convertersForPair = getMatchableConverters(convertiblePair);
			convertersForPair.add(converter);
		}
	}
}
 
Example 9
@Override
public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) {
	// Check raw type first...
	if (this.typeInfo.getTargetType() != targetType.getObjectType()) {
		return false;
	}
	// Full check for complex generic type match required?
	ResolvableType rt = targetType.getResolvableType();
	if (!(rt.getType() instanceof Class) && !rt.isAssignableFrom(this.targetType) &&
			!this.targetType.hasUnresolvableGenerics()) {
		return false;
	}
	return !(this.converter instanceof ConditionalConverter) ||
			((ConditionalConverter) this.converter).matches(sourceType, targetType);
}
 
Example 10
public void add(GenericConverter converter) {
	Set<ConvertiblePair> convertibleTypes = converter.getConvertibleTypes();
	if (convertibleTypes == null) {
		Assert.state(converter instanceof ConditionalConverter,
				"Only conditional converters may return null convertible types");
		this.globalConverters.add(converter);
	}
	else {
		for (ConvertiblePair convertiblePair : convertibleTypes) {
			ConvertersForPair convertersForPair = getMatchableConverters(convertiblePair);
			convertersForPair.add(converter);
		}
	}
}
 
Example 11
@Override
public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) {
	// Check raw type first...
	if (this.typeInfo.getTargetType() != targetType.getObjectType()) {
		return false;
	}
	// Full check for complex generic type match required?
	ResolvableType rt = targetType.getResolvableType();
	if (!(rt.getType() instanceof Class) && !rt.isAssignableFrom(this.targetType) &&
			!this.targetType.hasUnresolvableGenerics()) {
		return false;
	}
	return !(this.converter instanceof ConditionalConverter) ||
			((ConditionalConverter) this.converter).matches(sourceType, targetType);
}
 
Example 12
public void add(GenericConverter converter) {
	Set<ConvertiblePair> convertibleTypes = converter.getConvertibleTypes();
	if (convertibleTypes == null) {
		Assert.state(converter instanceof ConditionalConverter,
				"Only conditional converters may return null convertible types");
		this.globalConverters.add(converter);
	}
	else {
		for (ConvertiblePair convertiblePair : convertibleTypes) {
			ConvertersForPair convertersForPair = getMatchableConverters(convertiblePair);
			convertersForPair.add(converter);
		}
	}
}