make settings prefix simpler and not bail when not prefixed with org.elasticsearch, allow to provide settings prefix for analyzer provider

This commit is contained in:
kimchy 2010-12-29 19:12:38 +02:00
parent f73a5e62d3
commit e3322836b5
4 changed files with 40 additions and 2 deletions

View File

@ -76,7 +76,11 @@ public class ImmutableSettings implements Settings {
}
@Override public Settings getComponentSettings(Class component) {
return getComponentSettings("org.elasticsearch", component);
if (component.getName().startsWith("org.elasticsearch")) {
return getComponentSettings("org.elasticsearch", component);
}
// not starting with org.elasticsearch, just remove the first package part (probably org/net/com)
return getComponentSettings(component.getName().substring(0, component.getName().indexOf('.')), component);
}
@Override public Settings getComponentSettings(String prefix, Class component) {

View File

@ -41,7 +41,8 @@ public interface Settings {
/**
* Component settings for a specific component. Returns all the settings for the given class, where the
* FQN of the class is used, without the <tt>org.elasticsearch<tt> prefix.
* FQN of the class is used, without the <tt>org.elasticsearch<tt> prefix. If there is no <tt>org.elasticsearch</tt>
* prefix, then the prefix used is the first part of the package name (<tt>org</tt> / <tt>com</tt> / ...)
*/
Settings getComponentSettings(Class component);

View File

@ -40,6 +40,12 @@ public abstract class AbstractIndexComponent implements IndexComponent {
protected final Settings componentSettings;
/**
* Constructs a new index component, with the index name and its settings.
*
* @param index The index name
* @param indexSettings The index settings
*/
protected AbstractIndexComponent(Index index, @IndexSettings Settings indexSettings) {
this.index = index;
this.indexSettings = indexSettings;
@ -48,6 +54,13 @@ public abstract class AbstractIndexComponent implements IndexComponent {
this.logger = Loggers.getLogger(getClass(), indexSettings, index);
}
/**
* Constructs a new index component, with the index name and its settings, as well as settings prefix.
*
* @param index The index name
* @param indexSettings The index settings
* @param prefixSettings A settings prefix (like "com.mycompany") to simplify extracting the component settings
*/
protected AbstractIndexComponent(Index index, @IndexSettings Settings indexSettings, String prefixSettings) {
this.index = index;
this.indexSettings = indexSettings;

View File

@ -32,11 +32,31 @@ public abstract class AbstractIndexAnalyzerProvider<T extends Analyzer> extends
private final String name;
/**
* Constructs a new analyzer component, with the index name and its settings and the analyzer name.
*
* @param index The index name
* @param indexSettings The index settings
* @param name The analyzer name
*/
public AbstractIndexAnalyzerProvider(Index index, @IndexSettings Settings indexSettings, String name) {
super(index, indexSettings);
this.name = name;
}
/**
* Constructs a new analyzer component, with the index name and its settings and the analyzer name.
*
* @param index The index name
* @param indexSettings The index settings
* @param prefixSettings A settings prefix (like "com.mycompany") to simplify extracting the component settings
* @param name The analyzer name
*/
public AbstractIndexAnalyzerProvider(Index index, @IndexSettings Settings indexSettings, String prefixSettings, String name) {
super(index, indexSettings, prefixSettings);
this.name = name;
}
@Override public String name() {
return this.name;
}