com.thihy.es.analysis.paoding.dict.DictionariesModule Maven / Gradle / Ivy
package com.thihy.es.analysis.paoding.dict;
import java.util.Map;
import java.util.Map.Entry;
import org.elasticsearch.common.collect.Maps;
import org.elasticsearch.common.inject.AbstractModule;
import org.elasticsearch.common.inject.assistedinject.FactoryProvider;
import org.elasticsearch.common.inject.multibindings.MapBinder;
public class DictionariesModule extends AbstractModule {
private final Map> dictionariesLoaders = Maps.newHashMap();
public DictionariesModule() {
this.dictionariesLoaders.put("file", FileDictionariesLoader.class);
}
public void register(String type, Class extends DictionariesLoader> dictionariesLoaderFactory) {
this.dictionariesLoaders.put(type, dictionariesLoaderFactory);
}
@Override
protected void configure() {
MapBinder dictionariesLoaderFactoriesBinder = MapBinder.newMapBinder(binder(), String.class,
DictionariesLoaderFactory.class);
for (Entry> dictionariesLoaderFactoryEntry : this.dictionariesLoaders.entrySet()) {
dictionariesLoaderFactoriesBinder.addBinding(dictionariesLoaderFactoryEntry.getKey()).toProvider(
FactoryProvider.newFactory(DictionariesLoaderFactory.class, dictionariesLoaderFactoryEntry.getValue()));
}
bind(WordLoader.class).asEagerSingleton();
bind(DictionaryLoader.class).asEagerSingleton();
}
}