LUCENE-2510, LUCENE-4044: Better generics-conform fix, sorry for heavy committing! It is much better than the original code

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1365610 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Uwe Schindler 2012-07-25 14:55:48 +00:00
parent e3af5988e7
commit 09dc88ce9a
1 changed files with 5 additions and 6 deletions

View File

@ -32,7 +32,6 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.lucene.analysis.util.AbstractAnalysisFactory;
import org.apache.lucene.analysis.util.CharFilterFactory;
import org.apache.lucene.analysis.util.ResourceLoaderAware;
import org.apache.lucene.analysis.util.TokenFilterFactory;
@ -374,7 +373,7 @@ public class SolrResourceLoader implements ResourceLoader
private static final Map<String, String> classNameCache = new ConcurrentHashMap<String, String>();
// A static map of AnalysisSPILoaders, keyed by ClassLoader used (because it can change during Solr lifetime) and expected base class:
private static final WeakIdentityMap<ClassLoader, Map<Class,AnalysisSPILoader>> expectedTypesSPILoaders = WeakIdentityMap.newConcurrentHashMap();
private static final WeakIdentityMap<ClassLoader, Map<Class<?>,AnalysisSPILoader<?>>> expectedTypesSPILoaders = WeakIdentityMap.newConcurrentHashMap();
// Using this pattern, legacy analysis components from previous Solr versions are identified and delegated to SPI loader:
private static final Pattern legacyAnalysisPattern =
@ -412,19 +411,19 @@ public class SolrResourceLoader implements ResourceLoader
if (m.matches()) {
log.trace("Trying to load class from analysis SPI");
// retrieve the map of classLoader -> expectedType -> SPI from cache / regenerate cache
Map<Class,AnalysisSPILoader> spiLoaders = expectedTypesSPILoaders.get(classLoader);
Map<Class<?>,AnalysisSPILoader<?>> spiLoaders = expectedTypesSPILoaders.get(classLoader);
if (spiLoaders == null) {
spiLoaders = new IdentityHashMap<Class,AnalysisSPILoader>(3);
spiLoaders = new IdentityHashMap<Class<?>,AnalysisSPILoader<?>>(3);
spiLoaders.put(CharFilterFactory.class, CharFilterFactory.getSPILoader(classLoader));
spiLoaders.put(TokenizerFactory.class, TokenizerFactory.getSPILoader(classLoader));
spiLoaders.put(TokenFilterFactory.class, TokenFilterFactory.getSPILoader(classLoader));
expectedTypesSPILoaders.put(classLoader, spiLoaders);
}
final AnalysisSPILoader loader = spiLoaders.get(expectedType);
final AnalysisSPILoader<?> loader = spiLoaders.get(expectedType);
if (loader != null) {
// it's a correct expected type for analysis! Let's go on!
try {
return clazz = loader.lookupClass(m.group(4));
return clazz = loader.lookupClass(m.group(4)).asSubclass(expectedType);
} catch (IllegalArgumentException ex) {
// ok, we fall back to legacy loading
}