From 594596f361da63f4063e52c15e7dd9ae64540e40 Mon Sep 17 00:00:00 2001 From: Keith Donald Date: Mon, 19 Apr 2010 01:45:27 +0000 Subject: [PATCH] cache invalidation --- .../support/GenericConversionService.java | 27 ++++++++++--------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/org.springframework.core/src/main/java/org/springframework/core/convert/support/GenericConversionService.java b/org.springframework.core/src/main/java/org/springframework/core/convert/support/GenericConversionService.java index defab1c80e..1df21ae687 100644 --- a/org.springframework.core/src/main/java/org/springframework/core/convert/support/GenericConversionService.java +++ b/org.springframework.core/src/main/java/org/springframework/core/convert/support/GenericConversionService.java @@ -74,7 +74,7 @@ public class GenericConversionService implements ConversionService, ConverterReg throw new UnsupportedOperationException(); } public String toString() { - return "null"; + return "NO_MATCH"; } }; @@ -85,13 +85,6 @@ public class GenericConversionService implements ConversionService, ConverterReg // implementing ConverterRegistry - public void addConverter(GenericConverter converter) { - Set convertibleTypes = converter.getConvertibleTypes(); - for (GenericConverter.ConvertiblePair convertibleType : convertibleTypes) { - getMatchableConvertersList(convertibleType.getSourceType(), convertibleType.getTargetType()).add(converter); - } - } - public void addConverter(Converter converter) { GenericConverter.ConvertiblePair typeInfo = getRequiredTypeInfo(converter, Converter.class); if (typeInfo == null) { @@ -109,12 +102,20 @@ public class GenericConversionService implements ConversionService, ConverterReg } addConverter(new ConverterFactoryAdapter(typeInfo, converterFactory)); } + + public void addConverter(GenericConverter converter) { + Set convertibleTypes = converter.getConvertibleTypes(); + for (GenericConverter.ConvertiblePair convertibleType : convertibleTypes) { + getMatchableConverters(convertibleType.getSourceType(), convertibleType.getTargetType()).add(converter); + } + invalidateCache(); + } public void removeConvertible(Class sourceType, Class targetType) { getSourceConverterMap(sourceType).remove(targetType); + invalidateCache(); } - // implementing ConversionService public boolean canConvert(Class sourceType, Class targetType) { @@ -210,7 +211,6 @@ public class GenericConversionService implements ConversionService, ConverterReg return builder.toString(); } - // subclassing hooks /** @@ -295,7 +295,6 @@ public class GenericConversionService implements ConversionService, ConverterReg } } - // internal helpers private GenericConverter.ConvertiblePair getRequiredTypeInfo(Object converter, Class genericIfc) { @@ -303,7 +302,7 @@ public class GenericConversionService implements ConversionService, ConverterReg return (args != null ? new GenericConverter.ConvertiblePair(args[0], args[1]) : null); } - private MatchableConverters getMatchableConvertersList(Class sourceType, Class targetType) { + private MatchableConverters getMatchableConverters(Class sourceType, Class targetType) { Map, MatchableConverters> sourceMap = getSourceConverterMap(sourceType); MatchableConverters matchable = sourceMap.get(targetType); if (matchable == null) { @@ -312,6 +311,10 @@ public class GenericConversionService implements ConversionService, ConverterReg } return matchable; } + + private void invalidateCache() { + this.converterCache.clear(); + } private Map, MatchableConverters> getSourceConverterMap(Class sourceType) { Map, MatchableConverters> sourceMap = converters.get(sourceType);