Browse Source

alignment with backported 3.0.6 code (SPR-8538)

pull/7/head
Juergen Hoeller 14 years ago
parent
commit
0df4631788
  1. 2
      org.springframework.core/src/main/java/org/springframework/core/convert/support/ArrayToArrayConverter.java
  2. 7
      org.springframework.core/src/main/java/org/springframework/core/convert/support/ArrayToCollectionConverter.java
  3. 4
      org.springframework.core/src/main/java/org/springframework/core/convert/support/ArrayToObjectConverter.java
  4. 6
      org.springframework.core/src/main/java/org/springframework/core/convert/support/CollectionToArrayConverter.java
  5. 7
      org.springframework.core/src/main/java/org/springframework/core/convert/support/CollectionToCollectionConverter.java
  6. 2
      org.springframework.core/src/main/java/org/springframework/core/convert/support/CollectionToObjectConverter.java
  7. 6
      org.springframework.core/src/main/java/org/springframework/core/convert/support/CollectionToStringConverter.java
  8. 25
      org.springframework.core/src/main/java/org/springframework/core/convert/support/ConversionUtils.java
  9. 8
      org.springframework.core/src/main/java/org/springframework/core/convert/support/MapToMapConverter.java
  10. 6
      org.springframework.core/src/main/java/org/springframework/core/convert/support/ObjectToArrayConverter.java
  11. 11
      org.springframework.core/src/main/java/org/springframework/core/convert/support/ObjectToCollectionConverter.java
  12. 4
      org.springframework.core/src/main/java/org/springframework/core/convert/support/StringToBooleanConverter.java

2
org.springframework.core/src/main/java/org/springframework/core/convert/support/ArrayToArrayConverter.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2009 the original author or authors.
* Copyright 2002-2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

7
org.springframework.core/src/main/java/org/springframework/core/convert/support/ArrayToCollectionConverter.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2009 the original author or authors.
* Copyright 2002-2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -49,7 +49,7 @@ final class ArrayToCollectionConverter implements ConditionalGenericConverter { @@ -49,7 +49,7 @@ final class ArrayToCollectionConverter implements ConditionalGenericConverter {
}
public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) {
return ConversionUtils.canConvertElements(sourceType.getElementTypeDescriptor(), targetType.getElementTypeDescriptor(), conversionService);
return ConversionUtils.canConvertElements(sourceType.getElementTypeDescriptor(), targetType.getElementTypeDescriptor(), this.conversionService);
}
@SuppressWarnings("unchecked")
@ -64,7 +64,8 @@ final class ArrayToCollectionConverter implements ConditionalGenericConverter { @@ -64,7 +64,8 @@ final class ArrayToCollectionConverter implements ConditionalGenericConverter {
Object sourceElement = Array.get(source, i);
target.add(sourceElement);
}
} else {
}
else {
for (int i = 0; i < length; i++) {
Object sourceElement = Array.get(source, i);
Object targetElement = this.conversionService.convert(sourceElement, sourceType.elementTypeDescriptor(sourceElement), targetType.getElementTypeDescriptor());

4
org.springframework.core/src/main/java/org/springframework/core/convert/support/ArrayToObjectConverter.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2009 the original author or authors.
* Copyright 2002-2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -43,7 +43,7 @@ final class ArrayToObjectConverter implements ConditionalGenericConverter { @@ -43,7 +43,7 @@ final class ArrayToObjectConverter implements ConditionalGenericConverter {
}
public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) {
return ConversionUtils.canConvertElements(sourceType.getElementTypeDescriptor(), targetType, conversionService);
return ConversionUtils.canConvertElements(sourceType.getElementTypeDescriptor(), targetType, this.conversionService);
}
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {

6
org.springframework.core/src/main/java/org/springframework/core/convert/support/CollectionToArrayConverter.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2009 the original author or authors.
* Copyright 2002-2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -49,7 +49,7 @@ final class CollectionToArrayConverter implements ConditionalGenericConverter { @@ -49,7 +49,7 @@ final class CollectionToArrayConverter implements ConditionalGenericConverter {
}
public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) {
return ConversionUtils.canConvertElements(sourceType.getElementTypeDescriptor(), targetType.getElementTypeDescriptor(), conversionService);
return ConversionUtils.canConvertElements(sourceType.getElementTypeDescriptor(), targetType.getElementTypeDescriptor(), this.conversionService);
}
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
@ -66,4 +66,4 @@ final class CollectionToArrayConverter implements ConditionalGenericConverter { @@ -66,4 +66,4 @@ final class CollectionToArrayConverter implements ConditionalGenericConverter {
return array;
}
}
}

7
org.springframework.core/src/main/java/org/springframework/core/convert/support/CollectionToCollectionConverter.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2010 the original author or authors.
* Copyright 2002-2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -63,7 +63,8 @@ final class CollectionToCollectionConverter implements ConditionalGenericConvert @@ -63,7 +63,8 @@ final class CollectionToCollectionConverter implements ConditionalGenericConvert
for (Object element : sourceCollection) {
target.add(element);
}
} else {
}
else {
for (Object sourceElement : sourceCollection) {
Object targetElement = this.conversionService.convert(sourceElement, sourceType.elementTypeDescriptor(sourceElement), targetType.getElementTypeDescriptor());
target.add(targetElement);
@ -72,4 +73,4 @@ final class CollectionToCollectionConverter implements ConditionalGenericConvert @@ -72,4 +73,4 @@ final class CollectionToCollectionConverter implements ConditionalGenericConvert
return target;
}
}
}

2
org.springframework.core/src/main/java/org/springframework/core/convert/support/CollectionToObjectConverter.java

@ -43,7 +43,7 @@ final class CollectionToObjectConverter implements ConditionalGenericConverter { @@ -43,7 +43,7 @@ final class CollectionToObjectConverter implements ConditionalGenericConverter {
}
public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) {
return ConversionUtils.canConvertElements(sourceType.getElementTypeDescriptor(), targetType, conversionService);
return ConversionUtils.canConvertElements(sourceType.getElementTypeDescriptor(), targetType, this.conversionService);
}
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {

6
org.springframework.core/src/main/java/org/springframework/core/convert/support/CollectionToStringConverter.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2010 the original author or authors.
* Copyright 2002-2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -45,7 +45,7 @@ final class CollectionToStringConverter implements ConditionalGenericConverter { @@ -45,7 +45,7 @@ final class CollectionToStringConverter implements ConditionalGenericConverter {
}
public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) {
return ConversionUtils.canConvertElements(sourceType.getElementTypeDescriptor(), targetType, conversionService);
return ConversionUtils.canConvertElements(sourceType.getElementTypeDescriptor(), targetType, this.conversionService);
}
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
@ -69,4 +69,4 @@ final class CollectionToStringConverter implements ConditionalGenericConverter { @@ -69,4 +69,4 @@ final class CollectionToStringConverter implements ConditionalGenericConverter {
return sb.toString();
}
}
}

25
org.springframework.core/src/main/java/org/springframework/core/convert/support/ConversionUtils.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2010 the original author or authors.
* Copyright 2002-2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -41,7 +41,7 @@ abstract class ConversionUtils { @@ -41,7 +41,7 @@ abstract class ConversionUtils {
throw new ConversionFailedException(sourceType, targetType, source, ex);
}
}
public static boolean canConvertElements(TypeDescriptor sourceElementType, TypeDescriptor targetElementType, ConversionService conversionService) {
if (targetElementType == null) {
// yes
@ -51,19 +51,18 @@ abstract class ConversionUtils { @@ -51,19 +51,18 @@ abstract class ConversionUtils {
// maybe
return true;
}
boolean canConvert = conversionService.canConvert(sourceElementType, targetElementType);
if (canConvert) {
if (conversionService.canConvert(sourceElementType, targetElementType)) {
// yes
return true;
} else {
if (sourceElementType.getType().isAssignableFrom(targetElementType.getType())) {
// maybe;
return true;
} else {
// no;
return false;
}
}
}
else if (sourceElementType.getType().isAssignableFrom(targetElementType.getType())) {
// maybe;
return true;
}
else {
// no;
return false;
}
}
}

8
org.springframework.core/src/main/java/org/springframework/core/convert/support/MapToMapConverter.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2010 the original author or authors.
* Copyright 2002-2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -72,11 +72,11 @@ final class MapToMapConverter implements ConditionalGenericConverter { @@ -72,11 +72,11 @@ final class MapToMapConverter implements ConditionalGenericConverter {
// internal helpers
private boolean canConvertKey(TypeDescriptor sourceType, TypeDescriptor targetType) {
return ConversionUtils.canConvertElements(sourceType.getMapKeyTypeDescriptor(), targetType.getMapKeyTypeDescriptor(), conversionService);
return ConversionUtils.canConvertElements(sourceType.getMapKeyTypeDescriptor(), targetType.getMapKeyTypeDescriptor(), this.conversionService);
}
private boolean canConvertValue(TypeDescriptor sourceType, TypeDescriptor targetType) {
return ConversionUtils.canConvertElements(sourceType.getMapValueTypeDescriptor(), targetType.getMapValueTypeDescriptor(), conversionService);
return ConversionUtils.canConvertElements(sourceType.getMapValueTypeDescriptor(), targetType.getMapValueTypeDescriptor(), this.conversionService);
}
private Object convertKey(Object sourceKey, TypeDescriptor sourceType, TypeDescriptor targetType) {
@ -93,4 +93,4 @@ final class MapToMapConverter implements ConditionalGenericConverter { @@ -93,4 +93,4 @@ final class MapToMapConverter implements ConditionalGenericConverter {
return this.conversionService.convert(sourceValue, sourceType.mapValueTypeDescriptor(sourceValue), targetType);
}
}
}

6
org.springframework.core/src/main/java/org/springframework/core/convert/support/ObjectToArrayConverter.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2009 the original author or authors.
* Copyright 2002-2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -44,7 +44,7 @@ final class ObjectToArrayConverter implements ConditionalGenericConverter { @@ -44,7 +44,7 @@ final class ObjectToArrayConverter implements ConditionalGenericConverter {
}
public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) {
return ConversionUtils.canConvertElements(sourceType, targetType.getElementTypeDescriptor(), conversionService);
return ConversionUtils.canConvertElements(sourceType, targetType.getElementTypeDescriptor(), this.conversionService);
}
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
@ -57,4 +57,4 @@ final class ObjectToArrayConverter implements ConditionalGenericConverter { @@ -57,4 +57,4 @@ final class ObjectToArrayConverter implements ConditionalGenericConverter {
return target;
}
}
}

11
org.springframework.core/src/main/java/org/springframework/core/convert/support/ObjectToCollectionConverter.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2010 the original author or authors.
* Copyright 2002-2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -46,7 +46,7 @@ final class ObjectToCollectionConverter implements ConditionalGenericConverter { @@ -46,7 +46,7 @@ final class ObjectToCollectionConverter implements ConditionalGenericConverter {
}
public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) {
return ConversionUtils.canConvertElements(sourceType, targetType.getElementTypeDescriptor(), conversionService);
return ConversionUtils.canConvertElements(sourceType, targetType.getElementTypeDescriptor(), this.conversionService);
}
@SuppressWarnings("unchecked")
@ -56,12 +56,13 @@ final class ObjectToCollectionConverter implements ConditionalGenericConverter { @@ -56,12 +56,13 @@ final class ObjectToCollectionConverter implements ConditionalGenericConverter {
}
Collection<Object> target = CollectionFactory.createCollection(targetType.getType(), 1);
if (targetType.getElementTypeDescriptor() == null || targetType.getElementTypeDescriptor().isCollection()) {
target.add(source);
} else {
target.add(source);
}
else {
Object singleElement = this.conversionService.convert(source, sourceType, targetType.getElementTypeDescriptor());
target.add(singleElement);
}
return target;
}
}
}

4
org.springframework.core/src/main/java/org/springframework/core/convert/support/StringToBooleanConverter.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2009 the original author or authors.
* Copyright 2002-2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -48,7 +48,7 @@ final class StringToBooleanConverter implements Converter<String, Boolean> { @@ -48,7 +48,7 @@ final class StringToBooleanConverter implements Converter<String, Boolean> {
public Boolean convert(String source) {
String value = source.trim();
if (value.length() == 0) {
if ("".equals(value)) {
return null;
}
value = value.toLowerCase();

Loading…
Cancel
Save