Java 类org.springframework.core.convert.converter.ConditionalConverter 实例源码

项目:spring4-understanding    文件:GenericConversionService.java   
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;
}
项目:spring    文件:GenericConversionService.java   
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;
}
项目:class-guard    文件:GenericConversionService.java   
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 ConditionalGenericConverter that match all types
    for (GenericConverter globalConverter : this.globalConverters) {
        if (((ConditionalConverter)globalConverter).matches(sourceType, targetType)) {
            return globalConverter;
        }
    }
    return null;
}
项目:spring4-understanding    文件:GenericConversionService.java   
@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);
}
项目:spring4-understanding    文件:GenericConversionService.java   
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);
        }
    }
}
项目:spring    文件:GenericConversionService.java   
@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);
}
项目:spring    文件:GenericConversionService.java   
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);
        }
    }
}
项目:class-guard    文件:GenericConversionService.java   
public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) {
    if (!this.typeInfo.getTargetType().equals(targetType.getObjectType())) {
        return false;
    }
    if (this.converter instanceof ConditionalConverter) {
        return ((ConditionalConverter) this.converter).matches(sourceType, targetType);
    }
    return true;
}
项目:class-guard    文件:GenericConversionService.java   
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);
        }
    }
}