refactored and added javadocs

git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@817501 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Noble Paul 2009-09-22 04:38:10 +00:00
parent ab13635017
commit 2652eabbbd
4 changed files with 34 additions and 23 deletions

View File

@ -92,6 +92,10 @@ public class PluginInfo {
return Boolean.parseBoolean(attributes.get("default"));
}
/**Filter children by type
* @param type The type name. must not be null
* @return The mathcing children
*/
public List<PluginInfo> getChildren(String type){
if(children.isEmpty()) return children;
List<PluginInfo> result = new ArrayList<PluginInfo>();

View File

@ -400,7 +400,7 @@ public final class SolrCore implements SolrInfoMBean {
/** Creates an instance by trying a constructor that accepts a SolrCore before
* trying the default (no arg) constructor.
*@param className the instance class to create
*@cast the class or interface that the instance should extend or implement
*@param cast the class or interface that the instance should extend or implement
*@param msg a message helping compose the exception error if any occurs.
*@return the desired instance
*@throws SolrException if the object could not be instantiated
@ -430,6 +430,7 @@ public final class SolrCore implements SolrInfoMBean {
}
public <T extends Object> T createInitInstance(PluginInfo info,Class<T> cast, String msg, String defClassName){
if(info == null) return null;
T o = createInstance(info.className == null ? defClassName : info.className,cast, msg);
if (o instanceof PluginInfoInitialized) {
((PluginInfoInitialized) o).init(info);
@ -1478,6 +1479,12 @@ public final class SolrCore implements SolrInfoMBean {
}
}
/**
* @param registry The map to which the instance should be added to. The key is the name attribute
* @param type the class or interface that the instance should extend or implement.
* @param defClassName If PluginInfo does not have a classname, use this as the classname
* @return The default instance . The one with (default=true)
*/
public <T> T initPlugins(Map<String ,T> registry, Class<T> type, String defClassName){
return initPlugins(solrConfig.getPluginInfos(type.getName()), registry, type, defClassName);
}
@ -1486,11 +1493,6 @@ public final class SolrCore implements SolrInfoMBean {
T def = null;
for (PluginInfo info : pluginInfos) {
T o = createInitInstance(info,type, type.getSimpleName(), defClassName);
if (o instanceof PluginInfoInitialized) {
((PluginInfoInitialized) o).init(info);
}else if (o instanceof NamedListInitializedPlugin) {
((NamedListInitializedPlugin) o).init(info.initArgs);
}
registry.put(info.name, o);
if(info.isDefault()){
def = o;
@ -1499,6 +1501,23 @@ public final class SolrCore implements SolrInfoMBean {
return def;
}
/**For a given List of PluginInfo return the instances as a List
* @param defClassName The default classname if PluginInfo#className == null
* @return The instances initialized
*/
public <T> List<T> initPlugins(List<PluginInfo> pluginInfos, Class<T> type, String defClassName) {
if(pluginInfos.isEmpty()) return Collections.emptyList();
List<T> result = new ArrayList<T>();
for (PluginInfo info : pluginInfos) result.add(createInitInstance(info,type, type.getSimpleName(), defClassName));
return result;
}
/**
*
* @param registry The map to which the instance should be added to. The key is the name attribute
* @param type The type of the Plugin. These should be standard ones registerd by type.getName() in SolrConfig
* @return The default if any
*/
public <T> T initPlugins(Map<String, T> registry, Class<T> type) {
return initPlugins(registry, type, null);
}

View File

@ -72,25 +72,19 @@ public class DefaultSolrHighlighter extends SolrHighlighter implements PluginInf
formatters.clear();
fragmenters.clear();
List<PluginInfo> fragmenterInfo = new ArrayList<PluginInfo>();
List<PluginInfo> formatterrInfo = new ArrayList<PluginInfo>();
// Load the fragmenters
for (PluginInfo child : info.children) {
if("fragmenter".equals(child.type)) fragmenterInfo.add(child);
if("formatter".equals(child.type)) formatterrInfo.add(child);
}
SolrFragmenter frag = solrCore.initPlugins(fragmenterInfo, fragmenters,SolrFragmenter.class,null);
SolrFragmenter frag = solrCore.initPlugins(info.getChildren("fragmenter") , fragmenters,SolrFragmenter.class,null);
if (frag == null) frag = new GapFragmenter();
fragmenters.put("", frag);
fragmenters.put(null, frag);
// Load the formatters
SolrFormatter fmt = solrCore.initPlugins(formatterrInfo, formatters,SolrFormatter.class,null);
SolrFormatter fmt = solrCore.initPlugins(info.getChildren("formatter"), formatters,SolrFormatter.class,null);
if (fmt == null) fmt = new HtmlFormatter();
formatters.put("", fmt);
formatters.put(null, fmt);
initialized = true;
}
//just for back-compat with the deprecated method
private boolean initialized = false;
@Deprecated
public void initalize( SolrConfig config) {

View File

@ -23,7 +23,7 @@ import org.apache.solr.util.plugin.PluginInfoInitialized;
import org.apache.solr.core.PluginInfo;
import org.apache.solr.core.SolrCore;
import java.util.ArrayList;
import java.util.List;
/**
* Manages a chain of UpdateRequestProcessorFactories.
@ -54,13 +54,7 @@ public final class UpdateRequestProcessorChain implements PluginInfoInitialized
}
public void init(PluginInfo info) {
ArrayList<UpdateRequestProcessorFactory> list = new ArrayList<UpdateRequestProcessorFactory>();
for (PluginInfo child : info.children) {
if("processor".equals(child.type)){
UpdateRequestProcessorFactory factory = solrCore.createInitInstance(child, UpdateRequestProcessorFactory.class, null,null);
list.add(factory);
}
}
List<UpdateRequestProcessorFactory> list = solrCore.initPlugins(info.getChildren("processor"),UpdateRequestProcessorFactory.class,null);
if(list.isEmpty()){
throw new RuntimeException( "updateRequestProcessorChain require at least one processor");
}